Commit d31057a0 authored by Aaron Jorbin's avatar Aaron Jorbin
Browse files

Posts: Add filter to allow overriding `post_password_required` return

Post Passwords are incredibly inflexible. One Password per site at a time and other limitations that can't really be changed without a backwards compatibility break.  This adds the ability for sites to change the password behavior such as doing per post passwords or allowing multiple passwords to be set in a browser. The possibilities are YUGE.

Additionally, it allows for a behavior other than returning a html form when a password is needed. This is important for non website use cases (such as in a restful API).

Fixes #38056. See #16483.
Props rmccue.


Built from https://develop.svn.wordpress.org/trunk@38603


git-svn-id: http://core.svn.wordpress.org/trunk@38546 1a063a9b-81f0-0310-95a4-ce76da25c4cd
parent dd6da701
......@@ -779,19 +779,33 @@ function get_body_class( $class = '' ) {
function post_password_required( $post = null ) {
$post = get_post($post);
if ( empty( $post->post_password ) )
return false;
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] ) )
return true;
if ( ! isset( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ) ) {
/** This filter is documented in wp-includes/post.php */
return apply_filters( 'post_password_required', true, $post );
}
$hasher = new PasswordHash( 8, true );
$hash = wp_unslash( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] );
if ( 0 !== strpos( $hash, '$P$B' ) )
return true;
if ( 0 !== strpos( $hash, '$P$B' ) ) {
$required = true;
} else {
$required = ! $hasher->CheckPassword( $post->post_password, $hash );
}
return ! $hasher->CheckPassword( $post->post_password, $hash );
/**
* Filter whether a post requires the user to supply a password.
*
* @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 );
}
//
......
......@@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.7-alpha-38602';
$wp_version = '4.7-alpha-38603';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment