From 6c1284896c272ff7b5f993a89c02fe679010adff Mon Sep 17 00:00:00 2001 From: Grant Kinney Date: Mon, 5 Feb 2024 13:16:51 -0600 Subject: [PATCH 1/9] Removes unneeded comment in wp_get_font_dir --- lib/compat/wordpress-6.5/fonts/fonts.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/compat/wordpress-6.5/fonts/fonts.php b/lib/compat/wordpress-6.5/fonts/fonts.php index e6913b0d8a57eb..c3ac3757401b7f 100644 --- a/lib/compat/wordpress-6.5/fonts/fonts.php +++ b/lib/compat/wordpress-6.5/fonts/fonts.php @@ -184,7 +184,6 @@ function gutenberg_register_font_collections() { * } */ function wp_get_font_dir( $defaults = array() ) { - // Multi site path $site_path = ''; if ( is_multisite() && ! ( is_main_network() && is_main_site() ) ) { $site_path = '/sites/' . get_current_blog_id(); From fc3f6fce7ffd823f43542c05848b257e6b9019cd Mon Sep 17 00:00:00 2001 From: Grant Kinney Date: Mon, 5 Feb 2024 13:19:19 -0600 Subject: [PATCH 2/9] Move font collection slug check to immediately after slug is assigned --- .../fonts/class-wp-font-collection.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/compat/wordpress-6.5/fonts/class-wp-font-collection.php b/lib/compat/wordpress-6.5/fonts/class-wp-font-collection.php index 019cf0f3f0b29d..a5ee289755b35a 100644 --- a/lib/compat/wordpress-6.5/fonts/class-wp-font-collection.php +++ b/lib/compat/wordpress-6.5/fonts/class-wp-font-collection.php @@ -55,14 +55,6 @@ final class WP_Font_Collection { */ public function __construct( $slug, $data_or_file ) { $this->slug = sanitize_title( $slug ); - - if ( is_array( $data_or_file ) ) { - $this->data = $this->sanitize_and_validate_data( $data_or_file ); - } else { - // JSON data is lazy loaded by ::get_data(). - $this->src = $data_or_file; - } - if ( $this->slug !== $slug ) { _doing_it_wrong( __METHOD__, @@ -71,6 +63,13 @@ public function __construct( $slug, $data_or_file ) { '6.5.0' ); } + + if ( is_array( $data_or_file ) ) { + $this->data = $this->sanitize_and_validate_data( $data_or_file ); + } else { + // JSON data is lazy loaded by ::get_data(). + $this->src = $data_or_file; + } } /** From b8db2bd9bd86e8805e9649693d17ba0cfadcf061 Mon Sep 17 00:00:00 2001 From: Grant Kinney Date: Mon, 5 Feb 2024 13:21:16 -0600 Subject: [PATCH 3/9] Fix translators comment indentation --- lib/compat/wordpress-6.5/fonts/class-wp-font-library.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.5/fonts/class-wp-font-library.php b/lib/compat/wordpress-6.5/fonts/class-wp-font-library.php index 9bf90ca1d9dd8a..498faf5fe48541 100644 --- a/lib/compat/wordpress-6.5/fonts/class-wp-font-library.php +++ b/lib/compat/wordpress-6.5/fonts/class-wp-font-library.php @@ -52,7 +52,7 @@ public function register_font_collection( $slug, $data_or_file ) { if ( $this->is_collection_registered( $new_collection->slug ) ) { $error_message = sprintf( - /* translators: %s: Font collection slug. */ + /* translators: %s: Font collection slug. */ __( 'Font collection with slug: "%s" is already registered.', 'gutenberg' ), $new_collection->slug ); From 3c6d65d29c6ee7a3eeb41f499e6b0a6f416573b9 Mon Sep 17 00:00:00 2001 From: Grant Kinney Date: Mon, 5 Feb 2024 13:22:12 -0600 Subject: [PATCH 4/9] Remove unneeded colon from error message --- lib/compat/wordpress-6.5/fonts/class-wp-font-library.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.5/fonts/class-wp-font-library.php b/lib/compat/wordpress-6.5/fonts/class-wp-font-library.php index 498faf5fe48541..ecbbecba623d2d 100644 --- a/lib/compat/wordpress-6.5/fonts/class-wp-font-library.php +++ b/lib/compat/wordpress-6.5/fonts/class-wp-font-library.php @@ -53,7 +53,7 @@ public function register_font_collection( $slug, $data_or_file ) { if ( $this->is_collection_registered( $new_collection->slug ) ) { $error_message = sprintf( /* translators: %s: Font collection slug. */ - __( 'Font collection with slug: "%s" is already registered.', 'gutenberg' ), + __( 'Font collection with slug "%s" is already registered.', 'gutenberg' ), $new_collection->slug ); _doing_it_wrong( From b51db012b8c26f48a9d402253d3cf3071f530c3a Mon Sep 17 00:00:00 2001 From: Grant Kinney Date: Mon, 5 Feb 2024 13:32:20 -0600 Subject: [PATCH 5/9] Use is_collection_registered in get_font_collection --- lib/compat/wordpress-6.5/fonts/class-wp-font-library.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.5/fonts/class-wp-font-library.php b/lib/compat/wordpress-6.5/fonts/class-wp-font-library.php index ecbbecba623d2d..925a429624fa07 100644 --- a/lib/compat/wordpress-6.5/fonts/class-wp-font-library.php +++ b/lib/compat/wordpress-6.5/fonts/class-wp-font-library.php @@ -122,7 +122,7 @@ public function get_font_collections() { * or WP_Error object if the font collection doesn't exist. */ public function get_font_collection( $slug ) { - if ( array_key_exists( $slug, $this->collections ) ) { + if ( $this->is_collection_registered( $slug ) ) { return $this->collections[ $slug ]; } return new WP_Error( 'font_collection_not_found', 'Font collection not found.' ); From 59478bc04ce5916f38dd20b5ae51023c81e92458 Mon Sep 17 00:00:00 2001 From: Grant Kinney Date: Mon, 5 Feb 2024 13:41:40 -0600 Subject: [PATCH 6/9] Removes extra line in WP_Font_Library::$collections docblock --- lib/compat/wordpress-6.5/fonts/class-wp-font-library.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/compat/wordpress-6.5/fonts/class-wp-font-library.php b/lib/compat/wordpress-6.5/fonts/class-wp-font-library.php index 925a429624fa07..6e735ad31c5459 100644 --- a/lib/compat/wordpress-6.5/fonts/class-wp-font-library.php +++ b/lib/compat/wordpress-6.5/fonts/class-wp-font-library.php @@ -22,7 +22,6 @@ class WP_Font_Library { * Font collections. * * @since 6.5.0 - * * @var array */ private $collections = array(); From 62487785d063292c9f76ed726687ade8684afc0b Mon Sep 17 00:00:00 2001 From: Grant Kinney Date: Mon, 5 Feb 2024 14:21:19 -0600 Subject: [PATCH 7/9] Use variable for font_dir so function isn't called repeatedly within loop --- lib/compat/wordpress-6.5/fonts/fonts.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.5/fonts/fonts.php b/lib/compat/wordpress-6.5/fonts/fonts.php index c3ac3757401b7f..96bd089488e8fd 100644 --- a/lib/compat/wordpress-6.5/fonts/fonts.php +++ b/lib/compat/wordpress-6.5/fonts/fonts.php @@ -257,9 +257,10 @@ function _wp_before_delete_font_face( $post_id, $post ) { } $font_files = get_post_meta( $post_id, '_wp_font_face_file', false ); + $font_dir = wp_get_font_dir()['path']; foreach ( $font_files as $font_file ) { - wp_delete_file( wp_get_font_dir()['path'] . '/' . $font_file ); + wp_delete_file( $font_dir . '/' . $font_file ); } } add_action( 'before_delete_post', '_wp_before_delete_font_face', 10, 2 ); From b27b0ad17903efae6c597233d2ae40441b72bd01 Mon Sep 17 00:00:00 2001 From: Grant Kinney Date: Mon, 5 Feb 2024 14:27:06 -0600 Subject: [PATCH 8/9] Adds empty line before the return of WP_Font_Collection::get_data --- lib/compat/wordpress-6.5/fonts/class-wp-font-collection.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/compat/wordpress-6.5/fonts/class-wp-font-collection.php b/lib/compat/wordpress-6.5/fonts/class-wp-font-collection.php index a5ee289755b35a..9078beb40f160d 100644 --- a/lib/compat/wordpress-6.5/fonts/class-wp-font-collection.php +++ b/lib/compat/wordpress-6.5/fonts/class-wp-font-collection.php @@ -94,6 +94,7 @@ public function get_data() { 'description' => '', 'categories' => array(), ); + return wp_parse_args( $this->data, $defaults ); } From 4d8472acac32ef24071fdd5edbe295f964d363c6 Mon Sep 17 00:00:00 2001 From: Grant Kinney Date: Mon, 5 Feb 2024 14:36:08 -0600 Subject: [PATCH 9/9] Uses static closure in font collection sanitization schema --- lib/compat/wordpress-6.5/fonts/class-wp-font-collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.5/fonts/class-wp-font-collection.php b/lib/compat/wordpress-6.5/fonts/class-wp-font-collection.php index 9078beb40f160d..bfaef134d0fdae 100644 --- a/lib/compat/wordpress-6.5/fonts/class-wp-font-collection.php +++ b/lib/compat/wordpress-6.5/fonts/class-wp-font-collection.php @@ -229,7 +229,7 @@ private static function get_sanitization_schema() { 'fontFamily' => 'sanitize_text_field', 'fontStyle' => 'sanitize_text_field', 'fontWeight' => 'sanitize_text_field', - 'src' => function ( $value ) { + 'src' => static function ( $value ) { return is_array( $value ) ? array_map( 'sanitize_text_field', $value ) : sanitize_text_field( $value );