WP_REST_Posts_Controller::check_status() WordPress Method

The WP_REST_Posts_Controller::check_status() method is used to check the post status for a given post. This is useful for determining if a post is published or not, as well as for checking if a post is trashed or not.

WP_REST_Posts_Controller::check_status( string $status, WP_REST_Request $request, string $param ) #

Checks whether the status is valid for the given post.


Description

Allows for sending an update request with the current status, even if that status would not be acceptable.


Top ↑

Parameters

$status

(string)(Required)The provided status.

$request

(WP_REST_Request)(Required)The request object.

$param

(string)(Required)The parameter name.


Top ↑

Return

(true|WP_Error) True if the status is valid, or WP_Error if not.


Top ↑

Source

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

	public function check_status( $status, $request, $param ) {
		if ( $request['id'] ) {
			$post = $this->get_post( $request['id'] );

			if ( ! is_wp_error( $post ) && $post->post_status === $status ) {
				return true;
			}
		}

		$args = $request->get_attributes()['args'][ $param ];

		return rest_validate_value_from_schema( $status, $args, $param );
	}


Top ↑

Changelog

Changelog
VersionDescription
5.6.0Introduced.

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.