WP_REST_Posts_Controller::check_password_required() WordPress Method

The WP_REST_Posts_Controller::check_password_required() method is used to check if a post is password protected and if the correct password is supplied.

WP_REST_Posts_Controller::check_password_required( bool $required, WP_Post $post ) #

Override 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.


Top ↑

Parameters

$required

(bool)(Required)Whether the post requires a password check.

$post

(WP_Post)(Required)The post been password checked.


Top ↑

Return

(bool) Result of password check taking in to account REST API considerations.


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

	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 );
	}


Top ↑

Changelog

Changelog
VersionDescription
5.7.1Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.