Make WordPress Core

Changeset 57878


Ignore:
Timestamp:
03/26/2024 01:23:14 AM (3 weeks ago)
Author:
peterwilsoncc
Message:

Editor: Relocate font files uploads to the uploads directory.

Relocate the upload of font files uploaded via the Font Library feature to the wp-content/uploads/fonts (or multisite equivalent) directory.

This accounts for immutable file systems in which directories are unable to be created within wp-content and deploy processes which require special consideration of the uploads directory to ensure it remains persistent between deploys.

Props azaozz, burnuser, cbirdsong, christopherplus, costdev, davidbaumwald, desrosj, elrae, euthelup, get_dave, grantmkin, hellofromtonya, janthiel, jazzs3quence, johnbillion, jorbin, justlevine, kraftner, matveb, mcsf, mmaattiiaass, nico23, peterwilsoncc, priethor, rmccue, samuelsidler, swissspidy, youknowriad.
Fixes #60845.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/fonts.php

    r57871 r57878  
    168168    }
    169169
    170     $site_path = '';
    171     if ( is_multisite() && ! ( is_main_network() && is_main_site() ) ) {
    172         $site_path = '/sites/' . get_current_blog_id();
    173     }
    174 
    175170    $font_dir = array(
    176         'path'    => path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path,
    177         'url'     => untrailingslashit( content_url( 'fonts' ) ) . $site_path,
     171        'path'    => untrailingslashit( $font_dir['basedir'] ) . '/fonts',
     172        'url'     => untrailingslashit( $font_dir['baseurl'] ) . '/fonts',
    178173        'subdir'  => '',
    179         'basedir' => path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path,
    180         'baseurl' => untrailingslashit( content_url( 'fonts' ) ) . $site_path,
     174        'basedir' => untrailingslashit( $font_dir['basedir'] ) . '/fonts',
     175        'baseurl' => untrailingslashit( $font_dir['baseurl'] ) . '/fonts',
    181176        'error'   => false,
    182177    );
  • trunk/tests/phpunit/tests/fonts/font-library/wpFontsDir.php

    r57868 r57878  
    1616    public static function set_up_before_class() {
    1717        parent::set_up_before_class();
     18        $upload_dir = wp_get_upload_dir();
    1819
    1920        static::$dir_defaults = array(
    20             'path'    => path_join( WP_CONTENT_DIR, 'fonts' ),
    21             'url'     => content_url( 'fonts' ),
     21            'path'    => untrailingslashit( $upload_dir['basedir'] ) . '/fonts',
     22            'url'     => untrailingslashit( $upload_dir['baseurl'] ) . '/fonts',
    2223            'subdir'  => '',
    23             'basedir' => path_join( WP_CONTENT_DIR, 'fonts' ),
    24             'baseurl' => content_url( 'fonts' ),
     24            'basedir' => untrailingslashit( $upload_dir['basedir'] ) . '/fonts',
     25            'baseurl' => untrailingslashit( $upload_dir['baseurl'] ) . '/fonts',
    2526            'error'   => false,
    2627        );
    2728    }
    2829
     30    /**
     31     * Ensure the font directory is correct.
     32     */
    2933    public function test_fonts_dir() {
    3034        $font_dir = wp_get_font_dir();
     
    3337    }
    3438
     39    /**
     40     * Ensure that the fonts directory is correct for a multisite installation.
     41     *
     42     * The main site will use the default location and others will follow a pattern of  `/sites/{$blog_id}/fonts`
     43     *
     44     * @group multisite
     45     * @group ms-required
     46     */
     47    public function test_fonts_dir_for_multisite() {
     48        $blog_id              = self::factory()->blog->create();
     49        $main_site_upload_dir = wp_get_upload_dir();
     50        switch_to_blog( $blog_id );
     51
     52        $actual   = wp_get_font_dir();
     53        $expected = array(
     54            'path'    => untrailingslashit( $main_site_upload_dir['basedir'] ) . "/sites/{$blog_id}/fonts",
     55            'url'     => untrailingslashit( $main_site_upload_dir['baseurl'] ) . "/sites/{$blog_id}/fonts",
     56            'subdir'  => '',
     57            'basedir' => untrailingslashit( $main_site_upload_dir['basedir'] ) . "/sites/{$blog_id}/fonts",
     58            'baseurl' => untrailingslashit( $main_site_upload_dir['baseurl'] ) . "/sites/{$blog_id}/fonts",
     59            'error'   => false,
     60        );
     61
     62        // Restore blog prior to assertions.
     63        restore_current_blog();
     64        $this->assertSameSets( $expected, $actual );
     65    }
     66
     67    /**
     68     * Ensure modifying the font directory via the 'font_dir' filter works.
     69     */
    3570    public function test_fonts_dir_with_filter() {
    3671        // Define a callback function to pass to the filter.
     
    72107
    73108    /**
     109     * Ensure infinite loops are not triggered when filtering the font uploads directory.
     110     *
    74111     * @ticket 60652
    75112     */
Note: See TracChangeset for help on using the changeset viewer.