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 22.4

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_-]+$`';
			$service = '';

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

				case 'googleverify':
					$regex   = '`^[A-Za-z0-9_-]+$`';
					$service = 'Google Webmaster tools';
					break;

				case 'msverify':
					$service = 'Bing Webmaster tools';
					break;

				case 'pinterestverify':
					$service = 'Pinterest';
					break;

				case 'yandexverify':
					$service = 'Yandex Webmaster tools';
					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 ];
				}

				if ( function_exists( 'add_settings_error' ) ) {
					add_settings_error(
						$this->group_name, // Slug title of the setting.
						$key, // Suffix-ID for the error message box. WordPress prepends `setting-error-`.
						/* translators: 1: Verification string from user input; 2: Service name. */
						sprintf( __( '%1$s does not seem to be a valid %2$s verification string. Please correct.', 'wordpress-seo' ), '<strong>' . esc_html( $meta ) . '</strong>', $service ), // The error message.
						'error' // CSS class for the WP notice, either the legacy 'error' / 'updated' or the new `notice-*` ones.
					);
				}

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