Automattic\WooCommerce\Internal\Font

FontFace::handle_font_file_upload()private staticWC 1.0

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

Copied from Gutenberg: https://github.com/WordPress/gutenberg/blob/f4889bf58ddeb8470c8d2a765f1b57229c515eda/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-faces-controller.php/#L859-L896

Метод класса: FontFace{}

Хуков нет.

Возвращает

Массив. Array containing uploaded file attributes on success, or error on failure.

Использование

$result = FontFace::handle_font_file_upload( $file );
$file(массив) (обязательный)
Single file item from $_FILES.

Код FontFace::handle_font_file_upload() WC 9.6.1

private static function handle_font_file_upload( $file ) {
	add_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) );

	/*
	 * Set the upload directory to the fonts directory.
	 *
	 * wp_get_font_dir() contains the 'font_dir' hook, whose callbacks are
	 * likely to call wp_get_upload_dir().
	 *
	 * To avoid an infinite loop, don't hook wp_get_font_dir() to 'upload_dir'.
	 * Instead, just pass its return value to the 'upload_dir' callback.
	 */
	$font_dir       = wp_get_font_dir();
	$set_upload_dir = function () use ( $font_dir ) {
		return $font_dir;
	};
	add_filter( 'upload_dir', $set_upload_dir );

	$overrides = array(
		'upload_error_handler' => array( self::class, 'handle_font_file_upload_error' ),
		// Arbitrary string to avoid the is_uploaded_file() check applied
		// when using 'wp_handle_upload'.
		'action'               => 'wp_handle_font_upload',
		// Not testing a form submission.
		'test_form'            => false,
		// Seems mime type for files that are not images cannot be tested.
		// See wp_check_filetype_and_ext().
		'test_type'            => true,
		// Only allow uploading font files for this request.
		'mimes'                => \WP_Font_Utils::get_allowed_font_mime_types(),
	);

	$uploaded_file = wp_handle_upload( $file, $overrides );
	remove_filter( 'upload_dir', $set_upload_dir );
	remove_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) );

	return $uploaded_file;
}