Changeset 50730 for branches/5.1/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
- Timestamp:
- 04/15/2021 01:09:07 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.1/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r46907 r50730 32 32 */ 33 33 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(); 34 42 35 43 /** … … 144 152 145 153 return true; 154 } 155 156 /** 157 * Override the result of the post password check for REST requested posts. 158 * 159 * Allow users to read the content of password protected posts if they have 160 * previously passed a permission check or if they have the `edit_post` capability 161 * for the post being checked. 162 * 163 * @since 5.7.1 164 * 165 * @param bool $required Whether the post requires a password check. 166 * @param WP_Post $post The post been password checked. 167 * @return bool Result of password check taking in to account REST API considerations. 168 */ 169 public function check_password_required( $required, $post ) { 170 if ( ! $required ) { 171 return $required; 172 } 173 174 $post = get_post( $post ); 175 176 if ( ! $post ) { 177 return $required; 178 } 179 180 if ( ! empty( $this->password_check_passed[ $post->ID ] ) ) { 181 // Password previously checked and approved. 182 return false; 183 } 184 185 return ! current_user_can( 'edit_post', $post->ID ); 146 186 } 147 187 … … 301 341 // Allow access to all password protected posts if the context is edit. 302 342 if ( 'edit' === $request['context'] ) { 303 add_filter( 'post_password_required', '__return_false');343 add_filter( 'post_password_required', array( $this, 'check_password_required' ), 10, 2 ); 304 344 } 305 345 … … 317 357 // Reset filter. 318 358 if ( 'edit' === $request['context'] ) { 319 remove_filter( 'post_password_required', '__return_false');359 remove_filter( 'post_password_required', array( $this, 'check_password_required' ) ); 320 360 } 321 361 … … 415 455 // Allow access to all password protected posts if the context is edit. 416 456 if ( 'edit' === $request['context'] ) { 417 add_filter( 'post_password_required', '__return_false');457 add_filter( 'post_password_required', array( $this, 'check_password_required' ), 10, 2 ); 418 458 } 419 459 … … 443 483 } 444 484 445 // Edit context always gets access to password-protected posts. 446 if ( 'edit' === $request['context'] ) { 485 /* 486 * Users always gets access to password protected content in the edit 487 * context if they have the `edit_post` meta capability. 488 */ 489 if ( 490 'edit' === $request['context'] && 491 current_user_can( 'edit_post', $post->ID ) 492 ) { 447 493 return true; 448 494 } … … 1520 1566 1521 1567 if ( $this->can_access_password_content( $post, $request ) ) { 1568 $this->password_check_passed[ $post->ID ] = true; 1522 1569 // Allow access to the post, permissions already checked before. 1523 add_filter( 'post_password_required', '__return_false');1570 add_filter( 'post_password_required', array( $this, 'check_password_required' ), 10, 2 ); 1524 1571 1525 1572 $has_password_filter = true; … … 1548 1595 if ( $has_password_filter ) { 1549 1596 // Reset filter. 1550 remove_filter( 'post_password_required', '__return_false');1597 remove_filter( 'post_password_required', array( $this, 'check_password_required' ) ); 1551 1598 } 1552 1599
Note: See TracChangeset
for help on using the changeset viewer.