WP_REST_Posts_Controller::can_access_password_content()publicWP 4.7.0

Checks if the user can access password-protected content.

This method determines whether we need to override the regular password check in core with a filter.

Метод класса: WP_REST_Posts_Controller{}

Хуков нет.

Возвращает

true|false. True if the user can access password-protected content, otherwise false.

Использование

$WP_REST_Posts_Controller = new WP_REST_Posts_Controller();
$WP_REST_Posts_Controller->can_access_password_content( $post, $request );
$post(WP_Post) (обязательный)
Post to check against.
$request(WP_REST_Request) (обязательный)
Request data to check.

Список изменений

С версии 4.7.0 Введена.

Код WP_REST_Posts_Controller::can_access_password_content() WP 6.6.2

public function can_access_password_content( $post, $request ) {
	if ( empty( $post->post_password ) ) {
		// No filter required.
		return false;
	}

	/*
	 * Users always gets access to password protected content in the edit
	 * context if they have the `edit_post` meta capability.
	 */
	if (
		'edit' === $request['context'] &&
		current_user_can( 'edit_post', $post->ID )
	) {
		return true;
	}

	// No password, no auth.
	if ( empty( $request['password'] ) ) {
		return false;
	}

	// Double-check the request password.
	return hash_equals( $post->post_password, $request['password'] );
}