WP_REST_Posts_Controller
- Since
- 4.7.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:17
Core class to access posts via the REST API.
Hooks fired · 19
Every hook that fires from inside WP_REST_Posts_Controller, in the order it appears in the class, grouped by the method that fires it.
WP_REST_Posts_Controller::create_item()
- do_action( rest_insert_{$this->post_type} )action line 808
- do_action( rest_after_insert_{$this->post_type} )action line 872
WP_REST_Posts_Controller::update_item()
- do_action( rest_insert_{$this->post_type} )action line 994
- do_action( rest_after_insert_{$this->post_type} )action line 1048
WP_REST_Posts_Controller::delete_item()
- apply_filters( rest_{$this->post_type}_trashable )filter line 1123
- do_action( rest_delete_{$this->post_type} )action line 1200
WP_REST_Posts_Controller::prepare_items_query()
- apply_filters( rest_query_var-{$key} )filter line 1231
WP_REST_Posts_Controller::prepare_item_for_database()
- apply_filters( rest_block_hooks_post_types )filter line 1508
- apply_filters( rest_pre_insert_{$this->post_type} )filter line 1531
WP_REST_Posts_Controller::prepare_item_for_response()
- apply_filters( rest_prepare_{$this->post_type} )filter line 1896
- apply_filters( get_the_guid )filter line 1930
- apply_filters( the_content )filter line 2007
- apply_filters( get_the_excerpt )filter line 2031
- apply_filters( the_excerpt )filter line 2034
- apply_filters( rest_block_hooks_post_types )filter line 2176
- apply_filters( rest_prepare_{$this->post_type} )filter line 2199
Properties · 4
$post_typestringprotected- Post type.
$metaWP_REST_Post_Meta_Fieldsprotected- Instance of a post meta fields object.
$password_check_passedint[]protected- Passwordless post access permitted.
$allow_batcharrayprotected- Whether the controller supports batching.
Methods · 40
- __construct()Constructor.
- register_routes()Registers the routes for posts.
- get_items_permissions_check()Checks if a given request has access to read posts.
- check_password_required()Overrides the result of the post password check for REST requested posts.
- get_items()Retrieves a collection of posts.
- get_post()Gets the post, if the ID is valid.
- get_item_permissions_check()Checks if a given request has access to read a post.
- can_access_password_content()Checks if the user can access password-protected content.
- get_item()Retrieves a single post.
- create_item_permissions_check()Checks if a given request has access to create a post.
- create_item()Creates a single post.
- update_item_permissions_check()Checks if a given request has access to update a post.
- update_item()Updates a single post.
- delete_item_permissions_check()Checks if a given request has access to delete a post.
- delete_item()Deletes a single post.
- prepare_items_query()Determines the allowed query_vars for a get_items() response and prepares them for WP_Query.
- prepare_date_response()Checks the post_date_gmt or modified_gmt and prepare any post or modified date for single post output.
- prepare_item_for_database()Prepares a single post for create or update.
- check_status()Checks whether the status is valid for the given post.
- handle_status_param()Determines validity and normalizes the given status parameter.
- handle_featured_media()Determines the featured media based on a request param.
- check_template()Checks whether the template is valid for the given post.
- handle_template()Sets the template for a post.
- handle_terms()Updates the post's terms from a REST request.
- check_assign_terms_permission()Checks whether current user can assign all terms sent with the current request.
- check_is_post_type_allowed()Checks if a given post type can be viewed or managed.
- check_read_permission()Checks if a post can be read.
- check_update_permission()Checks if a post can be edited.
- check_create_permission()Checks if a post can be created.
- check_delete_permission()Checks if a post can be deleted.
- prepare_item_for_response()Prepares a single post output for response.
- protected_title_format()Overwrites the default protected and private title format.
- prepare_links()Prepares links for the request.
- get_available_actions()Gets the link relations available for the post and current user.
- get_item_schema()Retrieves the post's schema, conforming to JSON Schema.
- get_schema_links()Retrieves Link Description Objects that should be added to the Schema for the posts collection.
- get_collection_params()Retrieves the query params for the posts collection.
- sanitize_post_statuses()Sanitizes and validates the list of post statuses, including whether the user can query private statuses.
- prepare_tax_query()Prepares the 'tax_query' for a collection of posts.
- prepare_taxonomy_limit_schema()Prepares the collection schema for including and excluding items by terms.
Source
class WP_REST_Posts_Controller extends WP_REST_Controller { /** * Post type. * * @since 4.7.0 * @var string */ protected $post_type; /** * Instance of a post meta fields object. * * @since 4.7.0 * @var WP_REST_Post_Meta_Fields */ protected $meta; /** * Passwordless post access permitted. * * @since 5.7.1 * @var int[] */ protected $password_check_passed = array(); /** * Whether the controller supports batching. * * @since 5.9.0 * @var array */ protected $allow_batch = array( 'v1' => true ); /** * Constructor. * * @since 4.7.0 * * @param string $post_type Post type. */ public function __construct( $post_type ) { $this->post_type = $post_type; $obj = get_post_type_object( $post_type ); $this->rest_base = ! empty( $obj->rest_base ) ? $obj->rest_base : $obj->name; $this->namespace = ! empty( $obj->rest_namespace ) ? $obj->rest_namespace : 'wp/v2'; $this->meta = new WP_REST_Post_Meta_Fields( $this->post_type ); } /** * Registers the routes for posts. * * @since 4.7.0 * * @see register_rest_route() */ public function register_routes() { register_rest_route( $this->namespace, '/' . $this->rest_base, array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => $this->get_collection_params(), ), array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => array( $this, 'create_item' ), 'permission_callback' => array( $this, 'create_item_permissions_check' ), 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), ), 'allow_batch' => $this->allow_batch, 'schema' => array( $this, 'get_public_item_schema' ), ) ); $schema = $this->get_item_schema();History
Introduced in 4.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.