From c31497ab3c311226737a69fce2108069fcfcf92f Mon Sep 17 00:00:00 2001 From: madhusudhand Date: Thu, 14 Dec 2023 13:17:14 +0530 Subject: [PATCH 01/10] add global configuration variables for font directory --- .../fonts/font-library/class-wp-font-library.php | 13 ++++--------- .../font-library/wpFontLibrary/setUploadDir.php | 14 ++++---------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/lib/experimental/fonts/font-library/class-wp-font-library.php b/lib/experimental/fonts/font-library/class-wp-font-library.php index 9320a554e510c..47ec854a965fc 100644 --- a/lib/experimental/fonts/font-library/class-wp-font-library.php +++ b/lib/experimental/fonts/font-library/class-wp-font-library.php @@ -106,7 +106,7 @@ public static function get_font_collection( $id ) { * @return string Path of the upload directory for fonts. */ public static function get_fonts_dir() { - return path_join( WP_CONTENT_DIR, 'fonts' ); + return ( defined( 'WP_FONT_DIR' ) && ! empty( WP_FONT_DIR ) ) ? WP_FONT_DIR : path_join( WP_CONTENT_DIR, 'fonts' ); } /** @@ -119,19 +119,14 @@ public static function get_fonts_dir() { * * @type string $path Path to the directory. * @type string $url URL for the directory. - * @type string $subdir Sub-directory of the directory. - * @type string $basedir Base directory. - * @type string $baseurl Base URL. * } * @return array Modified upload directory. */ public static function set_upload_dir( $defaults ) { - $defaults['basedir'] = WP_CONTENT_DIR; - $defaults['baseurl'] = content_url(); - $defaults['subdir'] = '/fonts'; - $defaults['path'] = self::get_fonts_dir(); - $defaults['url'] = $defaults['baseurl'] . '/fonts'; + $font_url = ( defined( 'WP_FONT_URL' ) && ! empty( WP_FONT_URL ) ) ? set_url_scheme( WP_FONT_URL ) : content_url( 'fonts' ); + $defaults['path'] = self::get_fonts_dir(); + $defaults['url'] = untrailingslashit( $font_url ); return $defaults; } diff --git a/phpunit/tests/fonts/font-library/wpFontLibrary/setUploadDir.php b/phpunit/tests/fonts/font-library/wpFontLibrary/setUploadDir.php index daa4c84aad900..ea99a66af1f19 100644 --- a/phpunit/tests/fonts/font-library/wpFontLibrary/setUploadDir.php +++ b/phpunit/tests/fonts/font-library/wpFontLibrary/setUploadDir.php @@ -14,18 +14,12 @@ class Tests_Fonts_WpFontLibrary_SetUploadDir extends WP_UnitTestCase { public function test_should_set_fonts_upload_dir() { $defaults = array( - 'subdir' => '/abc', - 'basedir' => '/any/path', - 'baseurl' => 'http://example.com/an/arbitrary/url', - 'path' => '/any/path/abc', - 'url' => 'http://example.com/an/arbitrary/url/abc', + 'path' => '/any/path/abc', + 'url' => 'http://example.com/an/arbitrary/url/abc', ); $expected = array( - 'subdir' => '/fonts', - 'basedir' => WP_CONTENT_DIR, - 'baseurl' => content_url(), - 'path' => path_join( WP_CONTENT_DIR, 'fonts' ), - 'url' => content_url() . '/fonts', + 'path' => path_join( WP_CONTENT_DIR, 'fonts' ), + 'url' => content_url( 'fonts' ), ); $this->assertSame( $expected, WP_Font_Library::set_upload_dir( $defaults ) ); } From d6f0a0e201905f878faee1be2db3e543f583b893 Mon Sep 17 00:00:00 2001 From: madhusudhand Date: Mon, 8 Jan 2024 18:02:54 +0530 Subject: [PATCH 02/10] add multi-site based directory path for fonts --- .../font-library/class-wp-font-library.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/experimental/fonts/font-library/class-wp-font-library.php b/lib/experimental/fonts/font-library/class-wp-font-library.php index 47ec854a965fc..37b1ff5c6e7f0 100644 --- a/lib/experimental/fonts/font-library/class-wp-font-library.php +++ b/lib/experimental/fonts/font-library/class-wp-font-library.php @@ -98,6 +98,14 @@ public static function get_font_collection( $id ) { return new WP_Error( 'font_collection_not_found', 'Font collection not found.' ); } + private static function get_multi_site_font_sub_dir() { + $font_sub_dir = ''; + if ( is_multisite() && ! ( is_main_network() && is_main_site() ) ) { + $font_sub_dir = '/sites/' . get_current_blog_id(); + } + return $font_sub_dir; + } + /** * Gets the upload directory for fonts. * @@ -106,7 +114,9 @@ public static function get_font_collection( $id ) { * @return string Path of the upload directory for fonts. */ public static function get_fonts_dir() { - return ( defined( 'WP_FONT_DIR' ) && ! empty( WP_FONT_DIR ) ) ? WP_FONT_DIR : path_join( WP_CONTENT_DIR, 'fonts' ); + $base_font_dir = ( defined( 'WP_FONT_DIR' ) && ! empty( WP_FONT_DIR ) ) ? WP_FONT_DIR : path_join( WP_CONTENT_DIR, 'fonts' ); + $font_sub_dir = self::get_multi_site_font_sub_dir(); + return rtrim( $base_font_dir, '/' ) . $font_sub_dir; } /** @@ -123,10 +133,11 @@ public static function get_fonts_dir() { * @return array Modified upload directory. */ public static function set_upload_dir( $defaults ) { - $font_url = ( defined( 'WP_FONT_URL' ) && ! empty( WP_FONT_URL ) ) ? set_url_scheme( WP_FONT_URL ) : content_url( 'fonts' ); + $font_url = ( defined( 'WP_FONT_URL' ) && ! empty( WP_FONT_URL ) ) ? set_url_scheme( WP_FONT_URL ) : content_url( 'fonts' ); + $font_sub_dir = self::get_multi_site_font_sub_dir(); $defaults['path'] = self::get_fonts_dir(); - $defaults['url'] = untrailingslashit( $font_url ); + $defaults['url'] = untrailingslashit( $font_url ) . $font_sub_dir; return $defaults; } From b48887a86d5153c5f0e5e6f1d4620d053498e90d Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Tue, 9 Jan 2024 12:39:37 -0300 Subject: [PATCH 03/10] add docblock for get_multi_site_font_sub_dir --- .../fonts/font-library/class-wp-font-library.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/experimental/fonts/font-library/class-wp-font-library.php b/lib/experimental/fonts/font-library/class-wp-font-library.php index 4d6ee6c6b5ffd..bb747830f57d5 100644 --- a/lib/experimental/fonts/font-library/class-wp-font-library.php +++ b/lib/experimental/fonts/font-library/class-wp-font-library.php @@ -140,6 +140,13 @@ public static function get_font_collection( $id ) { return new WP_Error( 'font_collection_not_found', 'Font collection not found.' ); } + /** + * Gets a multi site sub-dir. + * + * @since 6.5.0 + * + * @return string multi site sub-dir path. + */ private static function get_multi_site_font_sub_dir() { $font_sub_dir = ''; if ( is_multisite() && ! ( is_main_network() && is_main_site() ) ) { From 27c138bce53b708023132f6baea78e8930b15310 Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Tue, 9 Jan 2024 12:02:56 -0500 Subject: [PATCH 04/10] Rename function for accuracy. --- .../fonts/font-library/class-wp-font-library.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/experimental/fonts/font-library/class-wp-font-library.php b/lib/experimental/fonts/font-library/class-wp-font-library.php index bb747830f57d5..dba9d194ddc87 100644 --- a/lib/experimental/fonts/font-library/class-wp-font-library.php +++ b/lib/experimental/fonts/font-library/class-wp-font-library.php @@ -141,13 +141,13 @@ public static function get_font_collection( $id ) { } /** - * Gets a multi site sub-dir. + * Gets sub-dir for fonts in single or multi site. * * @since 6.5.0 * * @return string multi site sub-dir path. */ - private static function get_multi_site_font_sub_dir() { + private static function get_font_sub_dir() { $font_sub_dir = ''; if ( is_multisite() && ! ( is_main_network() && is_main_site() ) ) { $font_sub_dir = '/sites/' . get_current_blog_id(); @@ -164,7 +164,7 @@ private static function get_multi_site_font_sub_dir() { */ public static function get_fonts_dir() { $base_font_dir = ( defined( 'WP_FONT_DIR' ) && ! empty( WP_FONT_DIR ) ) ? WP_FONT_DIR : path_join( WP_CONTENT_DIR, 'fonts' ); - $font_sub_dir = self::get_multi_site_font_sub_dir(); + $font_sub_dir = self::get_font_sub_dir(); return rtrim( $base_font_dir, '/' ) . $font_sub_dir; } @@ -183,7 +183,7 @@ public static function get_fonts_dir() { */ public static function set_upload_dir( $defaults ) { $font_url = ( defined( 'WP_FONT_URL' ) && ! empty( WP_FONT_URL ) ) ? set_url_scheme( WP_FONT_URL ) : content_url( 'fonts' ); - $font_sub_dir = self::get_multi_site_font_sub_dir(); + $font_sub_dir = self::get_font_sub_dir(); $defaults['path'] = self::get_fonts_dir(); $defaults['url'] = untrailingslashit( $font_url ) . $font_sub_dir; From 384d7c923b9a38350221e50a7364c9150fbd9a80 Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Tue, 9 Jan 2024 17:28:05 -0500 Subject: [PATCH 05/10] Use filter instead of constant to determine where fonts are uploaded. --- .../font-library/class-wp-font-library.php | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/lib/experimental/fonts/font-library/class-wp-font-library.php b/lib/experimental/fonts/font-library/class-wp-font-library.php index dba9d194ddc87..98962e45d3a23 100644 --- a/lib/experimental/fonts/font-library/class-wp-font-library.php +++ b/lib/experimental/fonts/font-library/class-wp-font-library.php @@ -141,13 +141,29 @@ public static function get_font_collection( $id ) { } /** - * Gets sub-dir for fonts in single or multi site. + * Gets dir and url settings for font assets. * * @since 6.5.0 * - * @return string multi site sub-dir path. + * @return string site sub-dir path. */ - private static function get_font_sub_dir() { + private static function get_fonts_dir_settings() { + $fonts_dir_settings = array( + 'dir' => path_join( WP_CONTENT_DIR, 'fonts' ), + 'url' => content_url( 'fonts' ), + ); + + return apply_filters( 'fonts_dir', $fonts_dir_settings ); + } + + /** + * Gets sub-dir for fonts, using the blog ID if multi-site, empty otherwise. + * + * @since 6.5.0 + * + * @return string site sub-dir path. + */ + private static function get_multi_site_fonts_sub_dir() { $font_sub_dir = ''; if ( is_multisite() && ! ( is_main_network() && is_main_site() ) ) { $font_sub_dir = '/sites/' . get_current_blog_id(); @@ -163,9 +179,10 @@ private static function get_font_sub_dir() { * @return string Path of the upload directory for fonts. */ public static function get_fonts_dir() { - $base_font_dir = ( defined( 'WP_FONT_DIR' ) && ! empty( WP_FONT_DIR ) ) ? WP_FONT_DIR : path_join( WP_CONTENT_DIR, 'fonts' ); - $font_sub_dir = self::get_font_sub_dir(); - return rtrim( $base_font_dir, '/' ) . $font_sub_dir; + $fonts_dir_settings = self::get_fonts_dir_settings(); + $fonts_sub_dir = self::get_multi_site_fonts_sub_dir(); + + return rtrim( $fonts_dir_settings['dir'], '/' ) . $fonts_sub_dir; } /** @@ -182,11 +199,11 @@ public static function get_fonts_dir() { * @return array Modified upload directory. */ public static function set_upload_dir( $defaults ) { - $font_url = ( defined( 'WP_FONT_URL' ) && ! empty( WP_FONT_URL ) ) ? set_url_scheme( WP_FONT_URL ) : content_url( 'fonts' ); - $font_sub_dir = self::get_font_sub_dir(); - - $defaults['path'] = self::get_fonts_dir(); - $defaults['url'] = untrailingslashit( $font_url ) . $font_sub_dir; + $fonts_dir_settings = self::get_fonts_dir_settings(); + $fonts_sub_dir = self::get_multi_site_fonts_sub_dir(); + + $defaults['path'] = rtrim( $fonts_dir_settings['dir'], '/' ) . $fonts_sub_dir; + $defaults['url'] = untrailingslashit( $fonts_dir_settings['url'] ) . $fonts_sub_dir; return $defaults; } From a9089e49eeb6c5d15fddc5827668fdb3cfa657c7 Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Tue, 9 Jan 2024 17:40:31 -0500 Subject: [PATCH 06/10] Format php. --- .../fonts/font-library/class-wp-font-library.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/experimental/fonts/font-library/class-wp-font-library.php b/lib/experimental/fonts/font-library/class-wp-font-library.php index 98962e45d3a23..26945c3ea577d 100644 --- a/lib/experimental/fonts/font-library/class-wp-font-library.php +++ b/lib/experimental/fonts/font-library/class-wp-font-library.php @@ -152,7 +152,7 @@ private static function get_fonts_dir_settings() { 'dir' => path_join( WP_CONTENT_DIR, 'fonts' ), 'url' => content_url( 'fonts' ), ); - + return apply_filters( 'fonts_dir', $fonts_dir_settings ); } @@ -181,7 +181,7 @@ private static function get_multi_site_fonts_sub_dir() { public static function get_fonts_dir() { $fonts_dir_settings = self::get_fonts_dir_settings(); $fonts_sub_dir = self::get_multi_site_fonts_sub_dir(); - + return rtrim( $fonts_dir_settings['dir'], '/' ) . $fonts_sub_dir; } @@ -201,9 +201,9 @@ public static function get_fonts_dir() { public static function set_upload_dir( $defaults ) { $fonts_dir_settings = self::get_fonts_dir_settings(); $fonts_sub_dir = self::get_multi_site_fonts_sub_dir(); - + $defaults['path'] = rtrim( $fonts_dir_settings['dir'], '/' ) . $fonts_sub_dir; - $defaults['url'] = untrailingslashit( $fonts_dir_settings['url'] ) . $fonts_sub_dir; + $defaults['url'] = untrailingslashit( $fonts_dir_settings['url'] ) . $fonts_sub_dir; return $defaults; } From 915313a362dad623f27cbd94398d2252f9c3dbca Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Wed, 10 Jan 2024 09:25:57 -0300 Subject: [PATCH 07/10] simplify the filters code and output the same array as upload_filter does --- .../font-library/class-wp-font-family.php | 4 +- .../font-library/class-wp-font-library.php | 72 ++++++++++--------- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/lib/experimental/fonts/font-library/class-wp-font-family.php b/lib/experimental/fonts/font-library/class-wp-font-family.php index a4204dfe1fa2c..e47cf0afdac1d 100644 --- a/lib/experimental/fonts/font-library/class-wp-font-family.php +++ b/lib/experimental/fonts/font-library/class-wp-font-family.php @@ -599,9 +599,9 @@ private function create_or_update_font_post() { */ public function install( $files = null ) { add_filter( 'upload_mimes', array( 'WP_Font_Library', 'set_allowed_mime_types' ) ); - add_filter( 'upload_dir', array( 'WP_Font_Library', 'set_upload_dir' ) ); + add_filter( 'upload_dir', array( 'WP_Font_Library', 'fonts_dir' ) ); $were_assets_written = $this->download_or_move_font_faces( $files ); - remove_filter( 'upload_dir', array( 'WP_Font_Library', 'set_upload_dir' ) ); + remove_filter( 'upload_dir', array( 'WP_Font_Library', 'fonts_dir' ) ); remove_filter( 'upload_mimes', array( 'WP_Font_Library', 'set_allowed_mime_types' ) ); if ( ! $were_assets_written ) { diff --git a/lib/experimental/fonts/font-library/class-wp-font-library.php b/lib/experimental/fonts/font-library/class-wp-font-library.php index 26945c3ea577d..40e3a90d45b67 100644 --- a/lib/experimental/fonts/font-library/class-wp-font-library.php +++ b/lib/experimental/fonts/font-library/class-wp-font-library.php @@ -141,19 +141,45 @@ public static function get_font_collection( $id ) { } /** - * Gets dir and url settings for font assets. + * Returns an array containing the current fonts upload directory's path and URL. * * @since 6.5.0 * - * @return string site sub-dir path. + * @param array $defaults { + * Array of information about the upload directory. + * + * @type string $path Base directory and subdirectory or full path to the fonts upload directory. + * @type string $url Base URL and subdirectory or absolute URL to the fonts upload directory. + * @type string $subdir Subdirectory + * @type string $basedir Path without subdir. + * @type string $baseurl URL path without subdir. + * @type string|false $error False or error message. + * } + * + * @return array $defaults { + * Array of information about the upload directory. + * + * @type string $path Base directory and subdirectory or full path to the fonts upload directory. + * @type string $url Base URL and subdirectory or absolute URL to the fonts upload directory. + * @type string $subdir Subdirectory + * @type string $basedir Path without subdir. + * @type string $baseurl URL path without subdir. + * @type string|false $error False or error message. + * } */ - private static function get_fonts_dir_settings() { - $fonts_dir_settings = array( - 'dir' => path_join( WP_CONTENT_DIR, 'fonts' ), - 'url' => content_url( 'fonts' ), - ); - - return apply_filters( 'fonts_dir', $fonts_dir_settings ); + public static function fonts_dir( $defaults = array() ) { + $site_path = self::get_multi_site_fonts_sub_dir(); + + // Sets the defaults. + $defaults['path'] = path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path; + $defaults['url'] = untrailingslashit( content_url( 'fonts' ) ) . $site_path; + $defaults['subdir'] = ''; + $defaults['basedir'] = path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path; + $defaults['baseurl'] = untrailingslashit( content_url( 'fonts' ) ) . $site_path; + $defaults['error'] = false; + + // Filters the fonts directory data. + return apply_filters( 'fonts_dir', $defaults ); } /** @@ -179,32 +205,8 @@ private static function get_multi_site_fonts_sub_dir() { * @return string Path of the upload directory for fonts. */ public static function get_fonts_dir() { - $fonts_dir_settings = self::get_fonts_dir_settings(); - $fonts_sub_dir = self::get_multi_site_fonts_sub_dir(); - - return rtrim( $fonts_dir_settings['dir'], '/' ) . $fonts_sub_dir; - } - - /** - * Sets the upload directory for fonts. - * - * @since 6.5.0 - * - * @param array $defaults { - * Default upload directory. - * - * @type string $path Path to the directory. - * @type string $url URL for the directory. - * } - * @return array Modified upload directory. - */ - public static function set_upload_dir( $defaults ) { - $fonts_dir_settings = self::get_fonts_dir_settings(); - $fonts_sub_dir = self::get_multi_site_fonts_sub_dir(); - - $defaults['path'] = rtrim( $fonts_dir_settings['dir'], '/' ) . $fonts_sub_dir; - $defaults['url'] = untrailingslashit( $fonts_dir_settings['url'] ) . $fonts_sub_dir; - return $defaults; + $fonts_dir_settings = self::fonts_dir(); + return $fonts_dir_settings['path']; } /** From e11a7d870babc37c4ad2abd2ec656617bd380b4a Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Wed, 10 Jan 2024 09:26:31 -0300 Subject: [PATCH 08/10] remove tests no longer used --- .../wpFontLibrary/getFontsDir.php | 18 ------------- .../wpFontLibrary/setUploadDir.php | 26 ------------------- 2 files changed, 44 deletions(-) delete mode 100644 phpunit/tests/fonts/font-library/wpFontLibrary/getFontsDir.php delete mode 100644 phpunit/tests/fonts/font-library/wpFontLibrary/setUploadDir.php diff --git a/phpunit/tests/fonts/font-library/wpFontLibrary/getFontsDir.php b/phpunit/tests/fonts/font-library/wpFontLibrary/getFontsDir.php deleted file mode 100644 index 1200200d7160b..0000000000000 --- a/phpunit/tests/fonts/font-library/wpFontLibrary/getFontsDir.php +++ /dev/null @@ -1,18 +0,0 @@ -assertStringEndsWith( '/wp-content/fonts', WP_Font_Library::get_fonts_dir() ); - } -} diff --git a/phpunit/tests/fonts/font-library/wpFontLibrary/setUploadDir.php b/phpunit/tests/fonts/font-library/wpFontLibrary/setUploadDir.php deleted file mode 100644 index a69b89d1814d8..0000000000000 --- a/phpunit/tests/fonts/font-library/wpFontLibrary/setUploadDir.php +++ /dev/null @@ -1,26 +0,0 @@ - '/any/path/abc', - 'url' => 'http://example.com/an/arbitrary/url/abc', - ); - $expected = array( - 'path' => path_join( WP_CONTENT_DIR, 'fonts' ), - 'url' => content_url( 'fonts' ), - ); - $this->assertSame( $expected, WP_Font_Library::set_upload_dir( $defaults ) ); - } -} From 59fe6e61dfc92c4ab2755f9329afd3ba7533e72f Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Wed, 10 Jan 2024 09:26:55 -0300 Subject: [PATCH 09/10] add a test case for the filter --- .../font-library/wpFontLibrary/fontsDir.php | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 phpunit/tests/fonts/font-library/wpFontLibrary/fontsDir.php diff --git a/phpunit/tests/fonts/font-library/wpFontLibrary/fontsDir.php b/phpunit/tests/fonts/font-library/wpFontLibrary/fontsDir.php new file mode 100644 index 0000000000000..9926bb7409088 --- /dev/null +++ b/phpunit/tests/fonts/font-library/wpFontLibrary/fontsDir.php @@ -0,0 +1,70 @@ +dir_defaults = array( + 'path' => path_join( WP_CONTENT_DIR, 'fonts' ), + 'url' => content_url( 'fonts' ), + 'subdir' => '', + 'basedir' => path_join( WP_CONTENT_DIR, 'fonts' ), + 'baseurl' => content_url( 'fonts' ), + 'error' => false, + ); + } + + public function test_fonts_dir() { + $fonts_dir = WP_Font_Library::fonts_dir(); + $this->assertEquals( $fonts_dir, $this->dir_defaults ); + } + + public function test_fonts_dir_with_filter() { + // Define a callback function to pass to the filter. + function set_new_values( $defaults ) { + $defaults['path'] = '/custom-path/fonts/my-custom-subdir'; + $defaults['url'] = 'http://example.com/custom-path/fonts/my-custom-subdir'; + $defaults['subdir'] = 'my-custom-subdir'; + $defaults['basedir'] = '/custom-path/fonts'; + $defaults['baseurl'] = 'http://example.com/custom-path/fonts'; + $defaults['error'] = false; + return $defaults; + } + + // Add the filter. + add_filter( 'fonts_dir', 'set_new_values' ); + + // Gets the fonts dir. + $fonts_dir = WP_Font_Library::fonts_dir(); + + $expected = array( + 'path' => '/custom-path/fonts/my-custom-subdir', + 'url' => 'http://example.com/custom-path/fonts/my-custom-subdir', + 'subdir' => 'my-custom-subdir', + 'basedir' => '/custom-path/fonts', + 'baseurl' => 'http://example.com/custom-path/fonts', + 'error' => false, + ); + + $this->assertEquals( $fonts_dir, $expected, 'The fonts_dir() method should return the expected values.' ); + + // Remove the filter. + remove_filter( 'fonts_dir', 'set_new_values' ); + + // Gets the fonts dir. + $fonts_dir = WP_Font_Library::fonts_dir(); + + $this->assertEquals( $fonts_dir, $this->dir_defaults, 'The fonts_dir() method should return the default values.' ); + } +} From c76839c0cfe72ef93bafb3980de24f27f85385ed Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Wed, 10 Jan 2024 09:41:57 -0300 Subject: [PATCH 10/10] rename function. Replaces the misleading 'subdir' term by 'dir'. --- .../fonts/font-library/class-wp-font-library.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/experimental/fonts/font-library/class-wp-font-library.php b/lib/experimental/fonts/font-library/class-wp-font-library.php index 40e3a90d45b67..99de81e0bd74a 100644 --- a/lib/experimental/fonts/font-library/class-wp-font-library.php +++ b/lib/experimental/fonts/font-library/class-wp-font-library.php @@ -168,7 +168,7 @@ public static function get_font_collection( $id ) { * } */ public static function fonts_dir( $defaults = array() ) { - $site_path = self::get_multi_site_fonts_sub_dir(); + $site_path = self::get_multi_site_dir(); // Sets the defaults. $defaults['path'] = path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path; @@ -183,13 +183,13 @@ public static function fonts_dir( $defaults = array() ) { } /** - * Gets sub-dir for fonts, using the blog ID if multi-site, empty otherwise. + * Gets the Site dir for fonts, using the blog ID if multi-site, empty otherwise. * * @since 6.5.0 * - * @return string site sub-dir path. + * @return string Site dir path. */ - private static function get_multi_site_fonts_sub_dir() { + private static function get_multi_site_dir() { $font_sub_dir = ''; if ( is_multisite() && ! ( is_main_network() && is_main_site() ) ) { $font_sub_dir = '/sites/' . get_current_blog_id();