WP_REST_Font_Faces_Controller::handle_font_file_upload
Handles the upload of a font file using wp_handle_upload().
Метод класса: WP_REST_Font_Faces_Controller{}
Хуков нет.
Возвращает
Массив|WP_Error. Array containing uploaded file attributes on success, or WP_Error object on failure.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->handle_font_file_upload( $file );
- $file(массив) (обязательный)
- Single file item from
$_FILES.
Список изменений
| С версии 6.5.0 | Введена. |
Код WP_REST_Font_Faces_Controller::handle_font_file_upload() WP REST Font Faces Controller::handle font file upload WP 6.9.1
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;
}