WPSEO_Option::validate_verification_string()publicYoast 1.0

Validate webmaster tools & Pinterest verification strings.

Метод класса: WPSEO_Option{}

Хуков нет.

Возвращает

null. Ничего (null).

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

$WPSEO_Option = new WPSEO_Option();
$WPSEO_Option->validate_verification_string( $key, $dirty, $old, $clean );
$key(строка) (обязательный)
Key to check, by type of service.
$dirty(массив) (обязательный)
Dirty data with the new values.
$old(массив) (обязательный)
Old data.
$clean(массив) (обязательный) (передается по ссылке — &)
Clean data by reference, normally the default values.

Код WPSEO_Option::validate_verification_string() Yoast 24.9

public function validate_verification_string( $key, $dirty, $old, &$clean ) {
	if ( isset( $dirty[ $key ] ) && $dirty[ $key ] !== '' ) {
		$meta = $dirty[ $key ];
		if ( strpos( $meta, 'content=' ) ) {
			// Make sure we only have the real key, not a complete meta tag.
			preg_match( '`content=([\'"])?([^\'"> ]+)(?:\1|[ />])`', $meta, $match );
			if ( isset( $match[2] ) ) {
				$meta = $match[2];
			}
			unset( $match );
		}

		$meta = sanitize_text_field( $meta );
		if ( $meta !== '' ) {
			$regex = '`^[A-Fa-f0-9_-]+$`';

			switch ( $key ) {
				case 'googleverify':
				case 'baiduverify':
					$regex = '`^[A-Za-z0-9_-]+$`';
					break;

				case 'msverify':
				case 'pinterestverify':
				case 'yandexverify':
					break;
			}

			if ( preg_match( $regex, $meta ) ) {
				$clean[ $key ] = $meta;
			}
			else {
				// Restore the previous value, if any.
				if ( isset( $old[ $key ] ) && preg_match( $regex, $old[ $key ] ) ) {
					$clean[ $key ] = $old[ $key ];
				}

				Yoast_Input_Validation::add_dirty_value_to_settings_errors( $key, $meta );
			}
		}
	}
}