Title: WP_REST_Attachments_Controller::create_item_permissions_check
Published: December 6, 2016
Last modified: August 20, 2026

---

# WP_REST_Attachments_Controller::create_item_permissions_check( WP_REST_Request $request ): true|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/create_item_permissions_check/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/create_item_permissions_check/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/create_item_permissions_check/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/create_item_permissions_check/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/create_item_permissions_check/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/create_item_permissions_check/?output_format=md#changelog)

Checks if a given request has access to create an attachment.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/create_item_permissions_check/?output_format=md#parameters)󠁿

 `$request`[WP_REST_Request](https://developer.wordpress.org/reference/classes/wp_rest_request/)
required

Full details about the request.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/create_item_permissions_check/?output_format=md#return)󠁿

 true|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) Boolean
true if the attachment may be created, or a [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
if not.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/create_item_permissions_check/?output_format=md#source)󠁿

    ```php
    public function create_item_permissions_check( $request ) {
    	$ret = parent::create_item_permissions_check( $request );

    	if ( ! $ret || is_wp_error( $ret ) ) {
    		return $ret;
    	}

    	if ( ! current_user_can( 'upload_files' ) ) {
    		return new WP_Error(
    			'rest_cannot_create',
    			__( 'Sorry, you are not allowed to upload media on this site.' ),
    			array( 'status' => 400 )
    		);
    	}

    	// Attaching media to a post requires ability to edit said post.
    	if ( ! empty( $request['post'] ) && ! current_user_can( 'edit_post', (int) $request['post'] ) ) {
    		return new WP_Error(
    			'rest_cannot_edit',
    			__( 'Sorry, you are not allowed to upload media to this post.' ),
    			array( 'status' => rest_authorization_required_code() )
    		);
    	}
    	$files = $request->get_file_params();

    	/**
    	 * Filter whether the server should prevent uploads for image types it doesn't support. Default true.
    	 *
    	 * Developers can use this filter to enable uploads of certain image types. By default image types that are not
    	 * supported by the server are prevented from being uploaded.
    	 *
    	 * @since 6.8.0
    	 *
    	 * @param bool        $check_mime Whether to prevent uploads of unsupported image types.
    	 * @param string|null $mime_type  The mime type of the file being uploaded (if available).
    	 */
    	$prevent_unsupported_uploads = apply_filters( 'wp_prevent_unsupported_mime_type_uploads', true, $files['file']['type'] ?? null );

    	/*
    	 * When the client handles image processing (generate_sub_sizes is false),
    	 * skip the server-side image editor support check. This check exists
    	 * because the server cannot process the image, so it is only relaxed when
    	 * client side media processing is enabled and something else can. Asking
    	 * to skip sub sizes on a site without it does not make an unsupported
    	 * image type any more usable.
    	 */
    	if ( wp_is_client_side_media_processing_enabled() && false === $request['generate_sub_sizes'] ) {
    		$prevent_unsupported_uploads = false;
    	}

    	/*
    	 * Always allow still HEIC/HEIF uploads through even if the server's
    	 * image editor doesn't support them. The client-side canvas fallback
    	 * handles processing using the browser's native HEVC decoder.
    	 *
    	 * The '-sequence' variants (multi-frame Live Photos) are deliberately
    	 * excluded: neither the server nor the browser fallback can process
    	 * them yet, so they should fall through to the standard unsupported
    	 * mime-type error rather than be stored unprocessable.
    	 */
    	$still_heic_mime_types = array( 'image/heic', 'image/heif' );

    	if (
    		$prevent_unsupported_uploads &&
    		! empty( $files['file']['type'] ) &&
    		in_array( $files['file']['type'], $still_heic_mime_types, true )
    	) {
    		$prevent_unsupported_uploads = false;
    	}

    	// If the upload is an image, check if the server can handle the mime type.
    	if (
    		$prevent_unsupported_uploads &&
    		isset( $files['file']['type'] ) &&
    		str_starts_with( $files['file']['type'], 'image/' )
    	) {
    		// List of non-resizable image formats.
    		$editor_non_resizable_formats = array(
    			'image/svg+xml',
    		);

    		// Check if the image editor supports the type or ignore if it isn't a format resizable by an editor.
    		if (
    			! in_array( $files['file']['type'], $editor_non_resizable_formats, true ) &&
    			! wp_image_editor_supports( array( 'mime_type' => $files['file']['type'] ) )
    		) {
    			return new WP_Error(
    				'rest_upload_image_type_not_supported',
    				__( 'The web server cannot generate responsive image sizes for this image. Convert it to JPEG or PNG before uploading.' ),
    				array( 'status' => 400 )
    			);
    		}
    	}

    	return true;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php#L404)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php#L404-L499)

## 󠀁[Hooks](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/create_item_permissions_check/?output_format=md#hooks)󠁿

 [apply_filters( ‘wp_prevent_unsupported_mime_type_uploads’, bool $check_mime, string|null $mime_type )](https://developer.wordpress.org/reference/hooks/wp_prevent_unsupported_mime_type_uploads/)

Filter whether the server should prevent uploads for image types it doesn’t support.
Default true.

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/create_item_permissions_check/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_is_client_side_media_processing_enabled()](https://developer.wordpress.org/reference/functions/wp_is_client_side_media_processing_enabled/)`wp-includes/media.php` |

Checks whether client-side media processing is enabled.

  | 
| [WP_REST_Posts_Controller::create_item_permissions_check()](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/create_item_permissions_check/)`wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php` |

Checks if a given request has access to create a post.

  | 
| [wp_image_editor_supports()](https://developer.wordpress.org/reference/functions/wp_image_editor_supports/)`wp-includes/media.php` |

Tests whether there is an editor that supports a given mime type or methods.

  | 
| [rest_authorization_required_code()](https://developer.wordpress.org/reference/functions/rest_authorization_required_code/)`wp-includes/rest-api.php` |

Returns a contextual HTTP error code for authorization failure.

  | 
| [current_user_can()](https://developer.wordpress.org/reference/functions/current_user_can/)`wp-includes/capabilities.php` |

Returns whether the current user has the specified capability.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [is_wp_error()](https://developer.wordpress.org/reference/functions/is_wp_error/)`wp-includes/load.php` |

Checks whether the given variable is a WordPress Error.

  | 
| [WP_Error::__construct()](https://developer.wordpress.org/reference/classes/wp_error/__construct/)`wp-includes/class-wp-error.php` |

Initializes the error.

  |

[Show 6 more](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/create_item_permissions_check/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/create_item_permissions_check/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/create_item_permissions_check/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_attachments_controller%2Fcreate_item_permissions_check%2F)
before being able to contribute a note or feedback.