Skip to content

Commit

Permalink
[CMSP-695] Remove override for font_dir filter (#33)
Browse files Browse the repository at this point in the history
* remove the filter to override our customization
per WordPress/gutenberg#59102 (comment) it seems like fonts are more likely to be treated like media files, in which case it would be undesirable to commit them to the repository, so we're removing our override.

our behavior can still be overridden by removing or changing the font_dir filter at a priority higher than 9 (default is 10).

* update tests
  • Loading branch information
jazzsequence authored Feb 16, 2024
1 parent dbe012b commit 6f799a5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 45 deletions.
17 changes: 2 additions & 15 deletions inc/fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,8 @@
* Kick off our customizations to the WP_Font_Library.
*/
function bootstrap() {
/**
* Modify the fonts directory.
*
* By default, this is set to true, so we can override the default fonts directory from wp-content/fonts to wp-content/uploads/fonts.
*
* Use the filter to set to false and use the default WordPress behavior (committing fonts to your repository and pushing from dev -> test -> live).
*
* @param bool $modify_fonts_dir Whether to modify the fonts directory.
*/
$modify_fonts_dir = apply_filters( 'pantheon_modify_fonts_dir', true );

if ( $modify_fonts_dir ) {
// Use the new font_dir filter added in WordPress 6.5. See https://github.com/WordPress/gutenberg/pull/57697.
add_filter( 'font_dir', __NAMESPACE__ . '\\pantheon_font_dir', 9 );
}
// Use the new font_dir filter added in WordPress 6.5. See https://github.com/WordPress/gutenberg/pull/57697.
add_filter( 'font_dir', __NAMESPACE__ . '\\pantheon_font_dir', 9 );
}
add_action( 'init', __NAMESPACE__ . '\\bootstrap' );

Expand Down
30 changes: 0 additions & 30 deletions tests/phpunit/test-fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Test_Fonts extends WP_UnitTestCase {
public function setUp(): void {
parent::setUp();
remove_all_filters( 'font_dir' );
remove_all_filters( 'pantheon_modify_fonts_dir' );

// Mock the global variable before each test.
global $_pantheon_upload_dir;
Expand Down Expand Up @@ -147,35 +146,6 @@ public function test_pantheon_fonts_dir_filter() {
$this->assertEquals( $expected, $font_dir );
}

/**
* Test that the font directory modifications can be disabled.
*/
public function test_disable_pantheon_font_dir_mods() {
$this->maybe_get_font_library();
if ( ! function_exists( 'wp_get_font_dir' ) ) {
// If the function still doesn't exist after trying to get the font library from gutenberg, mark the test skipped.
$this->markTestSkipped( 'The wp_get_font_dir function is not available. We\'re probably not using WP 6.5+' );
}

// Disable the font directory modifications.
add_filter( 'pantheon_modify_fonts_dir', '__return_false' );
$modify_fonts_dir = apply_filters( 'pantheon_modify_fonts_dir', true );
$this->assertFalse( $modify_fonts_dir );

$font_dir = wp_get_font_dir();

$expected = [
'path' => WP_CONTENT_DIR . '/fonts',
'url' => WP_CONTENT_URL . '/fonts',
'subdir' => '',
'basedir' => WP_CONTENT_DIR . '/fonts',
'baseurl' => WP_CONTENT_URL . '/fonts',
'error' => false,
];

$this->assertEquals( $expected, $font_dir );
}

/**
* Get the font library from Gutenberg if it's not available.
*/
Expand Down

0 comments on commit 6f799a5

Please sign in to comment.