Changeset 50726 for branches/5.6/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
- Timestamp:
- 04/15/2021 01:06:00 AM (5 years ago)
- Location:
- branches/5.6
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/5.6
-
branches/5.6/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r49732 r50726 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 /** … … 147 155 148 156 return true; 157 } 158 159 /** 160 * Override the result of the post password check for REST requested posts. 161 * 162 * Allow users to read the content of password protected posts if they have 163 * previously passed a permission check or if they have the `edit_post` capability 164 * for the post being checked. 165 * 166 * @since 5.7.1 167 * 168 * @param bool $required Whether the post requires a password check. 169 * @param WP_Post $post The post been password checked. 170 * @return bool Result of password check taking in to account REST API considerations. 171 */ 172 public function check_password_required( $required, $post ) { 173 if ( ! $required ) { 174 return $required; 175 } 176 177 $post = get_post( $post ); 178 179 if ( ! $post ) { 180 return $required; 181 } 182 183 if ( ! empty( $this->password_check_passed[ $post->ID ] ) ) { 184 // Password previously checked and approved. 185 return false; 186 } 187 188 return ! current_user_can( 'edit_post', $post->ID ); 149 189 } 150 190 … … 316 356 // Allow access to all password protected posts if the context is edit. 317 357 if ( 'edit' === $request['context'] ) { 318 add_filter( 'post_password_required', '__return_false');358 add_filter( 'post_password_required', array( $this, 'check_password_required' ), 10, 2 ); 319 359 } 320 360 … … 332 372 // Reset filter. 333 373 if ( 'edit' === $request['context'] ) { 334 remove_filter( 'post_password_required', '__return_false');374 remove_filter( 'post_password_required', array( $this, 'check_password_required' ) ); 335 375 } 336 376 … … 447 487 // Allow access to all password protected posts if the context is edit. 448 488 if ( 'edit' === $request['context'] ) { 449 add_filter( 'post_password_required', '__return_false');489 add_filter( 'post_password_required', array( $this, 'check_password_required' ), 10, 2 ); 450 490 } 451 491 … … 475 515 } 476 516 477 // Edit context always gets access to password-protected posts. 478 if ( 'edit' === $request['context'] ) { 517 /* 518 * Users always gets access to password protected content in the edit 519 * context if they have the `edit_post` meta capability. 520 */ 521 if ( 522 'edit' === $request['context'] && 523 current_user_can( 'edit_post', $post->ID ) 524 ) { 479 525 return true; 480 526 } … … 1706 1752 1707 1753 if ( $this->can_access_password_content( $post, $request ) ) { 1754 $this->password_check_passed[ $post->ID ] = true; 1708 1755 // Allow access to the post, permissions already checked before. 1709 add_filter( 'post_password_required', '__return_false');1756 add_filter( 'post_password_required', array( $this, 'check_password_required' ), 10, 2 ); 1710 1757 1711 1758 $has_password_filter = true; … … 1745 1792 if ( $has_password_filter ) { 1746 1793 // Reset filter. 1747 remove_filter( 'post_password_required', '__return_false');1794 remove_filter( 'post_password_required', array( $this, 'check_password_required' ) ); 1748 1795 } 1749 1796
Note: See TracChangeset
for help on using the changeset viewer.