WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Получай пассивный доход от сайта с помощью браузерных PUSH уведомлений
функция не описана

WPSEO_Meta::sanitize_post_meta() public Yoast 1.0

Validate the post meta values.

{} Это метод класса: WPSEO_Meta{}

Хуки из метода
Возвращает

Строку. Validated meta value.

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

$result = WPSEO_Meta::sanitize_post_meta( $meta_value, $meta_key );
$meta_value(разное) (обязательный)
The new value.
$meta_key(строка) (обязательный)
The full meta key (including prefix).

Код WPSEO_Meta::sanitize_post_meta() Yoast 16.1.1

<?php
public static function sanitize_post_meta( $meta_value, $meta_key ) {
	$field_def = self::$meta_fields[ self::$fields_index[ $meta_key ]['subset'] ][ self::$fields_index[ $meta_key ]['key'] ];
	$clean     = self::$defaults[ $meta_key ];

	switch ( true ) {
		case ( $meta_key === self::$meta_prefix . 'linkdex' ):
			$int = WPSEO_Utils::validate_int( $meta_value );
			if ( $int !== false && $int >= 0 ) {
				$clean = strval( $int ); // Convert to string to make sure default check works.
			}
			break;

		case ( $field_def['type'] === 'checkbox' ):
			// Only allow value if it's one of the predefined options.
			if ( in_array( $meta_value, [ 'on', 'off' ], true ) ) {
				$clean = $meta_value;
			}
			break;


		case ( $field_def['type'] === 'select' || $field_def['type'] === 'radio' ):
			// Only allow value if it's one of the predefined options.
			if ( isset( $field_def['options'][ $meta_value ] ) ) {
				$clean = $meta_value;
			}
			break;


		case ( $field_def['type'] === 'hidden' && $meta_key === self::$meta_prefix . 'meta-robots-adv' ):
			$clean = self::validate_meta_robots_adv( $meta_value );
			break;


		case ( $field_def['type'] === 'url' || $meta_key === self::$meta_prefix . 'canonical' ):
			// Validate as url(-part).
			$url = WPSEO_Utils::sanitize_url( $meta_value );
			if ( $url !== '' ) {
				$clean = $url;
			}
			break;


		case ( $field_def['type'] === 'upload' && in_array( $meta_key, [ self::$meta_prefix . 'opengraph-image', self::$meta_prefix . 'twitter-image' ], true ) ):
			// Validate as url.
			$url = WPSEO_Utils::sanitize_url( $meta_value, [ 'http', 'https', 'ftp', 'ftps' ] );
			if ( $url !== '' ) {
				$clean = $url;
			}
			break;

		case ( $field_def['type'] === 'hidden' && $meta_key === self::$meta_prefix . 'is_cornerstone' ):
			$clean = $meta_value;

			/*
			 * This used to be a checkbox, then became a hidden input.
			 * To make sure the value remains consistent, we cast 'true' to '1'.
			 */
			if ( $meta_value === 'true' ) {
				$clean = '1';
			}
			break;

		case ( $field_def['type'] === 'hidden' && isset( $field_def['options'] ) ):
			// Only allow value if it's one of the predefined options.
			if ( isset( $field_def['options'][ $meta_value ] ) ) {
				$clean = $meta_value;
			}
			break;

		case ( $field_def['type'] === 'textarea' ):
			if ( is_string( $meta_value ) ) {
				// Remove line breaks and tabs.
				// @todo [JRF => Yoast] Verify that line breaks and the likes aren't allowed/recommended in meta header fields.
				$meta_value = str_replace( [ "\n", "\r", "\t", '  ' ], ' ', $meta_value );
				$clean      = WPSEO_Utils::sanitize_text_field( trim( $meta_value ) );
			}
			break;

		case ( $field_def['type'] === 'multiselect' ):
			$clean = $meta_value;
			break;


		case ( $field_def['type'] === 'text' ):
		default:
			if ( is_string( $meta_value ) ) {
				$clean = WPSEO_Utils::sanitize_text_field( trim( $meta_value ) );
			}

			break;
	}

	$clean = apply_filters( 'wpseo_sanitize_post_meta_' . $meta_key, $clean, $meta_value, $field_def, $meta_key );

	return $clean;
}