Make WordPress Core


Ignore:
Timestamp:
02/21/2024 07:24:14 PM (8 months ago)
Author:
swissspidy
Message:

Editor: Ensure font collection metadata can be properly localized.

Updates wp_register_font_collection() and WP_Font_Collection so that only font families can be loaded from a file or URL.
All metadata, such as name, description, and list of font categories, needs to be passed directly in PHP so that it can be properly localized.

Props swissspidy, mmaattiiaass, grantmkin, youknowriad.
Fixes #60509.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/fonts/class-wp-font-library.php

    r57548 r57686  
    3838     * @since 6.5.0
    3939     *
    40      * @param string $slug         Font collection slug.
    41      * @param array  $data_or_file Font collection data array or a path/URL to a JSON file
    42      *                             containing the font collection.
    43      *                             See {@see wp_register_font_collection()} for the supported fields.
     40     * @param string $slug Font collection slug. May only contain alphanumeric characters, dashes,
     41     *                     and underscores. See sanitize_title().
     42     * @param array  $args Font collection data. See wp_register_font_collection() for information on accepted arguments.
    4443     * @return WP_Font_Collection|WP_Error A font collection if it was registered successfully,
    4544     *                                     or WP_Error object on failure.
    4645     */
    47     public function register_font_collection( $slug, $data_or_file ) {
    48         $new_collection = new WP_Font_Collection( $slug, $data_or_file );
     46    public function register_font_collection( string $slug, array $args ) {
     47        $new_collection = new WP_Font_Collection( $slug, $args );
    4948
    5049        if ( $this->is_collection_registered( $new_collection->slug ) ) {
     
    7372     * @return bool True if the font collection was unregistered successfully and false otherwise.
    7473     */
    75     public function unregister_font_collection( $slug ) {
     74    public function unregister_font_collection( string $slug ) {
    7675        if ( ! $this->is_collection_registered( $slug ) ) {
    7776            _doing_it_wrong(
     
    9594     * @return bool True if the font collection is registered and false otherwise.
    9695     */
    97     private function is_collection_registered( $slug ) {
     96    private function is_collection_registered( string $slug ) {
    9897        return array_key_exists( $slug, $this->collections );
    9998    }
     
    118117     * @return WP_Font_Collection|null Font collection object, or null if the font collection doesn't exist.
    119118     */
    120     public function get_font_collection( $slug ) {
     119    public function get_font_collection( string $slug ) {
    121120        if ( $this->is_collection_registered( $slug ) ) {
    122121            return $this->collections[ $slug ];
Note: See TracChangeset for help on using the changeset viewer.