WPSEO_Option_Wpseo::validate_option()protectedYoast 1.0

Validate the option.

{} Это метод класса: WPSEO_Option_Wpseo{}

Хуков нет.

Возвращает

Массив. Validated clean value for the option to be saved to the database.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->validate_option( $dirty, $clean, $old );
$dirty(массив) (обязательный)
New value for the option.
$clean(массив) (обязательный)
Clean value for the option, normally the defaults.
$old(массив) (обязательный)
Old value of the option.

Код WPSEO_Option_Wpseo::validate_option() Yoast 19.6.1

protected function validate_option( $dirty, $clean, $old ) {

	foreach ( $clean as $key => $value ) {
		switch ( $key ) {
			case 'version':
				$clean[ $key ] = WPSEO_VERSION;
				break;
			case 'previous_version':
			case 'semrush_country_code':
			case 'license_server_version':
			case 'home_url':
			case 'zapier_api_key':
			case 'index_now_key':
			case 'wincher_website_id':
			case 'clean_permalinks_extra_variables':
				if ( isset( $dirty[ $key ] ) ) {
					$clean[ $key ] = $dirty[ $key ];
				}
				break;
			case 'indexing_reason':
				if ( isset( $dirty[ $key ] ) ) {
					$clean[ $key ] = sanitize_text_field( $dirty[ $key ] );
				}
				break;

			/* Verification strings. */
			case 'baiduverify':
			case 'googleverify':
			case 'msverify':
			case 'yandexverify':
				$this->validate_verification_string( $key, $dirty, $old, $clean );
				break;

			/*
			 * Boolean dismiss warnings - not fields - may not be in form
			 * (and don't need to be either as long as the default is false).
			 */
			case 'ignore_search_engines_discouraged_notice':
			case 'ms_defaults_set':
				if ( isset( $dirty[ $key ] ) ) {
					$clean[ $key ] = WPSEO_Utils::validate_bool( $dirty[ $key ] );
				}
				elseif ( isset( $old[ $key ] ) ) {
					$clean[ $key ] = WPSEO_Utils::validate_bool( $old[ $key ] );
				}
				break;

			case 'site_type':
				$clean[ $key ] = $old[ $key ];
				if ( isset( $dirty[ $key ] ) && in_array( $dirty[ $key ], $this->site_types, true ) ) {
					$clean[ $key ] = $dirty[ $key ];
				}
				break;

			case 'environment_type':
				$clean[ $key ] = $old[ $key ];
				if ( isset( $dirty[ $key ] ) && in_array( $dirty[ $key ], $this->environment_types, true ) ) {
					$clean[ $key ] = $dirty[ $key ];
				}
				break;

			case 'has_multiple_authors':
				$clean[ $key ] = $old[ $key ];
				if ( isset( $dirty[ $key ] ) && in_array( $dirty[ $key ], $this->has_multiple_authors_options, true ) ) {
					$clean[ $key ] = $dirty[ $key ];
				}

				break;

			case 'first_activated_on':
			case 'indexing_started':
			case 'activation_redirect_timestamp_free':
				$clean[ $key ] = false;
				if ( isset( $dirty[ $key ] ) ) {
					if ( $dirty[ $key ] === false || WPSEO_Utils::validate_int( $dirty[ $key ] ) ) {
						$clean[ $key ] = $dirty[ $key ];
					}
				}
				break;

			case 'tracking':
				$clean[ $key ] = ( isset( $dirty[ $key ] ) ? WPSEO_Utils::validate_bool( $dirty[ $key ] ) : null );
				break;

			case 'myyoast_oauth':
			case 'semrush_tokens':
			case 'custom_taxonomy_slugs':
			case 'zapier_subscription':
			case 'wincher_tokens':
			case 'workouts_data':
			case 'configuration_finished_steps':
				$clean[ $key ] = $old[ $key ];

				if ( isset( $dirty[ $key ] ) ) {
					$items = $dirty[ $key ];
					if ( ! is_array( $items ) ) {
						$items = json_decode( $dirty[ $key ], true );
					}

					if ( is_array( $items ) ) {
						$clean[ $key ] = $dirty[ $key ];
					}
				}

				break;

			case 'permalink_structure':
			case 'category_base_url':
			case 'tag_base_url':
				if ( isset( $dirty[ $key ] ) ) {
					$clean[ $key ] = sanitize_option( $key, $dirty[ $key ] );
				}
				break;

			case 'search_character_limit':
				if ( isset( $dirty[ $key ] ) ) {
					$clean[ $key ] = (int) $dirty[ $key ];
				}
				break;

			case 'import_cursors':
			case 'importing_completed':
				if ( isset( $dirty[ $key ] ) && is_array( $dirty[ $key ] ) ) {
					$clean[ $key ] = $dirty[ $key ];
				}
				break;

			case 'wordproof_integration_active':
				$clean[ $key ] = ( isset( $dirty[ $key ] ) ? WPSEO_Utils::validate_bool( $dirty[ $key ] ) : false );
				// If the setting has changed, record it.
				if ( $old[ $key ] !== $clean[ $key ] ) {
					$clean['wordproof_integration_changed'] = true;
				}
				break;


			/*
			* Boolean (checkbox) fields.
			*/

			/*
			 * Covers:
			 *  'disableadvanced_meta'
			 *  'enable_headless_rest_endpoints'
			 *  'yoast_tracking'
			 *  'dynamic_permalinks'
			 *  'indexing_first_time'
			 *  'first_time_install'
			 *  'remove_feed_global'
			 *  'remove_feed_global_comments'
			 *  'remove_feed_post_comments'
			 *  'remove_feed_authors'
			 *  'remove_feed_categories'
			 *  'remove_feed_tags'
			 *  'remove_feed_custom_taxonomies'
			 *  'remove_feed_post_types'
			 *  'remove_feed_search'
			 *  'remove_atom_rdf_feeds'
			 *  'remove_shortlinks'
			 *  'remove_rest_api_links'
			 *  'remove_rsd_wlw_links'
			 *  'remove_oembed_links'
			 *  'remove_generator'
			 *  'remove_emoji_scripts'
			 *  'remove_powered_by_header'
			 *  'remove_pingback_header'
			 *  'clean_campaign_tracking_urls'
			 *  'clean_permalinks'
			 *  'clean_permalinks_extra_variables'
			 *  'search_cleanup'
			 *  'search_cleanup_emoji'
			 *  'search_cleanup_patterns'
			 *  'should_redirect_after_install_free'
			 *  and most of the feature variables.
			 */
			default:
				$clean[ $key ] = ( isset( $dirty[ $key ] ) ? WPSEO_Utils::validate_bool( $dirty[ $key ] ) : false );
				break;
		}
	}

	return $clean;
}