WP_REST_Posts_Controller::check_password_required( bool $required, WP_Post $post ): bool
- Since
- 5.7.1
- Source
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:188
Overrides the result of the post password check for REST requested posts.
Description
Allow users to read the content of password protected posts if they have previously passed a permission check or if they have the
edit_post capability for the post being checked.Parameters
$requiredbool- Whether the post requires a password check.
$postWP_Post- The post been password checked.
Return
bool- Result of password check taking into account REST API considerations.
Uses · 2
- get_post()Retrieves post data given a post ID or post object.
- current_user_can()Returns whether the current user has the specified capability.
Source
public function check_password_required( $required, $post ) { if ( ! $required ) { return $required; } $post = get_post( $post ); if ( ! $post ) { return $required; } if ( ! empty( $this->password_check_passed[ $post->ID ] ) ) { // Password previously checked and approved. return false; } return ! current_user_can( 'edit_post', $post->ID ); }History
Introduced in 5.7.1. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.