sanitize_comment_cookies()WP 2.0.4

Очищает поля формы комментирвоания имя, почту и сайт находящихся в кукисах.

Функция ничего не получает и не возвращает, а работает напрямую с суперглобальной переменной $_COOKIES и очищает соответствующие значения в ней.

Возвращает

null. Ничего.

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

sanitize_comment_cookies();

Примеры

0

#1 Очистка значений кукисов для формы комментариев перед выводом на экран

Предположим что мы используем функцию wp_get_current_commenter(), чтобы получить данные имени , почты и сайта неавторизованного пользователя, которые находятся в кукисах. Но мы получим не очищенные данные, чтобы их очистить перед выводом, нужно запустить функцию sanitize_comment_cookies()

// чистим данные
sanitize_comment_cookies();

// теперь данные безопасны для использования
$commenter = wp_get_current_commenter();

// Вывод данных
echo $commenter['comment_author'];
echo $commenter['comment_author_email'];
echo $commenter['comment_author_url'];

Список изменений

С версии 2.0.4 Введена.

Код sanitize_comment_cookies() WP 6.5.2

function sanitize_comment_cookies() {
	if ( isset( $_COOKIE[ 'comment_author_' . COOKIEHASH ] ) ) {
		/**
		 * Filters the comment author's name cookie before it is set.
		 *
		 * When this filter hook is evaluated in wp_filter_comment(),
		 * the comment author's name string is passed.
		 *
		 * @since 1.5.0
		 *
		 * @param string $author_cookie The comment author name cookie.
		 */
		$comment_author = apply_filters( 'pre_comment_author_name', $_COOKIE[ 'comment_author_' . COOKIEHASH ] );
		$comment_author = wp_unslash( $comment_author );
		$comment_author = esc_attr( $comment_author );

		$_COOKIE[ 'comment_author_' . COOKIEHASH ] = $comment_author;
	}

	if ( isset( $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ) ) {
		/**
		 * Filters the comment author's email cookie before it is set.
		 *
		 * When this filter hook is evaluated in wp_filter_comment(),
		 * the comment author's email string is passed.
		 *
		 * @since 1.5.0
		 *
		 * @param string $author_email_cookie The comment author email cookie.
		 */
		$comment_author_email = apply_filters( 'pre_comment_author_email', $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] );
		$comment_author_email = wp_unslash( $comment_author_email );
		$comment_author_email = esc_attr( $comment_author_email );

		$_COOKIE[ 'comment_author_email_' . COOKIEHASH ] = $comment_author_email;
	}

	if ( isset( $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] ) ) {
		/**
		 * Filters the comment author's URL cookie before it is set.
		 *
		 * When this filter hook is evaluated in wp_filter_comment(),
		 * the comment author's URL string is passed.
		 *
		 * @since 1.5.0
		 *
		 * @param string $author_url_cookie The comment author URL cookie.
		 */
		$comment_author_url = apply_filters( 'pre_comment_author_url', $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] );
		$comment_author_url = wp_unslash( $comment_author_url );

		$_COOKIE[ 'comment_author_url_' . COOKIEHASH ] = $comment_author_url;
	}
}