[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/rest-api/endpoints/ -> class-wp-rest-posts-controller.php (summary)

REST API: WP_REST_Posts_Controller class

File Size: 3113 lines (95 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP_REST_Posts_Controller:: (40 methods):
  __construct()
  register_routes()
  get_items_permissions_check()
  check_password_required()
  get_items()
  get_post()
  get_item_permissions_check()
  can_access_password_content()
  get_item()
  create_item_permissions_check()
  create_item()
  update_item_permissions_check()
  update_item()
  delete_item_permissions_check()
  delete_item()
  prepare_items_query()
  prepare_date_response()
  prepare_item_for_database()
  check_status()
  handle_status_param()
  handle_featured_media()
  check_template()
  handle_template()
  handle_terms()
  check_assign_terms_permission()
  check_is_post_type_allowed()
  check_read_permission()
  check_update_permission()
  check_create_permission()
  check_delete_permission()
  prepare_item_for_response()
  protected_title_format()
  prepare_links()
  get_available_actions()
  get_item_schema()
  get_schema_links()
  get_collection_params()
  sanitize_post_statuses()
  prepare_tax_query()
  prepare_taxonomy_limit_schema()


Class: WP_REST_Posts_Controller  - X-Ref

Core class to access posts via the REST API.

__construct( $post_type )   X-Ref
Constructor.

since: 4.7.0
param: string $post_type Post type.

register_routes()   X-Ref
Registers the routes for posts.

since: 4.7.0

get_items_permissions_check( $request )   X-Ref
Checks if a given request has access to read posts.

return: true|WP_Error True if the request has read access, WP_Error object otherwise.
since: 4.7.0
param: WP_REST_Request $request Full details about the request.

check_password_required( $required, $post )   X-Ref
Override the result of the post password check for REST requested posts.

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.

return: bool Result of password check taking in to account REST API considerations.
since: 5.7.1
param: bool    $required Whether the post requires a password check.
param: WP_Post $post     The post been password checked.

get_items( $request )   X-Ref
Retrieves a collection of posts.

return: WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
since: 4.7.0
param: WP_REST_Request $request Full details about the request.

get_post( $id )   X-Ref
Get the post, if the ID is valid.

return: WP_Post|WP_Error Post object if ID is valid, WP_Error otherwise.
since: 4.7.2
param: int $id Supplied ID.

get_item_permissions_check( $request )   X-Ref
Checks if a given request has access to read a post.

return: true|WP_Error True if the request has read access for the item, WP_Error object otherwise.
since: 4.7.0
param: WP_REST_Request $request Full details about the request.

can_access_password_content( $post, $request )   X-Ref
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.

return: bool True if the user can access password-protected content, otherwise false.
since: 4.7.0
param: WP_Post         $post    Post to check against.
param: WP_REST_Request $request Request data to check.

get_item( $request )   X-Ref
Retrieves a single post.

return: WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
since: 4.7.0
param: WP_REST_Request $request Full details about the request.

create_item_permissions_check( $request )   X-Ref
Checks if a given request has access to create a post.

return: true|WP_Error True if the request has access to create items, WP_Error object otherwise.
since: 4.7.0
param: WP_REST_Request $request Full details about the request.

create_item( $request )   X-Ref
Creates a single post.

return: WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
since: 4.7.0
param: WP_REST_Request $request Full details about the request.

update_item_permissions_check( $request )   X-Ref
Checks if a given request has access to update a post.

return: true|WP_Error True if the request has access to update the item, WP_Error object otherwise.
since: 4.7.0
param: WP_REST_Request $request Full details about the request.

update_item( $request )   X-Ref
Updates a single post.

return: WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
since: 4.7.0
param: WP_REST_Request $request Full details about the request.

delete_item_permissions_check( $request )   X-Ref
Checks if a given request has access to delete a post.

return: true|WP_Error True if the request has access to delete the item, WP_Error object otherwise.
since: 4.7.0
param: WP_REST_Request $request Full details about the request.

delete_item( $request )   X-Ref
Deletes a single post.

return: WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
since: 4.7.0
param: WP_REST_Request $request Full details about the request.

prepare_items_query( $prepared_args = array()   X-Ref
Determines the allowed query_vars for a get_items() response and prepares
them for WP_Query.

return: array Items query arguments.
since: 4.7.0
param: array           $prepared_args Optional. Prepared WP_Query arguments. Default empty array.
param: WP_REST_Request $request       Optional. Full details about the request.

prepare_date_response( $date_gmt, $date = null )   X-Ref
Checks the post_date_gmt or modified_gmt and prepare any post or
modified date for single post output.

return: string|null ISO8601/RFC3339 formatted datetime.
since: 4.7.0
param: string      $date_gmt GMT publication time.
param: string|null $date     Optional. Local publication time. Default null.

prepare_item_for_database( $request )   X-Ref
Prepares a single post for create or update.

return: stdClass|WP_Error Post object or WP_Error.
since: 4.7.0
param: WP_REST_Request $request Request object.

check_status( $status, $request, $param )   X-Ref
Checks whether the status is valid for the given post.

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

return: true|WP_Error True if the status is valid, or WP_Error if not.
since: 5.6.0
param: string          $status  The provided status.
param: WP_REST_Request $request The request object.
param: string          $param   The parameter name.

handle_status_param( $post_status, $post_type )   X-Ref
Determines validity and normalizes the given status parameter.

return: string|WP_Error Post status or WP_Error if lacking the proper permission.
since: 4.7.0
param: string       $post_status Post status.
param: WP_Post_Type $post_type   Post type.

handle_featured_media( $featured_media, $post_id )   X-Ref
Determines the featured media based on a request param.

return: bool|WP_Error Whether the post thumbnail was successfully deleted, otherwise WP_Error.
since: 4.7.0
param: int $featured_media Featured Media ID.
param: int $post_id        Post ID.

check_template( $template, $request )   X-Ref
Check whether the template is valid for the given post.

return: bool|WP_Error True if template is still valid or if the same as existing value, or false if template not supported.
since: 4.9.0
param: string          $template Page template filename.
param: WP_REST_Request $request  Request.

handle_template( $template, $post_id, $validate = false )   X-Ref
Sets the template for a post.

since: 4.7.0
since: 4.9.0 Added the `$validate` parameter.
param: string $template Page template filename.
param: int    $post_id  Post ID.
param: bool   $validate Whether to validate that the template selected is valid.

handle_terms( $post_id, $request )   X-Ref
Updates the post's terms from a REST request.

return: null|WP_Error WP_Error on an error assigning any of the terms, otherwise null.
since: 4.7.0
param: int             $post_id The post ID to update the terms form.
param: WP_REST_Request $request The request object with post and terms data.

check_assign_terms_permission( $request )   X-Ref
Checks whether current user can assign all terms sent with the current request.

return: bool Whether the current user can assign the provided terms.
since: 4.7.0
param: WP_REST_Request $request The request object with post and terms data.

check_is_post_type_allowed( $post_type )   X-Ref
Checks if a given post type can be viewed or managed.

return: bool Whether the post type is allowed in REST.
since: 4.7.0
param: WP_Post_Type|string $post_type Post type name or object.

check_read_permission( $post )   X-Ref
Checks if a post can be read.

Correctly handles posts with the inherit status.

return: bool Whether the post can be read.
since: 4.7.0
param: WP_Post $post Post object.

check_update_permission( $post )   X-Ref
Checks if a post can be edited.

return: bool Whether the post can be edited.
since: 4.7.0
param: WP_Post $post Post object.

check_create_permission( $post )   X-Ref
Checks if a post can be created.

return: bool Whether the post can be created.
since: 4.7.0
param: WP_Post $post Post object.

check_delete_permission( $post )   X-Ref
Checks if a post can be deleted.

return: bool Whether the post can be deleted.
since: 4.7.0
param: WP_Post $post Post object.

prepare_item_for_response( $item, $request )   X-Ref
Prepares a single post output for response.

return: WP_REST_Response Response object.
since: 4.7.0
since: 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support.
param: WP_Post         $item    Post object.
param: WP_REST_Request $request Request object.

protected_title_format()   X-Ref
Overwrites the default protected title format.

By default, WordPress will show password protected posts with a title of
"Protected: %s", as the REST API communicates the protected status of a post
in a machine readable format, we remove the "Protected: " prefix.

return: string Protected title format.
since: 4.7.0

prepare_links( $post )   X-Ref
Prepares links for the request.

return: array Links for the given post.
since: 4.7.0
param: WP_Post $post Post object.

get_available_actions( $post, $request )   X-Ref
Get the link relations available for the post and current user.

return: array List of link relations.
since: 4.9.8
param: WP_Post         $post    Post object.
param: WP_REST_Request $request Request object.

get_item_schema()   X-Ref
Retrieves the post's schema, conforming to JSON Schema.

return: array Item schema data.
since: 4.7.0

get_schema_links()   X-Ref
Retrieve Link Description Objects that should be added to the Schema for the posts collection.

return: array
since: 4.9.8

get_collection_params()   X-Ref
Retrieves the query params for the posts collection.

return: array Collection parameters.
since: 4.7.0
since: 5.4.0 The `tax_relation` query parameter was added.
since: 5.7.0 The `modified_after` and `modified_before` query parameters were added.

sanitize_post_statuses( $statuses, $request, $parameter )   X-Ref
Sanitizes and validates the list of post statuses, including whether the
user can query private statuses.

return: array|WP_Error A list of valid statuses, otherwise WP_Error object.
since: 4.7.0
param: string|array    $statuses  One or more post statuses.
param: WP_REST_Request $request   Full details about the request.
param: string          $parameter Additional parameter to pass to validation.

prepare_tax_query( array $args, WP_REST_Request $request )   X-Ref
Prepares the 'tax_query' for a collection of posts.

return: array Updated query arguments.
since: 5.7.0
param: array           $args    WP_Query arguments.
param: WP_REST_Request $request Full details about the request.

prepare_taxonomy_limit_schema( array $query_params )   X-Ref
Prepares the collection schema for including and excluding items by terms.

return: array Updated schema.
since: 5.7.0
param: array $query_params Collection schema.



Generated: Tue Dec 24 01:00:02 2024 Cross-referenced by PHPXref 0.7.1