src/Page/Page.php
public function sanitizeSetting($value)
    {
        $keys = $this->repository()->getSettings()->collapse()->map(function ($setting) {
            /** @var FieldTypeInterface $setting */
            return $setting->getName();
        });

        $settingName = $keys->slice($this->offset, 1)->first();
        $lastSetting = $this->repository()->getSettings()->collapse()->last();
        $data = collect($_POST);

        if ($this->offset > $keys->count() - 1) {
            if (empty($value)) {
                return '';
            }

            // Sanitize is called one more time with a valid value.
            // Let's get the $settingName based on the given value
            // as we can't rely anymore on the offset.
            $settingName = $data->search($value, true);

            if (! $settingName) {
                return '';
            }

            // Let's add a "fake" error to avoid duplicate success messages.
            $this->errors++;
        }

        $setting = $this->repository()->getSettingByName($settingName);

        $validator = $this->validator->make(
            $data->all(),
            [$setting->getName() => $setting->getOption('rules')],
            $this->getSettingMessages($setting),
            $this->getSettingPlaceholder($setting)
        );

        // Update setting offset.
        $this->offset++;

        /** @var Validator $validator */
        if ($validator->fails()) {
            $this->errors++;

            add_settings_error(
                $this->getSlug(),
                $setting->getName(),
                $validator->getMessageBag()->first($setting->getName()),
                'error'
            );

            return '';
        }

        if ($settingName === $lastSetting->getName() && ! $this->errors) {
            add_settings_error(
                $this->getSlug(),
                'settings_updated',
                __('Settings saved.'),
                'updated'
            );
        }

        return $value;
    }
public function sanitizeSetting($value)
    {
        $keys = $this->repository()->getSettings()->collapse()->map(function ($setting) {
            /** @var FieldTypeInterface $setting */
            return $setting->getName();
        });

        $settingName = $keys->slice($this->offset, 1)->first();
        $lastSetting = $this->repository()->getSettings()->collapse()->last();
        $data = collect($_POST);

        if ($this->offset > $keys->count() - 1) {
            if (empty($value)) {
                return '';
            }

            // Sanitize is called one more time with a valid value.
            // Let's get the $settingName based on the given value
            // as we can't rely anymore on the offset.
            $settingName = $data->search($value, true);

            if (! $settingName) {
                return '';
            }

            // Let's add a "fake" error to avoid duplicate success messages.
            $this->errors++;
        }

        $setting = $this->repository()->getSettingByName($settingName);

        $validator = $this->validator->make(
            $data->all(),
            [$setting->getName() => $setting->getOption('rules')],
            $this->getSettingMessages($setting),
            $this->getSettingPlaceholder($setting)
        );

        // Update setting offset.
        $this->offset++;

        /** @var Validator $validator */
        if ($validator->fails()) {
            $this->errors++;

            add_settings_error(
                $this->getSlug(),
                $setting->getName(),
                $validator->getMessageBag()->first($setting->getName()),
                'error'
            );

            return '';
        }

        if ($settingName === $lastSetting->getName() && ! $this->errors) {
            add_settings_error(
                $this->getSlug(),
                'settings_updated',
                __('Settings saved.'),
                'updated'
            );
        }

        return $value;
    }
public function sanitizeSetting ( $ value ) { $ keys = $ this -> repository ( ) -> getSettings ( ) -> collapse ( ) -> map ( function ( $ setting ) { /** @var FieldTypeInterface $setting */ return $ setting -> getName ( ) ; } ) ; $ settingName = $ keys -> slice ( $ this -> offset , 1 ) -> first ( ) ; $ lastSetting = $ this -> repository ( ) -> getSettings ( ) -> collapse ( ) -> last ( ) ; $ data = collect ( $ _POST ) ; if ( $ this -> offset > $ keys -> count ( ) - 1 ) { if ( empty ( $ value ) ) { return '' ; } // Sanitize is called one more time with a valid value. // Let's get the $settingName based on the given value // as we can't rely anymore on the offset. $ settingName = $ data -> search ( $ value , true ) ; if ( ! $ settingName ) { return '' ; } // Let's add a "fake" error to avoid duplicate success messages. $ this -> errors ++ ; } $ setting = $ this -> repository ( ) -> getSettingByName ( $ settingName ) ; $ validator = $ this -> validator -> make ( $ data -> all ( ) , [ $ setting -> getName ( ) => $ setting -> getOption ( 'rules' ) ] , $ this -> getSettingMessages ( $ setting ) , $ this -> getSettingPlaceholder ( $ setting ) ) ; // Update setting offset. $ this -> offset ++ ; /** @var Validator $validator */ if ( $ validator -> fails ( ) ) { $ this -> errors ++ ; add_settings_error ( $ this -> getSlug ( ) , $ setting -> getName ( ) , $ validator -> getMessageBag ( ) -> first ( $ setting -> getName ( ) ) , 'error' ) ; return '' ; } if ( $ settingName === $ lastSetting -> getName ( ) && ! $ this -> errors ) { add_settings_error ( $ this -> getSlug ( ) , 'settings_updated' , __ ( 'Settings saved.' ) , 'updated' ) ; } return $ value ; }
Sanitize the setting before save.

@param string|array $value

@return string|array
Sanitize the setting before save .