返回介绍

post_password_required()

发布于 2017-09-11 09:57:03 字数 3395 浏览 1400 评论 0 收藏 0

post_password_required( int|WP_Post|null $post = null )

Whether post requires password and correct password has been provided.


description


参数

$post

(int|WP_Post|null) (Optional) An optional post. Global $post used if not provided.

Default value: null


返回值

(bool) false if a password is not required or the correct password cookie is present, true otherwise.


源代码

File: wp-includes/post-template.php

function post_password_required( $post = null ) {
	$post = get_post($post);

	if ( empty( $post->post_password ) ) {
		/** This filter is documented in wp-includes/post.php */
		return apply_filters( 'post_password_required', false, $post );
	}

	if ( ! isset( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ) ) {
		/** This filter is documented in wp-includes/post.php */
		return apply_filters( 'post_password_required', true, $post );
	}

	require_once ABSPATH . WPINC . '/class-phpass.php';
	$hasher = new PasswordHash( 8, true );

	$hash = wp_unslash( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] );
	if ( 0 !== strpos( $hash, '$P$B' ) ) {
		$required = true;
	} else {
		$required = ! $hasher->CheckPassword( $post->post_password, $hash );
	}

	/**
	 * Filters whether a post requires the user to supply a password.
	 *
	 * @since 4.7.0
	 *
	 * @param bool    $required Whether the user needs to supply a password. True if password has not been
	 *                          provided or is incorrect, false if password has been supplied or is not required.
	 * @param WP_Post $post     Post data.
	 */
	return apply_filters( 'post_password_required', $required, $post );
}

更新日志

Versiondescription
2.7.0Introduced.

相关函数

Uses

  • wp-includes/post-template.php: post_password_required
  • wp-includes/formatting.php: wp_unslash()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/post.php: get_post()

Used By

  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::prepare_item_for_response()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::prepare_item_for_database()
  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::check_read_post_permission()
  • wp-includes/comment.php: wp_handle_comment_submission()
  • wp-includes/feed.php: rss_enclosure()
  • wp-includes/feed.php: atom_enclosure()
  • wp-includes/post-template.php: get_the_content()
  • wp-includes/post-template.php: get_the_excerpt()
  • wp-includes/post-template.php: get_post_class()
  • wp-includes/comment-template.php: comments_popup_link()
  • Show 5 more used by Hide more used by

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文