WPSEO_Taxonomy_Meta::clean_option
Clean a given option value.
- Convert old option values to new
- Fixes strings which were escaped (should have been sanitized - escaping is for output)
Метод класса: WPSEO_Taxonomy_Meta{}
Хуков нет.
Возвращает
Массив. Cleaned option.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->clean_option( $option_value, $current_version, $all_old_option_values );
- $option_value(массив) (обязательный)
- Old (not merged with defaults or filtered) option value to clean according to the rules for this option.
- $current_version(строка|null)
- Version from which to upgrade, if not set, version specific upgrades will be disregarded.
По умолчанию:null - $all_old_option_values(массив|null)
- Only used when importing old options to have access to the real old values, in contrast to the saved ones.
По умолчанию:null
Код WPSEO_Taxonomy_Meta::clean_option() WPSEO Taxonomy Meta::clean option Yoast 28.3
protected function clean_option( $option_value, $current_version = null, $all_old_option_values = null ) {
/* Clean up old values and remove empty arrays. */
if ( is_array( $option_value ) && $option_value !== [] ) {
foreach ( $option_value as $taxonomy => $terms ) {
if ( is_array( $terms ) && $terms !== [] ) {
foreach ( $terms as $term_id => $meta_data ) {
if ( ! is_array( $meta_data ) || $meta_data === [] ) {
// Remove empty term arrays.
unset( $option_value[ $taxonomy ][ $term_id ] );
}
else {
foreach ( $meta_data as $key => $value ) {
switch ( $key ) {
case 'noindex':
if ( $value === 'on' ) {
// Convert 'on' to 'noindex'.
$option_value[ $taxonomy ][ $term_id ][ $key ] = 'noindex';
}
break;
case 'canonical':
case 'wpseo_bctitle':
case 'wpseo_title':
case 'wpseo_desc':
case 'wpseo_linkdex':
// @todo [JRF => whomever] Needs checking, I don't have example data [JRF].
if ( $value !== '' ) {
// Fix incorrectly saved (encoded) canonical urls and texts.
$option_value[ $taxonomy ][ $term_id ][ $key ] = wp_specialchars_decode( stripslashes( $value ), ENT_QUOTES );
}
break;
default:
// @todo [JRF => whomever] Needs checking, I don't have example data [JRF].
if ( $value !== '' ) {
// Fix incorrectly saved (escaped) text strings.
$option_value[ $taxonomy ][ $term_id ][ $key ] = wp_specialchars_decode( $value, ENT_QUOTES );
}
break;
}
}
}
}
}
else {
// Remove empty taxonomy arrays.
unset( $option_value[ $taxonomy ] );
}
}
}
return $option_value;
}