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

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

$requiredboolrequired
Whether the post requires a password check.
$postWP_Postrequired
The post been password checked.

Return

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

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

Changelog

VersionDescription
5.7.1Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.