post_password_required()

 

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-template.php */
		return apply_filters( 'post_password_required', false, $post );
	}

	if ( ! isset( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ) ) {
		/** This filter is documented in wp-includes/post-template.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 );
}

参数:post_password_required( int|WP_Post|null $post = null )

An optional post. Global $post used if not provided.

(bool)如果不需要密码或存在正确的密码cookie,则为false,否则为true。

$post

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

Default value: null

{acontent3}

You must log in before being able to contribute a note or feedback.

41.67% (10) 次Baidu访问
4.17% (1) 次Google访问
54.17% (13) 次Sogou访问
  • 蜘蛛:Baidu,10次,更新时间:2019-05-20 05:42:46
  • 蜘蛛:Google,1次,更新时间:2019-04-29 10:47:10
  • 蜘蛛:Sogou,13次,更新时间:2019-05-05 11:33:51

参与评论