Make WordPress Core

Changeset 50732 for branches/4.9


Ignore:
Timestamp:
04/15/2021 01:11:06 AM (5 years ago)
Author:
peterwilsoncc
Message:

Grouped merges for 4.9.17.

  • REST API: Allow authors to read their own password protected posts.
  • About page update

Merges [50717] to the 4.9 branch.

Location:
branches/4.9/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9/src/wp-admin/about.php

    r49415 r50732  
    3434                <div class="changelog point-releases">
    3535                        <h3><?php _e( 'Maintenance and Security Releases' ); ?></h3>
     36                        <p>
     37                                <?php
     38                                printf(
     39                                        /* translators: %s: WordPress version number */
     40                                        __( '<strong>Version %s</strong> addressed some security issues.' ),
     41                                        '4.9.17'
     42                                );
     43                                ?>
     44                                <?php
     45                                printf(
     46                                        /* translators: %s: HelpHub URL */
     47                                        __( 'For more information, see <a href="%s">the release notes</a>.' ),
     48                                        sprintf(
     49                                                /* translators: %s: WordPress version */
     50                                                esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
     51                                                sanitize_title( '4.9.17' )
     52                                        )
     53                                );
     54                                ?>
     55                        </p>
    3656                        <p>
    3757                                <?php
  • branches/4.9/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r46918 r50732  
    3232         */
    3333        protected $meta;
     34
     35        /**
     36         * Passwordless post access permitted.
     37         *
     38         * @since 5.7.1
     39         * @var int[]
     40         */
     41        protected $password_check_passed = array();
    3442
    3543        /**
    … …  
    139147
    140148        /**
     149         * Override the result of the post password check for REST requested posts.
     150         *
     151         * Allow users to read the content of password protected posts if they have
     152         * previously passed a permission check or if they have the `edit_post` capability
     153         * for the post being checked.
     154         *
     155         * @since 5.7.1
     156         *
     157         * @param bool    $required Whether the post requires a password check.
     158         * @param WP_Post $post     The post been password checked.
     159         * @return bool Result of password check taking in to account REST API considerations.
     160         */
     161        public function check_password_required( $required, $post ) {
     162                if ( ! $required ) {
     163                        return $required;
     164                }
     165
     166                $post = get_post( $post );
     167
     168                if ( ! $post ) {
     169                        return $required;
     170                }
     171
     172                if ( ! empty( $this->password_check_passed[ $post->ID ] ) ) {
     173                        // Password previously checked and approved.
     174                        return false;
     175                }
     176
     177                return ! current_user_can( 'edit_post', $post->ID );
     178        }
     179
     180        /**
    141181         * Retrieves a collection of posts.
    142182         *
    … …  
    293333                // Allow access to all password protected posts if the context is edit.
    294334                if ( 'edit' === $request['context'] ) {
    295                         add_filter( 'post_password_required', '__return_false' );
     335                        add_filter( 'post_password_required', array( $this, 'check_password_required' ), 10, 2 );
    296336                }
    297337
    … …  
    309349                // Reset filter.
    310350                if ( 'edit' === $request['context'] ) {
    311                         remove_filter( 'post_password_required', '__return_false' );
     351                        remove_filter( 'post_password_required', array( $this, 'check_password_required' ) );
    312352                }
    313353
    … …  
    407447                // Allow access to all password protected posts if the context is edit.
    408448                if ( 'edit' === $request['context'] ) {
    409                         add_filter( 'post_password_required', '__return_false' );
     449                        add_filter( 'post_password_required', array( $this, 'check_password_required' ), 10, 2 );
    410450                }
    411451
    … …  
    435475                }
    436476
    437                 // Edit context always gets access to password-protected posts.
    438                 if ( 'edit' === $request['context'] ) {
     477                /*
     478                 * Users always gets access to password protected content in the edit
     479                 * context if they have the `edit_post` meta capability.
     480                 */
     481                if (
     482                        'edit' === $request['context'] &&
     483                        current_user_can( 'edit_post', $post->ID )
     484                ) {
    439485                        return true;
    440486                }
    … …  
    14861532
    14871533                if ( $this->can_access_password_content( $post, $request ) ) {
     1534                        $this->password_check_passed[ $post->ID ] = true;
    14881535                        // Allow access to the post, permissions already checked before.
    1489                         add_filter( 'post_password_required', '__return_false' );
     1536                        add_filter( 'post_password_required', array( $this, 'check_password_required' ), 10, 2 );
    14901537
    14911538                        $has_password_filter = true;
    … …  
    15131560                if ( $has_password_filter ) {
    15141561                        // Reset filter.
    1515                         remove_filter( 'post_password_required', '__return_false' );
     1562                        remove_filter( 'post_password_required', array( $this, 'check_password_required' ) );
    15161563                }
    15171564
Note: See TracChangeset for help on using the changeset viewer.