diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php index 3b3a338b838ec..46eeeccf31c46 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php @@ -856,21 +856,7 @@ protected function sanitize_src( $value ) { */ protected 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 ); + add_filter( 'upload_dir', 'wp_get_font_dir' ); $overrides = array( 'upload_error_handler' => array( $this, 'handle_font_file_upload_error' ), @@ -888,7 +874,7 @@ protected function handle_font_file_upload( $file ) { $uploaded_file = wp_handle_upload( $file, $overrides ); - remove_filter( 'upload_dir', $set_upload_dir ); + remove_filter( 'upload_dir', 'wp_get_font_dir' ); remove_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) ); return $uploaded_file;