Changeset 50728 for branches/5.3/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
- Timestamp:
- 04/15/2021 01:07:14 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.3/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r46897 r50728 31 31 */ 32 32 protected $meta; 33 34 /** 35 * Passwordless post access permitted. 36 * 37 * @since 5.7.1 38 * @var int[] 39 */ 40 protected $password_check_passed = array(); 33 41 34 42 /** … … 143 151 144 152 return true; 153 } 154 155 /** 156 * Override the result of the post password check for REST requested posts. 157 * 158 * Allow users to read the content of password protected posts if they have 159 * previously passed a permission check or if they have the `edit_post` capability 160 * for the post being checked. 161 * 162 * @since 5.7.1 163 * 164 * @param bool $required Whether the post requires a password check. 165 * @param WP_Post $post The post been password checked. 166 * @return bool Result of password check taking in to account REST API considerations. 167 */ 168 public function check_password_required( $required, $post ) { 169 if ( ! $required ) { 170 return $required; 171 } 172 173 $post = get_post( $post ); 174 175 if ( ! $post ) { 176 return $required; 177 } 178 179 if ( ! empty( $this->password_check_passed[ $post->ID ] ) ) { 180 // Password previously checked and approved. 181 return false; 182 } 183 184 return ! current_user_can( 'edit_post', $post->ID ); 145 185 } 146 186 … … 300 340 // Allow access to all password protected posts if the context is edit. 301 341 if ( 'edit' === $request['context'] ) { 302 add_filter( 'post_password_required', '__return_false');342 add_filter( 'post_password_required', array( $this, 'check_password_required' ), 10, 2 ); 303 343 } 304 344 … … 316 356 // Reset filter. 317 357 if ( 'edit' === $request['context'] ) { 318 remove_filter( 'post_password_required', '__return_false');358 remove_filter( 'post_password_required', array( $this, 'check_password_required' ) ); 319 359 } 320 360 … … 414 454 // Allow access to all password protected posts if the context is edit. 415 455 if ( 'edit' === $request['context'] ) { 416 add_filter( 'post_password_required', '__return_false');456 add_filter( 'post_password_required', array( $this, 'check_password_required' ), 10, 2 ); 417 457 } 418 458 … … 442 482 } 443 483 444 // Edit context always gets access to password-protected posts. 445 if ( 'edit' === $request['context'] ) { 484 /* 485 * Users always gets access to password protected content in the edit 486 * context if they have the `edit_post` meta capability. 487 */ 488 if ( 489 'edit' === $request['context'] && 490 current_user_can( 'edit_post', $post->ID ) 491 ) { 446 492 return true; 447 493 } … … 1534 1580 1535 1581 if ( $this->can_access_password_content( $post, $request ) ) { 1582 $this->password_check_passed[ $post->ID ] = true; 1536 1583 // Allow access to the post, permissions already checked before. 1537 add_filter( 'post_password_required', '__return_false');1584 add_filter( 'post_password_required', array( $this, 'check_password_required' ), 10, 2 ); 1538 1585 1539 1586 $has_password_filter = true; … … 1569 1616 if ( $has_password_filter ) { 1570 1617 // Reset filter. 1571 remove_filter( 'post_password_required', '__return_false');1618 remove_filter( 'post_password_required', array( $this, 'check_password_required' ) ); 1572 1619 } 1573 1620
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)