[wp-trac] [WordPress Trac] #60835: Fix and improve handling of uploading of font files

WordPress Trac noreply at wordpress.org
Thu Jun 27 20:49:07 UTC 2024


#60835: Fix and improve handling of uploading of font files
----------------------------------------------------+---------------------
 Reporter:  azaozz                                  |       Owner:  (none)
     Type:  defect (bug)                            |      Status:  new
 Priority:  high                                    |   Milestone:  6.6
Component:  Upload                                  |     Version:  6.5
 Severity:  normal                                  |  Resolution:
 Keywords:  needs-testing has-patch has-unit-tests  |     Focuses:
----------------------------------------------------+---------------------

Comment (by azaozz):

 As I mentioned above I'd consider this a blocker for WP 6.6. Seems that
 despite my best efforts there are still not enough contributors that would
 review the changes here. It's been three months. This is really
 troubling...

 According to two of the three reviews here the code in this patch is "too
 much of a change" (again!) to be added during RC. In that case lets come
 up with a minimal patch that would fix the worst problem: allowing plugins
 to remove the `/fonts` directory and disable the `font_dir` filter.

 A plugin can do this by removing the `_wp_filter_font_directory()`
 callback from the `upload_dir` filter. Something like this:
 {{{
 add_filter( 'upload_dir', function ( $upload_dir ) {
         remove_filter( 'upload_dir', '_wp_filter_font_directory' );
         return $upload_dir;
 }, 5 );
 }}}

 To fix that another plugin or core can do the opposite: i.e. re-add the
 callaback if it was removed. Something like this:
 {{{
 add_filter( 'upload_dir', function ( $upload_dir ) {
         if ( ! has_filter( 'upload_dir', '_wp_filter_font_directory' ) ) {
             add_filter( 'upload_dir', '_wp_filter_font_directory' );
         }
         return $upload_dir;
 }, 9 );
 }}}

 This code is a normal use of the Hooks API in WP. A plugin that would
 remove a callback should expect that another plugin may re-add it.

 However adding the above code to core would be quite a workaround. Core
 has access to better methods to stop the removal of a particular callback.
 Seems that can be done directly in `remove_filter()`, no need of
 workarounds. Patch coming up.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60835#comment:69>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list