On this page
WP_REST_Global_Styles_Controller::get_post( int $id ): WP_Post|WP_Error
Get the post, if the ID is valid.
Parameters
$idint Required-
Supplied ID.
Return
WP_Post|WP_Error Post object if ID is valid, WP_Error otherwise.
Source
File: wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php. View all references
protected function get_post( $id ) {
$error = new WP_Error(
'rest_global_styles_not_found',
__( 'No global styles config exist with that id.' ),
array( 'status' => 404 )
);
$id = (int) $id;
if ( $id <= 0 ) {
return $error;
}
$post = get_post( $id );
if ( empty( $post ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) {
return $error;
}
return $post;
}
Related
Uses
| Uses | Description |
|---|---|
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
| WP_Error::__construct() wp-includes/class-wp-error.php | Initializes the error. |
Used By
| Used By | Description |
|---|---|
| WP_REST_Global_Styles_Controller::get_item_permissions_check() wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php | Checks if a given request has access to read a single global style. |
| WP_REST_Global_Styles_Controller::get_item() wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php | Returns the given global styles config. |
| WP_REST_Global_Styles_Controller::update_item_permissions_check() wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php | Checks if a given request has access to write a single global styles config. |
| WP_REST_Global_Styles_Controller::update_item() wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php | Updates a single global style config. |
Changelog
| Version | Description |
|---|---|
| 5.9.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_global_styles_controller/get_post