WordPress.org

Make WordPress Core

Ticket #38056: 38056.diff

File 38056.diff, 1.6 KB (added by rmccue, 5 years ago)

Filter the return value of post_password_required

  • src/wp-includes/post-template.php

     
    779779function post_password_required( $post = null ) {
    780780        $post = get_post($post);
    781781
    782         if ( empty( $post->post_password ) )
    783                 return false;
     782        if ( empty( $post->post_password ) ) {
     783                /** This filter is documented in wp-includes/post.php */
     784                return apply_filters( 'post_password_required', false, $post );
     785        }
    784786
    785         if ( ! isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) )
    786                 return true;
     787        if ( ! isset( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ) ) {
     788                /** This filter is documented in wp-includes/post.php */
     789                return apply_filters( 'post_password_required', true, $post );
     790        }
    787791
    788792        $hasher = new PasswordHash( 8, true );
    789793
    790794        $hash = wp_unslash( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] );
    791         if ( 0 !== strpos( $hash, '$P$B' ) )
    792                 return true;
     795        if ( 0 !== strpos( $hash, '$P$B' ) ) {
     796                $required = true;
     797        } else {
     798                $required = ! $hasher->CheckPassword( $post->post_password, $hash );
     799        }
    793800
    794         return ! $hasher->CheckPassword( $post->post_password, $hash );
     801        /**
     802         * Filter whether a post requires the user to supply a password.
     803         *
     804         * @param bool    $required Whether the user needs to supply a password. True if password has not been
     805         *                          provided or is incorrect, false if password has been supplied or is not required.
     806         * @param WP_Post $post Post data.
     807         */
     808        return apply_filters( 'post_password_required', $required, $post );
    795809}
    796810
    797811//