diff --git a/lib/README.md b/lib/README.md
index 0e8c4263a49910..2c8e6cb2385d62 100644
--- a/lib/README.md
+++ b/lib/README.md
@@ -86,16 +86,15 @@ Or for classes:
* @package WordPress
* @since 6.3.0
*/
-if ( class_exists( 'WP_A_Stable_Class' ) ) {
- return;
+if ( ! class_exists( 'WP_A_Stable_Class' ) ) {
+ /**
+ * A very stable class that does something.
+ *
+ * @since 6.3.0
+ */
+ class WP_A_Stable_Class { ... }
}
-/**
- * A very stable class that does something.
- *
- * @since 6.3.0
- */
-class WP_A_Stable_Class { ... }
```
Wrapping code in `class_exists()` and `function_exists()` is usually inappropriate for evergreen code, or any plugin code that we expect to undergo constant change between WordPress releases, because it would prevent the latest versions of the code from being used. For example, the statement `class_exists( 'WP_Theme_JSON' )` would return `true` because the class already exists in Core.
diff --git a/lib/class-wp-duotone-gutenberg.php b/lib/class-wp-duotone-gutenberg.php
index 93714e59740063..85af24c1787ee8 100644
--- a/lib/class-wp-duotone-gutenberg.php
+++ b/lib/class-wp-duotone-gutenberg.php
@@ -32,10 +32,6 @@
* @since 6.3.0
*/
-if ( class_exists( 'WP_Duotone_Gutenberg' ) ) {
- return;
-}
-
/**
* Manages duotone block supports and global styles.
*
diff --git a/lib/class-wp-rest-global-styles-controller-gutenberg.php b/lib/class-wp-rest-global-styles-controller-gutenberg.php
index 8125b2ebf1c288..79cb8af59df4f9 100644
--- a/lib/class-wp-rest-global-styles-controller-gutenberg.php
+++ b/lib/class-wp-rest-global-styles-controller-gutenberg.php
@@ -10,10 +10,6 @@
* @since 5.9.0
*/
-if ( class_exists( 'WP_REST_Global_Styles_Controller_Gutenberg' ) ) {
- return;
-}
-
/**
* Base Global Styles REST API Controller.
*/
diff --git a/lib/class-wp-theme-json-data-gutenberg.php b/lib/class-wp-theme-json-data-gutenberg.php
index f0d2025347493b..6877a209b687f5 100644
--- a/lib/class-wp-theme-json-data-gutenberg.php
+++ b/lib/class-wp-theme-json-data-gutenberg.php
@@ -6,10 +6,6 @@
* @since 6.1.0
*/
-if ( class_exists( 'WP_Theme_JSON_Data_Gutenberg' ) ) {
- return;
-}
-
/**
* Class to provide access to update a theme.json structure.
*/
diff --git a/lib/class-wp-theme-json-gutenberg.php b/lib/class-wp-theme-json-gutenberg.php
index e23b0c88dd7070..6287a822238a23 100644
--- a/lib/class-wp-theme-json-gutenberg.php
+++ b/lib/class-wp-theme-json-gutenberg.php
@@ -6,10 +6,6 @@
* @since 5.8.0
*/
-if ( class_exists( 'WP_Theme_JSON_Gutenberg' ) ) {
- return;
-}
-
/**
* Class that encapsulates the processing of structures that adhere to the theme.json spec.
*
diff --git a/lib/class-wp-theme-json-resolver-gutenberg.php b/lib/class-wp-theme-json-resolver-gutenberg.php
index 189d411db2257f..97d8e4534d899c 100644
--- a/lib/class-wp-theme-json-resolver-gutenberg.php
+++ b/lib/class-wp-theme-json-resolver-gutenberg.php
@@ -6,10 +6,6 @@
* @since 5.8.0
*/
-if ( class_exists( 'WP_Theme_JSON_Resolver_Gutenberg' ) ) {
- return;
-}
-
/**
* Class that abstracts the processing of the different data sources
* for site-level config and offers an API to work with them.
diff --git a/lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face-resolver.php b/lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face-resolver.php
index 01b9d4566aa670..556663b8813665 100644
--- a/lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face-resolver.php
+++ b/lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face-resolver.php
@@ -9,176 +9,175 @@
* @core-merge: this file is located in `wp-includes/fonts/`.
*/
-if ( class_exists( 'WP_Font_Face_Resolver' ) ) {
- return;
-}
-
-/**
- * The Font Face Resolver abstracts the processing of different data sources
- * (such as theme.json) for processing within the Font Face.
- *
- * This class is for internal core usage and is not supposed to be used by
- * extenders (plugins and/or themes).
- *
- * @access private
- */
-class WP_Font_Face_Resolver {
+if ( ! class_exists( 'WP_Font_Face_Resolver' ) ) {
/**
- * Gets fonts defined in theme.json.
+ * The Font Face Resolver abstracts the processing of different data sources
+ * (such as theme.json) for processing within the Font Face.
*
- * @since 6.4.0
+ * This class is for internal core usage and is not supposed to be used by
+ * extenders (plugins and/or themes).
*
- * @return array Returns the font-families, each with their font-face variations.
+ * @access private
*/
- public static function get_fonts_from_theme_json() {
- $settings = gutenberg_get_global_settings();
+ class WP_Font_Face_Resolver {
+
+ /**
+ * Gets fonts defined in theme.json.
+ *
+ * @since 6.4.0
+ *
+ * @return array Returns the font-families, each with their font-face variations.
+ */
+ public static function get_fonts_from_theme_json() {
+ $settings = gutenberg_get_global_settings();
+
+ // Bail out early if there are no font settings.
+ if ( empty( $settings['typography']['fontFamilies'] ) ) {
+ return array();
+ }
- // Bail out early if there are no font settings.
- if ( empty( $settings['typography']['fontFamilies'] ) ) {
- return array();
+ return static::parse_settings( $settings );
}
- return static::parse_settings( $settings );
- }
-
- /**
- * Parse theme.json settings to extract font definitions with variations grouped by font-family.
- *
- * @since 6.4.0
- *
- * @param array $settings Font settings to parse.
- * @return array Returns an array of fonts, grouped by font-family.
- */
- private static function parse_settings( array $settings ) {
- $fonts = array();
-
- foreach ( $settings['typography']['fontFamilies'] as $font_families ) {
- foreach ( $font_families as $definition ) {
-
- // Skip if "fontFace" is not defined, meaning there are no variations.
- if ( empty( $definition['fontFace'] ) ) {
- continue;
- }
-
- // Skip if "fontFamily" is not defined.
- if ( empty( $definition['fontFamily'] ) ) {
- continue;
- }
-
- $font_family_name = static::maybe_parse_name_from_comma_separated_list( $definition['fontFamily'] );
-
- // Skip if no font family is defined.
- if ( empty( $font_family_name ) ) {
- continue;
+ /**
+ * Parse theme.json settings to extract font definitions with variations grouped by font-family.
+ *
+ * @since 6.4.0
+ *
+ * @param array $settings Font settings to parse.
+ * @return array Returns an array of fonts, grouped by font-family.
+ */
+ private static function parse_settings( array $settings ) {
+ $fonts = array();
+
+ foreach ( $settings['typography']['fontFamilies'] as $font_families ) {
+ foreach ( $font_families as $definition ) {
+
+ // Skip if "fontFace" is not defined, meaning there are no variations.
+ if ( empty( $definition['fontFace'] ) ) {
+ continue;
+ }
+
+ // Skip if "fontFamily" is not defined.
+ if ( empty( $definition['fontFamily'] ) ) {
+ continue;
+ }
+
+ $font_family_name = static::maybe_parse_name_from_comma_separated_list( $definition['fontFamily'] );
+
+ // Skip if no font family is defined.
+ if ( empty( $font_family_name ) ) {
+ continue;
+ }
+
+ // Prepare the fonts array structure for this font-family.
+ if ( ! array_key_exists( $font_family_name, $fonts ) ) {
+ $fonts[ $font_family_name ] = array();
+ }
+
+ $fonts[ $font_family_name ] = static::convert_font_face_properties( $definition['fontFace'], $font_family_name );
}
-
- // Prepare the fonts array structure for this font-family.
- if ( ! array_key_exists( $font_family_name, $fonts ) ) {
- $fonts[ $font_family_name ] = array();
- }
-
- $fonts[ $font_family_name ] = static::convert_font_face_properties( $definition['fontFace'], $font_family_name );
}
+
+ return $fonts;
}
- return $fonts;
- }
+ /**
+ * Parse font-family name from comma-separated lists.
+ *
+ * If the given `fontFamily` is a comma-separated lists (example: "Inter, sans-serif" ),
+ * parse and return the fist font from the list.
+ *
+ * @since 6.4.0
+ *
+ * @param string $font_family Font family `fontFamily' to parse.
+ * @return string Font-family name.
+ */
+ private static function maybe_parse_name_from_comma_separated_list( $font_family ) {
+ if ( str_contains( $font_family, ',' ) ) {
+ $font_family = explode( ',', $font_family )[0];
+ }
- /**
- * Parse font-family name from comma-separated lists.
- *
- * If the given `fontFamily` is a comma-separated lists (example: "Inter, sans-serif" ),
- * parse and return the fist font from the list.
- *
- * @since 6.4.0
- *
- * @param string $font_family Font family `fontFamily' to parse.
- * @return string Font-family name.
- */
- private static function maybe_parse_name_from_comma_separated_list( $font_family ) {
- if ( str_contains( $font_family, ',' ) ) {
- $font_family = explode( ',', $font_family )[0];
+ return trim( $font_family, "\"'" );
}
- return trim( $font_family, "\"'" );
- }
-
- /**
- * Converts font-face properties from theme.json format.
- *
- * @since 6.4.0
- *
- * @param array $font_face_definition The font-face definitions to convert.
- * @param string $font_family_property The value to store in the font-face font-family property.
- * @return array Converted font-face properties.
- */
- private static function convert_font_face_properties( array $font_face_definition, $font_family_property ) {
- $converted_font_faces = array();
+ /**
+ * Converts font-face properties from theme.json format.
+ *
+ * @since 6.4.0
+ *
+ * @param array $font_face_definition The font-face definitions to convert.
+ * @param string $font_family_property The value to store in the font-face font-family property.
+ * @return array Converted font-face properties.
+ */
+ private static function convert_font_face_properties( array $font_face_definition, $font_family_property ) {
+ $converted_font_faces = array();
+
+ foreach ( $font_face_definition as $font_face ) {
+ // Add the font-family property to the font-face.
+ $font_face['font-family'] = $font_family_property;
+
+ // Converts the "file:./" src placeholder into a theme font file URI.
+ if ( ! empty( $font_face['src'] ) ) {
+ $font_face['src'] = static::to_theme_file_uri( (array) $font_face['src'] );
+ }
- foreach ( $font_face_definition as $font_face ) {
- // Add the font-family property to the font-face.
- $font_face['font-family'] = $font_family_property;
+ // Convert camelCase properties into kebab-case.
+ $font_face = static::to_kebab_case( $font_face );
- // Converts the "file:./" src placeholder into a theme font file URI.
- if ( ! empty( $font_face['src'] ) ) {
- $font_face['src'] = static::to_theme_file_uri( (array) $font_face['src'] );
+ $converted_font_faces[] = $font_face;
}
- // Convert camelCase properties into kebab-case.
- $font_face = static::to_kebab_case( $font_face );
-
- $converted_font_faces[] = $font_face;
+ return $converted_font_faces;
}
- return $converted_font_faces;
- }
-
- /**
- * Converts each 'file:./' placeholder into a URI to the font file in the theme.
- *
- * The 'file:./' is specified in the theme's `theme.json` as a placeholder to be
- * replaced with the URI to the font file's location in the theme. When a "src"
- * beings with this placeholder, it is replaced, converting the src into a URI.
- *
- * @since 6.4.0
- *
- * @param array $src An array of font file sources to process.
- * @return array An array of font file src URI(s).
- */
- private static function to_theme_file_uri( array $src ) {
- $placeholder = 'file:./';
+ /**
+ * Converts each 'file:./' placeholder into a URI to the font file in the theme.
+ *
+ * The 'file:./' is specified in the theme's `theme.json` as a placeholder to be
+ * replaced with the URI to the font file's location in the theme. When a "src"
+ * beings with this placeholder, it is replaced, converting the src into a URI.
+ *
+ * @since 6.4.0
+ *
+ * @param array $src An array of font file sources to process.
+ * @return array An array of font file src URI(s).
+ */
+ private static function to_theme_file_uri( array $src ) {
+ $placeholder = 'file:./';
+
+ foreach ( $src as $src_key => $src_url ) {
+ // Skip if the src doesn't start with the placeholder, as there's nothing to replace.
+ if ( ! str_starts_with( $src_url, $placeholder ) ) {
+ continue;
+ }
- foreach ( $src as $src_key => $src_url ) {
- // Skip if the src doesn't start with the placeholder, as there's nothing to replace.
- if ( ! str_starts_with( $src_url, $placeholder ) ) {
- continue;
+ $src_file = str_replace( $placeholder, '', $src_url );
+ $src[ $src_key ] = get_theme_file_uri( $src_file );
}
- $src_file = str_replace( $placeholder, '', $src_url );
- $src[ $src_key ] = get_theme_file_uri( $src_file );
+ return $src;
}
- return $src;
- }
-
- /**
- * Converts all first dimension keys into kebab-case.
- *
- * @since 6.4.0
- *
- * @param array $data The array to process.
- * @return array Data with first dimension keys converted into kebab-case.
- */
- private static function to_kebab_case( array $data ) {
- foreach ( $data as $key => $value ) {
- $kebab_case = _wp_to_kebab_case( $key );
- $data[ $kebab_case ] = $value;
- if ( $kebab_case !== $key ) {
- unset( $data[ $key ] );
+ /**
+ * Converts all first dimension keys into kebab-case.
+ *
+ * @since 6.4.0
+ *
+ * @param array $data The array to process.
+ * @return array Data with first dimension keys converted into kebab-case.
+ */
+ private static function to_kebab_case( array $data ) {
+ foreach ( $data as $key => $value ) {
+ $kebab_case = _wp_to_kebab_case( $key );
+ $data[ $kebab_case ] = $value;
+ if ( $kebab_case !== $key ) {
+ unset( $data[ $key ] );
+ }
}
- }
- return $data;
+ return $data;
+ }
}
}
diff --git a/lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face.php b/lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face.php
index 8bb1d55414854f..6bea6eb86cc714 100644
--- a/lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face.php
+++ b/lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face.php
@@ -9,428 +9,427 @@
* @core-merge: this file is located in `wp-includes/fonts/`.
*/
-if ( class_exists( 'WP_Font_Face' ) ) {
- return;
-}
-
-/**
- * Font Face generates and prints `@font-face` styles for given fonts.
- *
- * @since 6.4.0
- */
-class WP_Font_Face {
+if ( ! class_exists( 'WP_Font_Face' ) ) {
/**
- * The font-face property defaults.
+ * Font Face generates and prints `@font-face` styles for given fonts.
*
* @since 6.4.0
- *
- * @var string[]
*/
- private $font_face_property_defaults = array(
- 'font-family' => '',
- 'font-style' => 'normal',
- 'font-weight' => '400',
- 'font-display' => 'fallback',
- );
+ class WP_Font_Face {
+
+ /**
+ * The font-face property defaults.
+ *
+ * @since 6.4.0
+ *
+ * @var string[]
+ */
+ private $font_face_property_defaults = array(
+ 'font-family' => '',
+ 'font-style' => 'normal',
+ 'font-weight' => '400',
+ 'font-display' => 'fallback',
+ );
+
+ /**
+ * Valid font-face property names.
+ *
+ * @since 6.4.0
+ *
+ * @var string[]
+ */
+ private $valid_font_face_properties = array(
+ 'ascent-override',
+ 'descent-override',
+ 'font-display',
+ 'font-family',
+ 'font-stretch',
+ 'font-style',
+ 'font-weight',
+ 'font-variant',
+ 'font-feature-settings',
+ 'font-variation-settings',
+ 'line-gap-override',
+ 'size-adjust',
+ 'src',
+ 'unicode-range',
+ );
+
+ /**
+ * Valid font-display values.
+ *
+ * @since 6.4.0
+ *
+ * @var string[]
+ */
+ private $valid_font_display = array( 'auto', 'block', 'fallback', 'swap', 'optional' );
+
+ /**
+ * Array of font-face style tag's attribute(s)
+ * where the key is the attribute name and the
+ * value is its value.
+ *
+ * @since 6.4.0
+ *
+ * @var string[]
+ */
+ private $style_tag_attrs = array();
- /**
- * Valid font-face property names.
- *
- * @since 6.4.0
- *
- * @var string[]
- */
- private $valid_font_face_properties = array(
- 'ascent-override',
- 'descent-override',
- 'font-display',
- 'font-family',
- 'font-stretch',
- 'font-style',
- 'font-weight',
- 'font-variant',
- 'font-feature-settings',
- 'font-variation-settings',
- 'line-gap-override',
- 'size-adjust',
- 'src',
- 'unicode-range',
- );
+ /**
+ * Creates and initializes an instance of WP_Font_Face.
+ *
+ * @since 6.4.0
+ */
+ public function __construct() {
+ if (
+ function_exists( 'is_admin' ) && ! is_admin()
+ &&
+ function_exists( 'current_theme_supports' ) && ! current_theme_supports( 'html5', 'style' )
+ ) {
+ $this->style_tag_attrs = array( 'type' => 'text/css' );
+ }
+ }
- /**
- * Valid font-display values.
- *
- * @since 6.4.0
- *
- * @var string[]
- */
- private $valid_font_display = array( 'auto', 'block', 'fallback', 'swap', 'optional' );
+ /**
+ * Generates and prints the `@font-face` styles for the given fonts.
+ *
+ * @since 6.4.0
+ *
+ * @param array[][] $fonts Optional. The font-families and their font variations.
+ * See {@see wp_print_font_faces()} for the supported fields.
+ * Default empty array.
+ */
+ public function generate_and_print( array $fonts ) {
+ $fonts = $this->validate_fonts( $fonts );
- /**
- * Array of font-face style tag's attribute(s)
- * where the key is the attribute name and the
- * value is its value.
- *
- * @since 6.4.0
- *
- * @var string[]
- */
- private $style_tag_attrs = array();
+ // Bail out if there are no fonts are given to process.
+ if ( empty( $fonts ) ) {
+ return;
+ }
- /**
- * Creates and initializes an instance of WP_Font_Face.
- *
- * @since 6.4.0
- */
- public function __construct() {
- if (
- function_exists( 'is_admin' ) && ! is_admin()
- &&
- function_exists( 'current_theme_supports' ) && ! current_theme_supports( 'html5', 'style' )
- ) {
- $this->style_tag_attrs = array( 'type' => 'text/css' );
- }
- }
+ $css = $this->get_css( $fonts );
- /**
- * Generates and prints the `@font-face` styles for the given fonts.
- *
- * @since 6.4.0
- *
- * @param array[][] $fonts Optional. The font-families and their font variations.
- * See {@see wp_print_font_faces()} for the supported fields.
- * Default empty array.
- */
- public function generate_and_print( array $fonts ) {
- $fonts = $this->validate_fonts( $fonts );
+ /*
+ * The font-face CSS is contained within and open a