WP_REST_Font_Faces_Controller::handle_font_file_upload
Handles the upload of a font file using wp_handle_upload().
Method of the class: WP_REST_Font_Faces_Controller{}
No Hooks.
Returns
Array|WP_Error. Array containing uploaded file attributes on success, or WP_Error object on failure.
Usage
// protected - for code of main (parent) or child class $result = $this->handle_font_file_upload( $file );
- $file(array) (required)
- Single file item from
$_FILES.
Changelog
| Since 6.5.0 | Introduced. |
WP_REST_Font_Faces_Controller::handle_font_file_upload() WP REST Font Faces Controller::handle font file upload code WP 7.0
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;
}