| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Source view] [Print] [Project Stats]
REST API: WP_REST_Attachments_Controller class
| File Size: | 2258 lines (72 kb) |
| Included or required: | 0 times |
| Referenced: | 0 times |
| Includes or requires: | 4 files wp-admin/includes/image.php wp-admin/includes/ms.php wp-admin/includes/media.php wp-admin/includes/file.php |
WP_REST_Attachments_Controller:: (30 methods):
register_routes()
get_endpoint_args_for_item_schema()
prepare_items_query()
create_item_permissions_check()
create_item()
remove_client_side_media_processing_filters()
insert_attachment()
handle_featured_media()
update_item()
post_process_item()
post_process_item_permissions_check()
edit_media_item_permissions_check()
edit_media_item()
prepare_item_for_database()
prepare_item_for_response()
prepare_links()
get_item_schema()
upload_from_data()
get_filename_from_disposition()
get_collection_params()
upload_from_file()
get_media_types()
check_upload_size()
get_edit_media_item_args()
get_attachment_filename()
get_attachment_filesize()
sideload_item_permissions_check()
sideload_item()
filter_wp_unique_filename()
finalize_item()
Class: WP_REST_Attachments_Controller - X-Ref
Core controller used to access attachments via the REST API.| register_routes() X-Ref |
| Registers the routes for attachments. |
| get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) X-Ref |
| Retrieves the query params for the attachments collection. return: array<string, array<string, mixed>> Endpoint arguments. param: string $method Optional. HTTP method of the request. |
| prepare_items_query( $prepared_args = array() X-Ref |
| Determines the allowed query_vars for a get_items() response and prepares for WP_Query. return: array Array of query arguments. param: array $prepared_args Optional. Array of prepared arguments. Default empty array. param: WP_REST_Request $request Optional. Request to prepare items for. |
| create_item_permissions_check( $request ) X-Ref |
| Checks if a given request has access to create an attachment. return: true|WP_Error Boolean true if the attachment may be created, or a WP_Error if not. param: WP_REST_Request $request Full details about the request. |
| create_item( $request ) X-Ref |
| Creates a single attachment. return: WP_REST_Response|WP_Error Response object on success, WP_Error object on failure. param: WP_REST_Request $request Full details about the request. |
| remove_client_side_media_processing_filters() X-Ref |
| Removes filters added for client-side media processing. |
| insert_attachment( $request ) X-Ref |
| Inserts the attachment post in the database. Does not update the attachment meta. return: array|WP_Error param: WP_REST_Request $request |
| 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. param: int $featured_media Featured Media ID. param: int $post_id Post ID. |
| update_item( $request ) X-Ref |
| Updates a single attachment. return: WP_REST_Response|WP_Error Response object on success, WP_Error object on failure. param: WP_REST_Request $request Full details about the request. |
| post_process_item( $request ) X-Ref |
| Performs post-processing on an attachment. return: WP_REST_Response|WP_Error Response object on success, WP_Error object on failure. param: WP_REST_Request $request Full details about the request. |
| post_process_item_permissions_check( $request ) X-Ref |
| Checks if a given request can perform post-processing on an attachment. return: true|WP_Error True if the request has access to update the item, WP_Error object otherwise. param: WP_REST_Request $request Full details about the request. |
| edit_media_item_permissions_check( $request ) X-Ref |
| Checks if a given request has access to editing media. return: true|WP_Error True if the request has read access, WP_Error object otherwise. param: WP_REST_Request $request Full details about the request. |
| edit_media_item( $request ) X-Ref |
| Applies edits to a media item and creates a new attachment record. return: WP_REST_Response|WP_Error Response object on success, WP_Error object on failure. param: WP_REST_Request $request Full details about the request. |
| prepare_item_for_database( $request ) X-Ref |
| Prepares a single attachment for create or update. return: stdClass|WP_Error Post object. param: WP_REST_Request $request Request object. |
| prepare_item_for_response( $item, $request ) X-Ref |
| Prepares a single attachment output for response. return: WP_REST_Response Response object. param: WP_Post $item Attachment object. param: WP_REST_Request $request Request object. |
| prepare_links( $post ) X-Ref |
| Prepares attachment links for the request. return: array Links for the given attachment. param: WP_Post $post Post object. |
| get_item_schema() X-Ref |
| Retrieves the attachment's schema, conforming to JSON Schema. return: array Item schema as an array. |
| upload_from_data( $data, $headers, $time = null ) X-Ref |
| Handles an upload via raw POST data. return: array|WP_Error Data from wp_handle_sideload(). param: string $data Supplied file data. param: array $headers HTTP headers from the request. param: string|null $time Optional. Time formatted in 'yyyy/mm'. Default null. |
| get_filename_from_disposition( $disposition_header ) X-Ref |
| Parses filename from a Content-Disposition header value. 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 = <the characters in token, followed by "*"> return: string|null Filename if available, or null if not found. param: string[] $disposition_header List of Content-Disposition header values. |
| get_collection_params() X-Ref |
| Retrieves the query params for collections of attachments. return: array Query parameters for the attachment collection as an array. |
| upload_from_file( $files, $headers, $time = null ) X-Ref |
| Handles an upload via multipart/form-data ($_FILES). return: array|WP_Error Data from wp_handle_upload(). param: array $files Data from the `$_FILES` superglobal. param: array $headers HTTP headers from the request. param: string|null $time Optional. Time formatted in 'yyyy/mm'. Default null. |
| get_media_types() X-Ref |
| Retrieves the supported media types. Media types are considered the MIME type category. return: array Array of supported media types. |
| check_upload_size( $file ) X-Ref |
| Determine if uploaded file exceeds space quota on multisite. Replicates check_upload_size(). return: true|WP_Error True if can upload, error for errors. param: array $file $_FILES array for a given file. |
| get_edit_media_item_args() X-Ref |
| Gets the request args for the edit item route. return: array |
| get_attachment_filename( int $attachment_id ) X-Ref |
| Gets the attachment's original file name. return: string|null Attachment file name, or null if not found. param: int $attachment_id Attachment ID. |
| get_attachment_filesize( int $attachment_id ) X-Ref |
| Gets the attachment's file size in bytes. return: int|null Attachment file size in bytes, or null if not available. param: int $attachment_id Attachment ID. |
| sideload_item_permissions_check( $request ) X-Ref |
| Checks if a given request has access to sideload a file. Sideloading a file for an existing attachment requires both update and create permissions. return: true|WP_Error True if the request has access to update the item, WP_Error object otherwise. param: WP_REST_Request $request Full details about the request. |
| sideload_item( WP_REST_Request $request ) X-Ref |
| Side-loads a media file without creating a new attachment. return: WP_REST_Response|WP_Error Response object on success, WP_Error object on failure. param: WP_REST_Request $request Full details about the request. |
| filter_wp_unique_filename( $filename, $dir, $number, $attachment_filename ) X-Ref |
| Filters wp_unique_filename during sideloads. wp_unique_filename() will always add numeric suffix if the name looks like a sub-size to avoid conflicts. Adding this closure to the filter helps work around this safeguard. Example: when uploading myphoto.jpeg, WordPress normally creates myphoto-150x150.jpeg, and when uploading myphoto-150x150.jpeg, it will be renamed to myphoto-150x150-1.jpeg However, here it is desired not to add the suffix in order to maintain the same naming convention as if the file was uploaded regularly. return: string Filtered file name. param: string $filename Unique file name. param: string $dir Directory path. param: int|string $number The highest number that was used to make the file name unique param: string|null $attachment_filename Original attachment file name. |
| finalize_item( WP_REST_Request $request ) X-Ref |
| Finalizes an attachment after client-side media processing. Triggers the 'wp_generate_attachment_metadata' filter so that server-side plugins can process the attachment after all client-side operations (upload, thumbnail generation, sideloads) are complete. return: WP_REST_Response|WP_Error Response object on success, WP_Error object on failure. param: WP_REST_Request $request Full details about the request. |
| Generated : Sat Jun 20 08:20:11 2026 | Cross-referenced by PHPXref |