wp_get_unapproved_comment_author_email() WordPress Function

The wp_get_unapproved_comment_author_email() function allows you to get the email address of the author of a comment that is awaiting approval. This is useful if you want to notify the author that their comment is awaiting approval.

wp_get_unapproved_comment_author_email() #

Gets unapproved comment author’s email.


Description

Used to allow the commenter to see their pending comment.


Top ↑

Return

(string) The unapproved comment author's email (when supplied).


Top ↑

Source

File: wp-includes/comment.php

function wp_get_unapproved_comment_author_email() {
	$commenter_email = '';

	if ( ! empty( $_GET['unapproved'] ) && ! empty( $_GET['moderation-hash'] ) ) {
		$comment_id = (int) $_GET['unapproved'];
		$comment    = get_comment( $comment_id );

		if ( $comment && hash_equals( $_GET['moderation-hash'], wp_hash( $comment->comment_date_gmt ) ) ) {
			// The comment will only be viewable by the comment author for 10 minutes.
			$comment_preview_expires = strtotime( $comment->comment_date_gmt . '+10 minutes' );

			if ( time() < $comment_preview_expires ) {
				$commenter_email = $comment->comment_author_email;
			}
		}
	}

	if ( ! $commenter_email ) {
		$commenter       = wp_get_current_commenter();
		$commenter_email = $commenter['comment_author_email'];
	}

	return $commenter_email;
}


Top ↑

Changelog

Changelog
VersionDescription
5.7.0The window within which the author email for an unapproved comment can be retrieved was extended to 10 minutes.
5.1.0Introduced.

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