wp_get_current_commenter() WordPress Function

The wp_get_current_commenter function is used to get the current commenter's IP address, name, email, and URL. This information is used by WordPress to populate the fields in the comment form. This function returns an array of the commenter's data.

wp_get_current_commenter() #

Gets current commenter’s name, email, and URL.


Description

Expects cookies content to already be sanitized. User of this function might wish to recheck the returned array for validity.

Top ↑

See also


Top ↑

Return

(array) An array of current commenter variables.

  • 'comment_author'
    (string) The name of the current commenter, or an empty string.
  • 'comment_author_email'
    (string) The email address of the current commenter, or an empty string.
  • 'comment_author_url'
    (string) The URL address of the current commenter, or an empty string.


Top ↑

Source

File: wp-includes/comment.php

function wp_get_current_commenter() {
	// Cookies should already be sanitized.

	$comment_author = '';
	if ( isset( $_COOKIE[ 'comment_author_' . COOKIEHASH ] ) ) {
		$comment_author = $_COOKIE[ 'comment_author_' . COOKIEHASH ];
	}

	$comment_author_email = '';
	if ( isset( $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ) ) {
		$comment_author_email = $_COOKIE[ 'comment_author_email_' . COOKIEHASH ];
	}

	$comment_author_url = '';
	if ( isset( $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] ) ) {
		$comment_author_url = $_COOKIE[ 'comment_author_url_' . COOKIEHASH ];
	}

	/**
	 * Filters the current commenter's name, email, and URL.
	 *
	 * @since 3.1.0
	 *
	 * @param array $comment_author_data {
	 *     An array of current commenter variables.
	 *
	 *     @type string $comment_author       The name of the current commenter, or an empty string.
	 *     @type string $comment_author_email The email address of the current commenter, or an empty string.
	 *     @type string $comment_author_url   The URL address of the current commenter, or an empty string.
	 * }
	 */
	return apply_filters( 'wp_get_current_commenter', compact( 'comment_author', 'comment_author_email', 'comment_author_url' ) );
}


Top ↑

Changelog

Changelog
VersionDescription
2.0.4Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More