PHP Class WP_REST_Attachments_Controller, wordpress

Inheritance: extends WP_REST_Posts_Controller
Datei anzeigen Open project: johnpbloch/wordpress Class Usage Examples

Public Methods

Method Description
create_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response Creates a single attachment.
create_item_permissions_check ( WP_REST_Request $request ) : WP_Error | true Checks if a given request has access to create an attachment.
get_collection_params ( ) : array Retrieves the query params for collections of attachments.
get_filename_from_disposition ( string[] $disposition_header ) : string | null Parses filename from a Content-Disposition header value.
get_item_schema ( ) : array Retrieves the attachment's schema, conforming to JSON Schema.
prepare_item_for_response ( WP_Post $post, WP_REST_Request $request ) : WP_REST_Response Prepares a single attachment output for response.
update_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response Updates a single attachment.
validate_user_can_query_private_statuses ( mixed $value, WP_REST_Request $request, string $parameter ) : WP_Error | boolean Validates whether the user can query private statuses.

Protected Methods

Method Description
get_media_types ( ) : array Retrieves the supported media types.
prepare_item_for_database ( WP_REST_Request $request ) : WP_Error | stdClass Prepares a single attachment 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 for WP_Query.
upload_from_data ( array $data, array $headers ) : array | WP_Error Handles an upload via raw POST data.
upload_from_file ( array $files, array $headers ) : array | WP_Error Handles an upload via multipart/form-data ($_FILES).

Method Details

create_item() public method

Creates a single attachment.
Since: 4.7.0
public create_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response
$request WP_REST_Request Full details about the request.
return WP_Error | WP_REST_Response Response object on success, WP_Error object on failure.

create_item_permissions_check() public method

Checks if a given request has access to create an attachment.
Since: 4.7.0
public create_item_permissions_check ( WP_REST_Request $request ) : WP_Error | true
$request WP_REST_Request Full details about the request.
return WP_Error | true Boolean true if the attachment may be created, or a WP_Error if not.

get_collection_params() public method

Retrieves the query params for collections of attachments.
Since: 4.7.0
public get_collection_params ( ) : array
return array Query parameters for the attachment collection as an array.

get_filename_from_disposition() public static method

As per RFC6266: content-disposition = "Content-Disposition" ":" disposition-type *( ";" disposition-parm ) disposition-type = "inline" | "attachment" | disp-ext-type ; case-insensitive disp-ext-type = token disposition-parm = filename-parm | disp-ext-parm filename-parm = "filename" "=" value | "filename*" "=" ext-value disp-ext-parm = token "=" value | ext-token "=" ext-value ext-token =
public static get_filename_from_disposition ( string[] $disposition_header ) : string | null
$disposition_header string[] List of Content-Disposition header values.
return string | null Filename if available, or null if not found.

get_item_schema() public method

Retrieves the attachment's schema, conforming to JSON Schema.
Since: 4.7.0
public get_item_schema ( ) : array
return array Item schema as an array.

get_media_types() protected method

Media types are considered the MIME type category.
Since: 4.7.0
protected get_media_types ( ) : array
return array Array of supported media types.

prepare_item_for_database() protected method

Prepares a single attachment for create or update.
Since: 4.7.0
protected prepare_item_for_database ( WP_REST_Request $request ) : WP_Error | stdClass
$request WP_REST_Request Request object.
return WP_Error | stdClass $prepared_attachment Post object.

prepare_item_for_response() public method

Prepares a single attachment output for response.
Since: 4.7.0
public prepare_item_for_response ( WP_Post $post, WP_REST_Request $request ) : WP_REST_Response
$post WP_Post Attachment object.
$request WP_REST_Request Request object.
return WP_REST_Response Response object.

prepare_items_query() protected method

Determines the allowed query_vars for a get_items() response and prepares for WP_Query.
Since: 4.7.0
protected prepare_items_query ( array $prepared_args = [], WP_REST_Request $request = null ) : array
$prepared_args array Optional. Array of prepared arguments. Default empty array.
$request WP_REST_Request Optional. Request to prepare items for.
return array Array of query arguments.

update_item() public method

Updates a single attachment.
Since: 4.7.0
public update_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response
$request WP_REST_Request Full details about the request.
return WP_Error | WP_REST_Response Response object on success, WP_Error object on failure.

upload_from_data() protected method

Handles an upload via raw POST data.
Since: 4.7.0
protected upload_from_data ( array $data, array $headers ) : array | WP_Error
$data array Supplied file data.
$headers array HTTP headers from the request.
return array | WP_Error Data from wp_handle_sideload().

upload_from_file() protected method

Handles an upload via multipart/form-data ($_FILES).
Since: 4.7.0
protected upload_from_file ( array $files, array $headers ) : array | WP_Error
$files array Data from the `$_FILES` superglobal.
$headers array HTTP headers from the request.
return array | WP_Error Data from wp_handle_upload().

validate_user_can_query_private_statuses() public method

Validates whether the user can query private statuses.
Since: 4.7.0
public validate_user_can_query_private_statuses ( mixed $value, WP_REST_Request $request, string $parameter ) : WP_Error | boolean
$value mixed Status value.
$request WP_REST_Request Request object.
$parameter string Additional parameter to pass for validation.
return WP_Error | boolean True if the user may query, WP_Error if not.