WPSEO_Option_Social::validate_option() │ protected │ Yoast 1.0
Validate the option.
Метод класса: WPSEO_Option_Social{}
Хуков нет.
Возвращает
Массив
. 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_Social::validate_option() WPSEO Option Social::validate option
Yoast 24.9
protected function validate_option( $dirty, $clean, $old ) {
foreach ( $clean as $key => $value ) {
switch ( $key ) {
/* Text fields. */
case 'og_frontpage_desc':
case 'og_frontpage_title':
if ( isset( $dirty[ $key ] ) && $dirty[ $key ] !== '' ) {
$clean[ $key ] = WPSEO_Utils::sanitize_text_field( $dirty[ $key ] );
}
break;
case 'og_default_image_id':
case 'og_frontpage_image_id':
if ( isset( $dirty[ $key ] ) ) {
$clean[ $key ] = (int) $dirty[ $key ];
if ( $dirty[ $key ] === '' ) {
$clean[ $key ] = $dirty[ $key ];
}
}
break;
/* URL text fields - no ftp allowed. */
case 'facebook_site':
case 'instagram_url':
case 'linkedin_url':
case 'myspace_url':
case 'pinterest_url':
case 'og_default_image':
case 'og_frontpage_image':
case 'youtube_url':
case 'wikipedia_url':
case 'mastodon_url':
$this->validate_url( $key, $dirty, $old, $clean );
break;
case 'pinterestverify':
$this->validate_verification_string( $key, $dirty, $old, $clean );
break;
/* Twitter user name. */
case 'twitter_site':
if ( isset( $dirty[ $key ] ) && $dirty[ $key ] !== '' ) {
$twitter_id = $this->validate_twitter_id( $dirty[ $key ] );
if ( $twitter_id ) {
$clean[ $key ] = $twitter_id;
}
elseif ( isset( $old[ $key ] ) && $old[ $key ] !== '' ) {
$twitter_id = sanitize_text_field( ltrim( $old[ $key ], '@' ) );
if ( preg_match( '`^[A-Za-z0-9_]{1,25}$`', $twitter_id ) ) {
$clean[ $key ] = $twitter_id;
}
}
unset( $twitter_id );
Yoast_Input_Validation::add_dirty_value_to_settings_errors( $key, $dirty[ $key ] );
}
break;
case 'twitter_card_type':
if ( isset( $dirty[ $key ], self::$twitter_card_types[ $dirty[ $key ] ] ) && $dirty[ $key ] !== '' ) {
$clean[ $key ] = $dirty[ $key ];
}
break;
/* Boolean fields. */
case 'opengraph':
case 'twitter':
$clean[ $key ] = ( isset( $dirty[ $key ] ) ? WPSEO_Utils::validate_bool( $dirty[ $key ] ) : false );
break;
/* Array fields. */
case 'other_social_urls':
if ( isset( $dirty[ $key ] ) ) {
$items = $dirty[ $key ];
if ( ! is_array( $items ) ) {
$items = json_decode( $dirty[ $key ], true );
}
if ( is_array( $items ) ) {
foreach ( $items as $item_key => $item ) {
$validated_url = $this->validate_social_url( $item );
if ( $validated_url === false ) {
// Restore the previous URL values, if any.
$old_urls = ( isset( $old[ $key ] ) ) ? $old[ $key ] : [];
foreach ( $old_urls as $old_item_key => $old_url ) {
if ( $old_url !== '' ) {
$url = WPSEO_Utils::sanitize_url( $old_url );
if ( $url !== '' ) {
$clean[ $key ][ $old_item_key ] = $url;
}
}
}
break;
}
// The URL format is valid, let's sanitize it.
$url = WPSEO_Utils::sanitize_url( $validated_url );
if ( $url !== '' ) {
$clean[ $key ][ $item_key ] = $url;
}
}
}
}
break;
}
}
return $clean;
}