WPSEO_Option_Wpseo::validate_option │ protected │ Yoast 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() WPSEO Option Wpseo::validate option Yoast 27.4
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 'index_now_key':
case 'wincher_website_id':
case 'clean_permalinks_extra_variables':
case 'indexables_overview_state':
if ( isset( $dirty[ $key ] ) ) {
$clean[ $key ] = $dirty[ $key ];
}
break;
case 'indexing_reason':
case 'site_kit_tracking_setup_widget_loaded':
case 'site_kit_tracking_first_interaction_stage':
case 'site_kit_tracking_last_interaction_stage':
case 'site_kit_tracking_setup_widget_temporarily_dismissed':
case 'site_kit_tracking_setup_widget_permanently_dismissed':
case 'ai_free_sparks_started_on':
case 'schema_aggregation_endpoint_enabled_on':
if ( isset( $dirty[ $key ] ) ) {
$clean[ $key ] = sanitize_text_field( $dirty[ $key ] );
}
break;
/* Verification strings. */
case 'baiduverify':
case 'googleverify':
case 'msverify':
case 'yandexverify':
case 'ahrefsverify':
$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':
case 'last_updated_on':
$clean[ $key ] = false;
if ( isset( $dirty[ $key ] ) ) {
if ( $dirty[ $key ] === false || WPSEO_Utils::validate_int( $dirty[ $key ] ) ) {
$clean[ $key ] = $dirty[ $key ];
}
}
break;
case 'first_activated_by':
// A slight change from the other integer fields, as we want to allow '0' here, but don't want to have much impact elsewhere.
$clean[ $key ] = false;
if ( isset( $dirty[ $key ] ) ) {
if ( $dirty[ $key ] === false || WPSEO_Utils::validate_int( $dirty[ $key ] ) !== false ) {
$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 'wincher_tokens':
case 'workouts_data':
case 'configuration_finished_steps':
case 'least_readability_ignore_list':
case 'least_seo_score_ignore_list':
case 'most_linked_ignore_list':
case 'least_linked_ignore_list':
case 'indexables_page_reading_list':
case 'last_known_public_post_types':
case 'last_known_public_taxonomies':
case 'new_post_types':
case 'new_taxonomies':
case 'default_seo_title':
case 'default_seo_meta_desc':
$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 'last_known_no_unindexed':
$clean[ $key ] = $old[ $key ];
if ( isset( $dirty[ $key ] ) ) {
$items = $dirty[ $key ];
if ( is_array( $items ) ) {
foreach ( $items as $item_key => $item ) {
if ( ! is_string( $item_key ) || ! is_numeric( $item ) ) {
unset( $items[ $item_key ] );
}
}
$clean[ $key ] = $items;
}
}
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'
* 'deny_wp_json_crawling'
* 'deny_adsbot_crawling'
* 'deny_ccbot_crawling'
* 'deny_google_extended_crawling'
* 'deny_gptbot_crawling'
* 'redirect_search_pretty_urls'
* 'should_redirect_after_install_free'
* 'show_new_content_type_notification'
* 'site_kit_configuration_permanently_dismissed',
* 'site_kit_connected',
* 'google_site_kit_feature_enabled',
* 'enable_llms_txt',
* 'enable_schema_aggregation_endpoint'
* 'enable_task_list',
* 'enable_schema',
* and most of the feature variables.
*/
default:
$clean[ $key ] = ( isset( $dirty[ $key ] ) ? WPSEO_Utils::validate_bool( $dirty[ $key ] ) : false );
break;
}
}
return $clean;
}