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..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 @@ -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; + } } /** @@ -95,6 +94,7 @@ public function get_data() { 'description' => '', 'categories' => array(), ); + return wp_parse_args( $this->data, $defaults ); } @@ -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 ); 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..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(); @@ -52,8 +51,8 @@ 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' ), + /* translators: %s: Font collection slug. */ + __( 'Font collection with slug "%s" is already registered.', 'gutenberg' ), $new_collection->slug ); _doing_it_wrong( @@ -122,7 +121,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.' ); diff --git a/lib/compat/wordpress-6.5/fonts/fonts.php b/lib/compat/wordpress-6.5/fonts/fonts.php index e6913b0d8a57eb..96bd089488e8fd 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(); @@ -258,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 );