wp_get_current_commenter

函数
wp_get_current_commenter ( No parameters )
返回值
  • (array) { 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. }
相关
  • sanitize_comment_cookies()
定义位置
相关方法
wp_get_current_user_wp_get_current_userwp_set_current_userwp_count_commentsget_current_screen
引入
2.0.4
弃用
-

wp_get_current_commenter: 这个函数返回一个关于当前登录的评论者的信息数组,如果用户没有登录,则返回一个占位符数组。该数组包括评论者的姓名、电子邮件和URL。

获取当前评论者的姓名、电子邮件和URL。

希望cookies的内容已经被净化: 该函数的用户可能希望重新检查返回的数组是否有效。

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' ) );
}

常见问题

FAQs
查看更多 >