WP_REST_Font_Faces_Controller::handle_font_file_upload( array $file ): array|WP_Error

In this article

Handles the upload of a font file using wp_handle_upload() .

Parameters

$filearrayrequired
Single file item from $_FILES.

Return

array|WP_Error Array containing uploaded file attributes on success, or WP_Error object on failure.

Source

protected function handle_font_file_upload( $file ) {
	add_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) );
	// Filter the upload directory to return the fonts directory.
	add_filter( 'upload_dir', '_wp_filter_font_directory' );

	$overrides = array(
		'upload_error_handler' => array( $this, 'handle_font_file_upload_error' ),
		// Not testing a form submission.
		'test_form'            => false,
		// Only allow uploading font files for this request.
		'mimes'                => WP_Font_Utils::get_allowed_font_mime_types(),
	);

	// Bypasses is_uploaded_file() when running unit tests.
	if ( defined( 'DIR_TESTDATA' ) && DIR_TESTDATA ) {
		$overrides['action'] = 'wp_handle_mock_upload';
	}

	$uploaded_file = wp_handle_upload( $file, $overrides );

	remove_filter( 'upload_dir', '_wp_filter_font_directory' );
	remove_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) );

	return $uploaded_file;
}

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.