PHP Класс WP_REST_Posts_Controller, wordpress

См. также: WP_REST_Controller
С версии: 4.7.0
Наследование: extends WP_REST_Controller
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$meta WP_REST_Post_Meta_Fields Instance of a post meta fields object.
$post_type string Post type.

Открытые методы

Метод Описание
__construct ( string $post_type ) Constructor.
can_access_password_content ( WP_Post $post, WP_REST_Request $request ) : boolean Checks if the user can access password-protected content.
check_read_permission ( object $post ) : boolean Checks if a post can be read.
create_item ( WP_REST_Request $request ) : WP_REST_Response | WP_Error Creates a single post.
create_item_permissions_check ( WP_REST_Request $request ) : true | WP_Error Checks if a given request has access to create a post.
delete_item ( WP_REST_Request $request ) : WP_REST_Response | WP_Error Deletes a single post.
delete_item_permissions_check ( WP_REST_Request $request ) : true | WP_Error Checks if a given request has access to delete a post.
get_collection_params ( ) : array Retrieves the query params for the posts collection.
get_item ( WP_REST_Request $request ) : WP_REST_Response | WP_Error Retrieves a single post.
get_item_permissions_check ( WP_REST_Request $request ) : boolean | WP_Error Checks if a given request has access to read a post.
get_item_schema ( ) : array Retrieves the post's schema, conforming to JSON Schema.
get_items ( WP_REST_Request $request ) : WP_REST_Response | WP_Error Retrieves a collection of posts.
get_items_permissions_check ( WP_REST_Request $request ) : true | WP_Error Checks if a given request has access to read posts.
handle_template ( string $template, integer $post_id ) Sets the template for a post.
prepare_item_for_response ( WP_Post $post, WP_REST_Request $request ) : WP_REST_Response Prepares a single post output for response.
protected_title_format ( ) : string Overwrites the default protected title format.
register_routes ( ) Registers the routes for the objects of the controller.
sanitize_post_statuses ( string | array $statuses, WP_REST_Request $request, string $parameter ) : array | WP_Error Sanitizes and validates the list of post statuses, including whether the user can query private statuses.
update_item ( WP_REST_Request $request ) : WP_REST_Response | WP_Error Updates a single post.
update_item_permissions_check ( WP_REST_Request $request ) : true | WP_Error Checks if a given request has access to update a post.

Защищенные методы

Метод Описание
check_assign_terms_permission ( WP_REST_Request $request ) : boolean Checks whether current user can assign all terms sent with the current request.
check_create_permission ( object $post ) : boolean Checks if a post can be created.
check_delete_permission ( object $post ) : boolean Checks if a post can be deleted.
check_is_post_type_allowed ( object | string $post_type ) : boolean Checks if a given post type can be viewed or managed.
check_update_permission ( object $post ) : boolean Checks if a post can be edited.
handle_featured_media ( integer $featured_media, integer $post_id ) : boolean | WP_Error Determines the featured media based on a request param.
handle_status_param ( string $post_status, object $post_type ) : string | WP_Error Determines validity and normalizes the given status parameter.
handle_terms ( integer $post_id, WP_REST_Request $request ) : null | WP_Error Updates the post's terms from a REST request.
prepare_date_response ( string $date_gmt, string | null $date = null ) : string | null Checks the post_date_gmt or modified_gmt and prepare any post or modified date for single post output.
prepare_item_for_database ( WP_REST_Request $request ) : stdClass | WP_Error Prepares a single post for create or update.
prepare_items_query ( array $prepared_args = [], WP_REST_Request $request = null ) : array Determines the allowed query_vars for a get_items() response and prepares them for WP_Query.
prepare_links ( WP_Post $post ) : array Prepares links for the request.

Описание методов

__construct() публичный Метод

Constructor.
С версии: 4.7.0
public __construct ( string $post_type )
$post_type string Post type.

can_access_password_content() публичный Метод

This method determines whether we need to override the regular password check in core with a filter.
С версии: 4.7.0
public can_access_password_content ( WP_Post $post, WP_REST_Request $request ) : boolean
$post WP_Post Post to check against.
$request WP_REST_Request Request data to check.
Результат boolean True if the user can access password-protected content, otherwise false.

check_assign_terms_permission() защищенный Метод

Checks whether current user can assign all terms sent with the current request.
С версии: 4.7.0
protected check_assign_terms_permission ( WP_REST_Request $request ) : boolean
$request WP_REST_Request The request object with post and terms data.
Результат boolean Whether the current user can assign the provided terms.

check_create_permission() защищенный Метод

Checks if a post can be created.
С версии: 4.7.0
protected check_create_permission ( object $post ) : boolean
$post object Post object.
Результат boolean Whether the post can be created.

check_delete_permission() защищенный Метод

Checks if a post can be deleted.
С версии: 4.7.0
protected check_delete_permission ( object $post ) : boolean
$post object Post object.
Результат boolean Whether the post can be deleted.

check_is_post_type_allowed() защищенный Метод

Checks if a given post type can be viewed or managed.
С версии: 4.7.0
protected check_is_post_type_allowed ( object | string $post_type ) : boolean
$post_type object | string Post type name or object.
Результат boolean Whether the post type is allowed in REST.

check_read_permission() публичный Метод

Correctly handles posts with the inherit status.
С версии: 4.7.0
public check_read_permission ( object $post ) : boolean
$post object Post object.
Результат boolean Whether the post can be read.

check_update_permission() защищенный Метод

Checks if a post can be edited.
С версии: 4.7.0
protected check_update_permission ( object $post ) : boolean
$post object Post object.
Результат boolean Whether the post can be edited.

create_item() публичный Метод

Creates a single post.
С версии: 4.7.0
public create_item ( WP_REST_Request $request ) : WP_REST_Response | WP_Error
$request WP_REST_Request Full details about the request.
Результат WP_REST_Response | WP_Error Response object on success, or WP_Error object on failure.

create_item_permissions_check() публичный Метод

Checks if a given request has access to create a post.
С версии: 4.7.0
public create_item_permissions_check ( WP_REST_Request $request ) : true | WP_Error
$request WP_REST_Request Full details about the request.
Результат true | WP_Error True if the request has access to create items, WP_Error object otherwise.

delete_item() публичный Метод

Deletes a single post.
С версии: 4.7.0
public delete_item ( WP_REST_Request $request ) : WP_REST_Response | WP_Error
$request WP_REST_Request Full details about the request.
Результат WP_REST_Response | WP_Error Response object on success, or WP_Error object on failure.

delete_item_permissions_check() публичный Метод

Checks if a given request has access to delete a post.
С версии: 4.7.0
public delete_item_permissions_check ( WP_REST_Request $request ) : true | WP_Error
$request WP_REST_Request Full details about the request.
Результат true | WP_Error True if the request has access to delete the item, WP_Error object otherwise.

get_collection_params() публичный Метод

Retrieves the query params for the posts collection.
С версии: 4.7.0
public get_collection_params ( ) : array
Результат array Collection parameters.

get_item() публичный Метод

Retrieves a single post.
С версии: 4.7.0
public get_item ( WP_REST_Request $request ) : WP_REST_Response | WP_Error
$request WP_REST_Request Full details about the request.
Результат WP_REST_Response | WP_Error Response object on success, or WP_Error object on failure.

get_item_permissions_check() публичный Метод

Checks if a given request has access to read a post.
С версии: 4.7.0
public get_item_permissions_check ( WP_REST_Request $request ) : boolean | WP_Error
$request WP_REST_Request Full details about the request.
Результат boolean | WP_Error True if the request has read access for the item, WP_Error object otherwise.

get_item_schema() публичный Метод

Retrieves the post's schema, conforming to JSON Schema.
С версии: 4.7.0
public get_item_schema ( ) : array
Результат array Item schema data.

get_items() публичный Метод

Retrieves a collection of posts.
С версии: 4.7.0
public get_items ( WP_REST_Request $request ) : WP_REST_Response | WP_Error
$request WP_REST_Request Full details about the request.
Результат WP_REST_Response | WP_Error Response object on success, or WP_Error object on failure.

get_items_permissions_check() публичный Метод

Checks if a given request has access to read posts.
С версии: 4.7.0
public get_items_permissions_check ( WP_REST_Request $request ) : true | WP_Error
$request WP_REST_Request Full details about the request.
Результат true | WP_Error True if the request has read access, WP_Error object otherwise.

handle_status_param() защищенный Метод

Determines validity and normalizes the given status parameter.
С версии: 4.7.0
protected handle_status_param ( string $post_status, object $post_type ) : string | WP_Error
$post_status string Post status.
$post_type object Post type.
Результат string | WP_Error Post status or WP_Error if lacking the proper permission.

handle_template() публичный Метод

Sets the template for a post.
С версии: 4.7.0
public handle_template ( string $template, integer $post_id )
$template string Page template filename.
$post_id integer Post ID.

handle_terms() защищенный Метод

Updates the post's terms from a REST request.
С версии: 4.7.0
protected handle_terms ( integer $post_id, WP_REST_Request $request ) : null | WP_Error
$post_id integer The post ID to update the terms form.
$request WP_REST_Request The request object with post and terms data.
Результат null | WP_Error WP_Error on an error assigning any of the terms, otherwise null.

prepare_date_response() защищенный Метод

Checks the post_date_gmt or modified_gmt and prepare any post or modified date for single post output.
С версии: 4.7.0
protected prepare_date_response ( string $date_gmt, string | null $date = null ) : string | null
$date_gmt string GMT publication time.
$date string | null Optional. Local publication time. Default null.
Результат string | null ISO8601/RFC3339 formatted datetime.

prepare_item_for_database() защищенный Метод

Prepares a single post for create or update.
С версии: 4.7.0
protected prepare_item_for_database ( WP_REST_Request $request ) : stdClass | WP_Error
$request WP_REST_Request Request object.
Результат stdClass | WP_Error Post object or WP_Error.

prepare_item_for_response() публичный Метод

Prepares a single post output for response.
С версии: 4.7.0
public prepare_item_for_response ( WP_Post $post, WP_REST_Request $request ) : WP_REST_Response
$post WP_Post Post object.
$request WP_REST_Request Request object.
Результат WP_REST_Response Response object.

prepare_items_query() защищенный Метод

Determines the allowed query_vars for a get_items() response and prepares them for WP_Query.
С версии: 4.7.0
protected prepare_items_query ( array $prepared_args = [], WP_REST_Request $request = null ) : array
$prepared_args array Optional. Prepared WP_Query arguments. Default empty array.
$request WP_REST_Request Optional. Full details about the request.
Результат array Items query arguments.

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.
public protected_title_format ( ) : string
Результат string Protected title format.

register_routes() публичный Метод

Registers the routes for the objects of the controller.
См. также: register_rest_route()
С версии: 4.7.0
public register_routes ( )

sanitize_post_statuses() публичный Метод

Sanitizes and validates the list of post statuses, including whether the user can query private statuses.
С версии: 4.7.0
public sanitize_post_statuses ( string | array $statuses, WP_REST_Request $request, string $parameter ) : array | WP_Error
$statuses string | array One or more post statuses.
$request WP_REST_Request Full details about the request.
$parameter string Additional parameter to pass to validation.
Результат array | WP_Error A list of valid statuses, otherwise WP_Error object.

update_item() публичный Метод

Updates a single post.
С версии: 4.7.0
public update_item ( WP_REST_Request $request ) : WP_REST_Response | WP_Error
$request WP_REST_Request Full details about the request.
Результат WP_REST_Response | WP_Error Response object on success, or WP_Error object on failure.

update_item_permissions_check() публичный Метод

Checks if a given request has access to update a post.
С версии: 4.7.0
public update_item_permissions_check ( WP_REST_Request $request ) : true | WP_Error
$request WP_REST_Request Full details about the request.
Результат true | WP_Error True if the request has access to update the item, WP_Error object otherwise.

Описание свойств

$meta защищенное свойство

Instance of a post meta fields object.
С версии: 4.7.0
protected WP_REST_Post_Meta_Fields $meta
Результат WP_REST_Post_Meta_Fields

$post_type защищенное свойство

Post type.
С версии: 4.7.0
protected string $post_type
Результат string