Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default fonts directory to wp-content/uploads/fonts #6317

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/wp-includes/fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,12 @@ function _wp_filter_font_directory( $font_dir ) {
return $font_dir;
}

$site_path = '';
if ( is_multisite() && ! ( is_main_network() && is_main_site() ) ) {
$site_path = '/sites/' . get_current_blog_id();
}

$font_dir = array(
'path' => path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path,
'url' => untrailingslashit( content_url( 'fonts' ) ) . $site_path,
'path' => untrailingslashit( $font_dir['basedir'] ) . '/fonts',
'url' => untrailingslashit( $font_dir['baseurl'] ) . '/fonts',
'subdir' => '',
'basedir' => path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path,
'baseurl' => untrailingslashit( content_url( 'fonts' ) ) . $site_path,
'basedir' => untrailingslashit( $font_dir['basedir'] ) . '/fonts',
'baseurl' => untrailingslashit( $font_dir['baseurl'] ) . '/fonts',
'error' => false,
);
swissspidy marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
45 changes: 41 additions & 4 deletions tests/phpunit/tests/fonts/font-library/wpFontsDir.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,58 @@ class Tests_Fonts_WpFontDir extends WP_UnitTestCase {

public static function set_up_before_class() {
parent::set_up_before_class();
$upload_dir = wp_get_upload_dir();

static::$dir_defaults = array(
'path' => path_join( WP_CONTENT_DIR, 'fonts' ),
'url' => content_url( 'fonts' ),
'path' => untrailingslashit( $upload_dir['basedir'] ) . '/fonts',
'url' => untrailingslashit( $upload_dir['baseurl'] ) . '/fonts',
'subdir' => '',
'basedir' => path_join( WP_CONTENT_DIR, 'fonts' ),
'baseurl' => content_url( 'fonts' ),
'basedir' => untrailingslashit( $upload_dir['basedir'] ) . '/fonts',
'baseurl' => untrailingslashit( $upload_dir['baseurl'] ) . '/fonts',
'error' => false,
);
}

/**
* Ensure the font directory is correct.
*/
public function test_fonts_dir() {
$font_dir = wp_get_font_dir();

$this->assertSame( $font_dir, static::$dir_defaults );
}

/**
* Ensure that the fonts directory is correct for a multisite installation.
peterwilsoncc marked this conversation as resolved.
Show resolved Hide resolved
*
* The main site will use the default location and others will follow a pattern of `/sites/{$blog_id}/fonts`
*
* @group multisite
* @group ms-required
*/
public function test_fonts_dir_for_multisite() {
$blog_id = self::factory()->blog->create();
$main_site_upload_dir = wp_get_upload_dir();
switch_to_blog( $blog_id );

$actual = wp_get_font_dir();
$expected = array(
'path' => untrailingslashit( $main_site_upload_dir['basedir'] ) . "/sites/{$blog_id}/fonts",
'url' => untrailingslashit( $main_site_upload_dir['baseurl'] ) . "/sites/{$blog_id}/fonts",
'subdir' => '',
'basedir' => untrailingslashit( $main_site_upload_dir['basedir'] ) . "/sites/{$blog_id}/fonts",
'baseurl' => untrailingslashit( $main_site_upload_dir['baseurl'] ) . "/sites/{$blog_id}/fonts",
'error' => false,
);

// Restore blog prior to assertions.
restore_current_blog();
$this->assertSameSets( $expected, $actual );
}
johnbillion marked this conversation as resolved.
Show resolved Hide resolved

/**
* Ensure modifying the font directory via the 'font_dir' filter works.
*/
public function test_fonts_dir_with_filter() {
// Define a callback function to pass to the filter.
function set_new_values( $defaults ) {
Expand Down Expand Up @@ -71,6 +106,8 @@ function set_new_values( $defaults ) {
}

/**
* Ensure infinite loops are not triggered when filtering the font uploads directory.
*
* @ticket 60652
*/
public function test_fonts_dir_filters_do_not_trigger_infinite_loop() {
Expand Down
Loading