Plugin Directory

Changeset 3323421


Ignore:
Timestamp:
07/07/2025 10:35:04 AM (9 months ago)
Author:
DannyCooper
Message:

Update to version 3.9.5 from GitHub

Location:
olympus-google-fonts
Files:
32 edited
1 copied

Legend:

Unmodified
Added
Removed
  • olympus-google-fonts/tags/3.9.5/admin/class-ogf-upload-fonts-screen.php

    r3100693 r3323421  
    9797            $parent_file = $this->parent_menu_slug; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
    9898        }
    99         if ( get_current_screen()->id != 'edit-' . OGF_Fonts_Taxonomy::$taxonomy_slug ) {
     99        $screen = get_current_screen();
     100        if ( ! $screen || $screen->id != 'edit-' . OGF_Fonts_Taxonomy::$taxonomy_slug ) {
    100101            return;
    101102        }
     
    118119    public function manage_columns( $columns ) {
    119120        $screen = get_current_screen();
     121        if ( ! $screen || $screen->id != 'edit-' . OGF_Fonts_Taxonomy::$taxonomy_slug ) {
     122            return;
     123        }
    120124        // If current screen is add new custom fonts screen.
    121125        if ( isset( $screen->base ) && 'edit-tags' == $screen->base ) {
     
    417421
    418422    /**
     423     * Get the correct MIME type for a font file extension.
     424     *
     425     * @param string $extension The file extension.
     426     * @return string The MIME type.
     427     */
     428    private function get_font_mime_type( $extension ) {
     429        switch ( $extension ) {
     430            case 'ttf':
     431                $php_7_ttf_mime_type = PHP_VERSION_ID >= 70300 ? 'application/font-sfnt' : 'application/x-font-ttf';
     432                return PHP_VERSION_ID >= 70400 ? 'font/sfnt' : $php_7_ttf_mime_type;
     433
     434            case 'otf':
     435                return 'application/vnd.ms-opentype';
     436
     437            case 'woff':
     438                return PHP_VERSION_ID >= 80112 ? 'font/woff' : 'application/font-woff';
     439
     440            case 'woff2':
     441                return PHP_VERSION_ID >= 80112 ? 'font/woff2' : 'application/font-woff2';
     442
     443            default:
     444                return '';
     445        }
     446    }
     447
     448    /**
    419449     * Add WOFF and WOFF2 to the allowed mime types.
    420450     *
     
    423453     */
    424454    public function add_to_allowed_mimes( $mimes ) {
    425 
    426         $php_7_ttf_mime_type = PHP_VERSION_ID >= 70300 ? 'application/font-sfnt' : 'application/x-font-ttf';
    427 
    428         $mimes['otf']   = 'application/vnd.ms-opentype';
    429         $mimes['ttf']   = PHP_VERSION_ID >= 70400 ? 'font/sfnt' : $php_7_ttf_mime_type;
    430         $mimes['woff']  = PHP_VERSION_ID >= 80112 ? 'font/woff' : 'application/font-woff';
    431         $mimes['woff2'] = PHP_VERSION_ID >= 80112 ? 'font/woff2' : 'application/font-woff2';
     455        $mimes['otf']   = $this->get_font_mime_type( 'otf' );
     456        $mimes['ttf']   = $this->get_font_mime_type( 'ttf' );
     457        $mimes['woff']  = $this->get_font_mime_type( 'woff' );
     458        $mimes['woff2'] = $this->get_font_mime_type( 'woff2' );
    432459
    433460        return $mimes;
     
    445472     */
    446473    public function update_mime_types( $defaults, $file, $filename ) {
    447         if ( 'ttf' === pathinfo( $filename, PATHINFO_EXTENSION ) ) {
    448             $defaults['type'] = 'application/x-font-ttf';
    449             $defaults['ext']  = 'ttf';
    450         }
    451 
    452         if ( 'otf' === pathinfo( $filename, PATHINFO_EXTENSION ) ) {
    453             $defaults['type'] = 'application/x-font-otf';
    454             $defaults['ext']  = 'otf';
     474        $extension = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );
     475
     476        // Get the MIME type using the same logic as add_to_allowed_mimes().
     477        $mime_type = $this->get_font_mime_type( $extension );
     478
     479        if ( ! empty( $mime_type ) ) {
     480            $defaults['type'] = $mime_type;
     481            $defaults['ext']  = $extension;
    455482        }
    456483
  • olympus-google-fonts/tags/3.9.5/assets/js/uploadFonts.js

    r3100693 r3323421  
    5151                file_frame.open();
    5252            });
    53             var file_frame;
    54             window.inputWrapper = '';
    5553        },
    5654    }
  • olympus-google-fonts/tags/3.9.5/blocks/src/google-fonts/edit.js

    r3221683 r3323421  
    276276            },
    277277            {
    278                 value: '500',
     278                value: '600',
    279279                label: __('Semi Bold', 'olympus-google-fonts' ),
    280280            },
  • olympus-google-fonts/tags/3.9.5/changelog.txt

    r3320024 r3323421  
     1  = 3.9.5 =
     2 
     3  * Fix error when use Blubrry podcast plugin
     4  * Fix null reference errors when get_current_screen() returns null
     5  * Fix memory leak by implementing singleton pattern for font loading with backward compatibility
     6  * Fix PHP 8.0+ compatibility by replacing str_starts_with() with strpos()
     7  * Fix inconsistent MIME type handling for font file uploads
     8
    19= 3.9.4 =
    210
  • olympus-google-fonts/tags/3.9.5/class-olympus-google-fonts.php

    r3320024 r3323421  
    3939    public function constants() {
    4040        if ( ! defined( 'OGF_VERSION' ) ) {
    41             define( 'OGF_VERSION', '3.9.4' );
     41            define( 'OGF_VERSION', '3.9.5' );
    4242        }
    4343
     
    134134     */
    135135    public function enqueue() {
    136         $fonts = new OGF_Fonts();
     136        $fonts = OGF_Fonts::get_instance();
    137137
    138138        if ( ! $fonts->has_google_fonts() ) {
     
    165165        }
    166166
    167         $fonts = new OGF_Fonts();
     167        $fonts = OGF_Fonts::get_instance();
    168168
    169169        // If no Google Fonts are being used we don't need this.
  • olympus-google-fonts/tags/3.9.5/includes/class-ogf-classic-editor.php

    r3243818 r3323421  
    5050            }
    5151
    52             $this->ogf_fonts     = new OGF_Fonts();
     52            $this->ogf_fonts     = OGF_Fonts::get_instance();
    5353            $this->system_fonts  = ogf_system_fonts();
    5454            $this->custom_fonts  = ogf_custom_fonts();
  • olympus-google-fonts/tags/3.9.5/includes/class-ogf-clear-cache.php

    r3100693 r3323421  
    9090         */
    9191        public function clear() {
    92             $fonts = new OGF_Fonts();
     92            $fonts = OGF_Fonts::get_instance();
    9393
    9494            if ( $fonts->has_google_fonts() ) {
  • olympus-google-fonts/tags/3.9.5/includes/class-ogf-fonts.php

    r3100693 r3323421  
    2727
    2828    /**
    29      * Let's get started.
     29     * Single instance of the class.
     30     *
     31     * @var OGF_Fonts|null
     32     */
     33    private static $instance = null;
     34
     35    /**
     36     * Get the singleton instance.
     37     *
     38     * @return OGF_Fonts
     39     */
     40    public static function get_instance() {
     41        if ( null === self::$instance ) {
     42            self::$instance = new self();
     43        }
     44        return self::$instance;
     45    }
     46
     47    /**
     48     * Constructor - made public for backward compatibility.
     49     * External plugins/code can still use 'new OGF_Fonts()'.
    3050     */
    3151    public function __construct() {
    32         self::$google_fonts = ogf_fonts_array();
     52        // If this is not the singleton instance, just initialize normally for backward compatibility.
     53        if ( null !== self::$instance && self::$instance !== $this ) {
     54            // This is a separate instance for backward compatibility.
     55            $this->initialize();
     56            return;
     57        }
     58
     59        // This is the singleton instance.
     60        $this->initialize();
     61    }
     62
     63    /**
     64     * Initialize the font data and choices.
     65     */
     66    private function initialize() {
     67        // Only load fonts array if not already loaded.
     68        if ( empty( self::$google_fonts ) ) {
     69            self::$google_fonts = ogf_fonts_array();
     70        }
    3371        $this->get_choices();
     72    }
     73
     74    /**
     75     * Prevent cloning of the instance.
     76     */
     77    private function __clone() {}
     78
     79    /**
     80     * Prevent unserialization of the instance.
     81     *
     82     * @throws Exception When attempting to unserialize.
     83     */
     84    public function __wakeup() {
     85        throw new Exception( 'Cannot unserialize singleton' );
    3486    }
    3587
     
    78130     */
    79131    public function get_font_weights( $font_id ) {
     132        // Check if font exists in the array.
     133        if ( ! array_key_exists( $font_id, self::$google_fonts ) ) {
     134            return array();
     135        }
     136
     137        // Check if the font has variants data.
     138        if ( ! isset( self::$google_fonts[ $font_id ]['v'] ) ) {
     139            return array();
     140        }
     141
    80142        $weights = self::$google_fonts[ $font_id ]['v'];
    81143
     
    95157     */
    96158    public function get_font_subsets( $font_id ) {
     159        // Check if font exists in the array.
     160        if ( ! array_key_exists( $font_id, self::$google_fonts ) ) {
     161            return array();
     162        }
     163
     164        // Check if the font has subsets data.
     165        if ( ! isset( self::$google_fonts[ $font_id ]['s'] ) ) {
     166            return array();
     167        }
     168
    97169        $subsets = self::$google_fonts[ $font_id ]['s'];
    98170
     
    113185     */
    114186    public function get_font_name( $font_id ) {
    115         if ( array_key_exists( $font_id, self::$google_fonts ) ) {
     187        if ( array_key_exists( $font_id, self::$google_fonts ) && isset( self::$google_fonts[ $font_id ]['f'] ) ) {
    116188            return self::$google_fonts[ $font_id ]['f'];
    117189        } else {
     
    203275        if ( false === ( $external_font_css ) ) {
    204276            // It wasn't there, so regenerate the data and save the transient.
    205             $external_font_css  = '/* Cached: ' . date( 'F j, Y \a\t g:ia' ) . ' */' . PHP_EOL;
     277            $external_font_css  = '/* Cached: ' . gmdate( 'F j, Y \a\t g:ia' ) . ' */' . PHP_EOL;
    206278            $external_font_css .= $this->get_remote_url_contents( $url ) . PHP_EOL;
    207279            set_transient( 'ogf_external_font_css_' . $url_to_id, $external_font_css, DAY_IN_SECONDS );
  • olympus-google-fonts/tags/3.9.5/includes/class-ogf-typekit.php

    r3128267 r3323421  
    138138     */
    139139    public function css_styles() {
    140         if ( get_current_screen()->id !== 'fonts-plugin_page_fonts-plugin-typekit' ) {
     140        $screen = get_current_screen();
     141        if ( ! $screen || $screen->id !== 'fonts-plugin_page_fonts-plugin-typekit' ) {
    141142            return;
    142143        }
     
    159160
    160161        // Only perform action on the Fonts Plugin Typekit Page.
    161         if ( get_current_screen()->id !== 'fonts-plugin_page_fonts-plugin-typekit' ) {
     162        $screen = get_current_screen();
     163        if ( ! $screen || $screen->id !== 'fonts-plugin_page_fonts-plugin-typekit' ) {
    162164            return;
    163165        }
     
    231233    public function manage_kits() {
    232234        // Only perform action on the Fonts Plugin Typekit Page.
    233         if ( get_current_screen()->id !== 'fonts-plugin_page_fonts-plugin-typekit' ) {
     235        $screen = get_current_screen();
     236        if ( ! $screen || $screen->id !== 'fonts-plugin_page_fonts-plugin-typekit' ) {
    234237            return;
    235238        }
  • olympus-google-fonts/tags/3.9.5/includes/customizer/output-css.php

    r3254070 r3323421  
    208208    $cache_key    = 'ogf_font_stack_' . md5( $font_id );
    209209    $cached_stack = wp_cache_get( $cache_key );
    210    
    211210    if ( $cached_stack !== false ) {
    212211        return $cached_stack;
     
    216215    $stack = '';
    217216
    218     if ( str_starts_with( $font_id, 'sf-' ) !== false ) {
     217    if ( 0 === strpos( $font_id, 'sf-' ) ) {
    219218        $system_fonts = ogf_system_fonts();
    220219        $font_id      = str_replace( 'sf-', '', $font_id );
     
    223222            $stack = $system_fonts[ $font_id ]['stack'];
    224223        }
    225     } elseif ( str_starts_with( $font_id, 'cf-' ) !== false ) {
     224    } elseif ( 0 === strpos( $font_id, 'cf-' ) ) {
    226225        $custom_fonts = ogf_custom_fonts();
    227226        $font_id      = str_replace( 'cf-', '', $font_id );
     
    235234            $stack = '"' . $font . '"';
    236235        }
    237     } elseif ( str_starts_with( $font_id, 'tk-' ) !== false ) {
     236    } elseif ( 0 === strpos( $font_id, 'tk-' ) ) {
    238237        $typekit_fonts = ogf_typekit_fonts();
    239238
     
    250249
    251250    // Cache the result.
    252     wp_cache_set( $cache_key, $stack, 'ogf_font_stacks', HOUR_IN_SECONDS );
    253    
     251    wp_cache_set( $cache_key, $stack, 'ogf_font_stacks', HOUR_IN_SECONDS );
    254252    // Allow filtering of the final stack.
    255253    return apply_filters( "ogf_{$font_id}_stack", $stack );
  • olympus-google-fonts/tags/3.9.5/includes/customizer/settings.php

    r3100693 r3323421  
    298298    );
    299299
    300     $fonts   = new OGF_Fonts();
     300            $fonts   = OGF_Fonts::get_instance();
    301301    $subsets = array();
    302302
  • olympus-google-fonts/tags/3.9.5/includes/functions.php

    r3254070 r3323421  
    156156
    157157/**
     158 * Get the OGF_Fonts singleton instance.
     159 *
     160 * @return OGF_Fonts The singleton instance.
     161 */
     162function ogf_get_fonts_instance() {
     163    return OGF_Fonts::get_instance();
     164}
     165
     166
     167
     168/**
    158169 * Return an array of all available Google Fonts.
    159170 *
     
    167178    }
    168179
    169     $fonts_json = file_get_contents( OGF_DIR_PATH . '/blocks/src/google-fonts/fonts.json' );
    170 
    171     // Change the object to a multidimensional array.
     180    $fonts_file = OGF_DIR_PATH . '/blocks/src/google-fonts/fonts.json';
     181
     182    if ( ! file_exists( $fonts_file ) ) {
     183        return array();
     184    }
     185
     186    $fonts_json = file_get_contents( $fonts_file );
     187    if ( false === $fonts_json ) {
     188        return array();
     189    }
     190
    172191    $fonts_array = json_decode( $fonts_json, true );
    173 
    174     // Format the variants array for easier use.
    175     foreach ( $fonts_array as $key => $font ) {
    176         $fonts_array[ $key ] = $font;
    177     }
    178 
    179     // Change the array key to the font's ID.
     192    if ( null === $fonts_array ) {
     193        return array();
     194    }
     195
     196    // Existing processing logic...
    180197    foreach ( $fonts_array as $font ) {
    181         $id                = trim( strtolower( str_replace( ' ', '-', $font['f'] ) ) );
    182         $fonts[ $id ]      = $font;
     198        $id = trim( strtolower( str_replace( ' ', '-', $font['f'] ) ) );
     199        $fonts[ $id ] = $font;
    183200        $fonts[ $id ]['v'] = array_flip( $fonts[ $id ]['v'] );
    184201    }
  • olympus-google-fonts/tags/3.9.5/includes/gutenberg/class-ogf-gutenberg-filters.php

    r3320024 r3323421  
    3636        }
    3737
    38         $fonts = new OGF_Fonts();
     38        $fonts = OGF_Fonts::get_instance();
    3939        $fonts = $fonts->choices;
    4040
  • olympus-google-fonts/tags/3.9.5/includes/gutenberg/output-css.php

    r3254070 r3323421  
    1212 */
    1313function ogf_gutenberg_enqueue_fonts() {
    14     $fonts = new OGF_Fonts();
     14    $fonts = OGF_Fonts::get_instance();
    1515
    1616    if ( $fonts->has_google_fonts() ) {
     
    2828    global $current_screen;
    2929    $current_screen = get_current_screen();
    30     if ( ! method_exists( $current_screen, 'is_block_editor' ) || ! $current_screen->is_block_editor() ) {
    31             return;
     30    if ( ! $current_screen || ! method_exists( $current_screen, 'is_block_editor' ) || ! $current_screen->is_block_editor() ) {
     31        return;
    3232    }
    3333    ?>
  • olympus-google-fonts/tags/3.9.5/olympus-google-fonts.php

    r3320024 r3323421  
    66 * Plugin URI:  https://wordpress.org/plugins/olympus-google-fonts/
    77 * Description: The easiest to customize fonts in WordPress. Optimized for Speed. 1000+ font choices. Supports Google Fonts, Adobe Fonts and Upload Fonts.
    8  * Version:     3.9.4
     8 * Version:     3.9.5
    99 * Author:      Fonts Plugin
    1010 * Author URI:  https://fontsplugin.com/?utm_source=wporg&utm_medium=readme&utm_campaign=description
  • olympus-google-fonts/tags/3.9.5/readme.txt

    r3320024 r3323421  
    66Tested up to: 6.8
    77License: GPLv2 or later
    8 Stable tag: 3.9.4
     8Stable tag: 3.9.5
    99
    1010The easiest to customize fonts in WordPress. Optimized for Speed. 1000+ font choices. Supports Google Fonts, Adobe Fonts and Upload Fonts.
  • olympus-google-fonts/trunk/admin/class-ogf-upload-fonts-screen.php

    r3100693 r3323421  
    9797            $parent_file = $this->parent_menu_slug; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
    9898        }
    99         if ( get_current_screen()->id != 'edit-' . OGF_Fonts_Taxonomy::$taxonomy_slug ) {
     99        $screen = get_current_screen();
     100        if ( ! $screen || $screen->id != 'edit-' . OGF_Fonts_Taxonomy::$taxonomy_slug ) {
    100101            return;
    101102        }
     
    118119    public function manage_columns( $columns ) {
    119120        $screen = get_current_screen();
     121        if ( ! $screen || $screen->id != 'edit-' . OGF_Fonts_Taxonomy::$taxonomy_slug ) {
     122            return;
     123        }
    120124        // If current screen is add new custom fonts screen.
    121125        if ( isset( $screen->base ) && 'edit-tags' == $screen->base ) {
     
    417421
    418422    /**
     423     * Get the correct MIME type for a font file extension.
     424     *
     425     * @param string $extension The file extension.
     426     * @return string The MIME type.
     427     */
     428    private function get_font_mime_type( $extension ) {
     429        switch ( $extension ) {
     430            case 'ttf':
     431                $php_7_ttf_mime_type = PHP_VERSION_ID >= 70300 ? 'application/font-sfnt' : 'application/x-font-ttf';
     432                return PHP_VERSION_ID >= 70400 ? 'font/sfnt' : $php_7_ttf_mime_type;
     433
     434            case 'otf':
     435                return 'application/vnd.ms-opentype';
     436
     437            case 'woff':
     438                return PHP_VERSION_ID >= 80112 ? 'font/woff' : 'application/font-woff';
     439
     440            case 'woff2':
     441                return PHP_VERSION_ID >= 80112 ? 'font/woff2' : 'application/font-woff2';
     442
     443            default:
     444                return '';
     445        }
     446    }
     447
     448    /**
    419449     * Add WOFF and WOFF2 to the allowed mime types.
    420450     *
     
    423453     */
    424454    public function add_to_allowed_mimes( $mimes ) {
    425 
    426         $php_7_ttf_mime_type = PHP_VERSION_ID >= 70300 ? 'application/font-sfnt' : 'application/x-font-ttf';
    427 
    428         $mimes['otf']   = 'application/vnd.ms-opentype';
    429         $mimes['ttf']   = PHP_VERSION_ID >= 70400 ? 'font/sfnt' : $php_7_ttf_mime_type;
    430         $mimes['woff']  = PHP_VERSION_ID >= 80112 ? 'font/woff' : 'application/font-woff';
    431         $mimes['woff2'] = PHP_VERSION_ID >= 80112 ? 'font/woff2' : 'application/font-woff2';
     455        $mimes['otf']   = $this->get_font_mime_type( 'otf' );
     456        $mimes['ttf']   = $this->get_font_mime_type( 'ttf' );
     457        $mimes['woff']  = $this->get_font_mime_type( 'woff' );
     458        $mimes['woff2'] = $this->get_font_mime_type( 'woff2' );
    432459
    433460        return $mimes;
     
    445472     */
    446473    public function update_mime_types( $defaults, $file, $filename ) {
    447         if ( 'ttf' === pathinfo( $filename, PATHINFO_EXTENSION ) ) {
    448             $defaults['type'] = 'application/x-font-ttf';
    449             $defaults['ext']  = 'ttf';
    450         }
    451 
    452         if ( 'otf' === pathinfo( $filename, PATHINFO_EXTENSION ) ) {
    453             $defaults['type'] = 'application/x-font-otf';
    454             $defaults['ext']  = 'otf';
     474        $extension = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );
     475
     476        // Get the MIME type using the same logic as add_to_allowed_mimes().
     477        $mime_type = $this->get_font_mime_type( $extension );
     478
     479        if ( ! empty( $mime_type ) ) {
     480            $defaults['type'] = $mime_type;
     481            $defaults['ext']  = $extension;
    455482        }
    456483
  • olympus-google-fonts/trunk/assets/js/uploadFonts.js

    r3100693 r3323421  
    5151                file_frame.open();
    5252            });
    53             var file_frame;
    54             window.inputWrapper = '';
    5553        },
    5654    }
  • olympus-google-fonts/trunk/blocks/src/google-fonts/edit.js

    r3221683 r3323421  
    276276            },
    277277            {
    278                 value: '500',
     278                value: '600',
    279279                label: __('Semi Bold', 'olympus-google-fonts' ),
    280280            },
  • olympus-google-fonts/trunk/changelog.txt

    r3320024 r3323421  
     1  = 3.9.5 =
     2 
     3  * Fix error when use Blubrry podcast plugin
     4  * Fix null reference errors when get_current_screen() returns null
     5  * Fix memory leak by implementing singleton pattern for font loading with backward compatibility
     6  * Fix PHP 8.0+ compatibility by replacing str_starts_with() with strpos()
     7  * Fix inconsistent MIME type handling for font file uploads
     8
    19= 3.9.4 =
    210
  • olympus-google-fonts/trunk/class-olympus-google-fonts.php

    r3320024 r3323421  
    3939    public function constants() {
    4040        if ( ! defined( 'OGF_VERSION' ) ) {
    41             define( 'OGF_VERSION', '3.9.4' );
     41            define( 'OGF_VERSION', '3.9.5' );
    4242        }
    4343
     
    134134     */
    135135    public function enqueue() {
    136         $fonts = new OGF_Fonts();
     136        $fonts = OGF_Fonts::get_instance();
    137137
    138138        if ( ! $fonts->has_google_fonts() ) {
     
    165165        }
    166166
    167         $fonts = new OGF_Fonts();
     167        $fonts = OGF_Fonts::get_instance();
    168168
    169169        // If no Google Fonts are being used we don't need this.
  • olympus-google-fonts/trunk/includes/class-ogf-classic-editor.php

    r3243818 r3323421  
    5050            }
    5151
    52             $this->ogf_fonts     = new OGF_Fonts();
     52            $this->ogf_fonts     = OGF_Fonts::get_instance();
    5353            $this->system_fonts  = ogf_system_fonts();
    5454            $this->custom_fonts  = ogf_custom_fonts();
  • olympus-google-fonts/trunk/includes/class-ogf-clear-cache.php

    r3100693 r3323421  
    9090         */
    9191        public function clear() {
    92             $fonts = new OGF_Fonts();
     92            $fonts = OGF_Fonts::get_instance();
    9393
    9494            if ( $fonts->has_google_fonts() ) {
  • olympus-google-fonts/trunk/includes/class-ogf-fonts.php

    r3100693 r3323421  
    2727
    2828    /**
    29      * Let's get started.
     29     * Single instance of the class.
     30     *
     31     * @var OGF_Fonts|null
     32     */
     33    private static $instance = null;
     34
     35    /**
     36     * Get the singleton instance.
     37     *
     38     * @return OGF_Fonts
     39     */
     40    public static function get_instance() {
     41        if ( null === self::$instance ) {
     42            self::$instance = new self();
     43        }
     44        return self::$instance;
     45    }
     46
     47    /**
     48     * Constructor - made public for backward compatibility.
     49     * External plugins/code can still use 'new OGF_Fonts()'.
    3050     */
    3151    public function __construct() {
    32         self::$google_fonts = ogf_fonts_array();
     52        // If this is not the singleton instance, just initialize normally for backward compatibility.
     53        if ( null !== self::$instance && self::$instance !== $this ) {
     54            // This is a separate instance for backward compatibility.
     55            $this->initialize();
     56            return;
     57        }
     58
     59        // This is the singleton instance.
     60        $this->initialize();
     61    }
     62
     63    /**
     64     * Initialize the font data and choices.
     65     */
     66    private function initialize() {
     67        // Only load fonts array if not already loaded.
     68        if ( empty( self::$google_fonts ) ) {
     69            self::$google_fonts = ogf_fonts_array();
     70        }
    3371        $this->get_choices();
     72    }
     73
     74    /**
     75     * Prevent cloning of the instance.
     76     */
     77    private function __clone() {}
     78
     79    /**
     80     * Prevent unserialization of the instance.
     81     *
     82     * @throws Exception When attempting to unserialize.
     83     */
     84    public function __wakeup() {
     85        throw new Exception( 'Cannot unserialize singleton' );
    3486    }
    3587
     
    78130     */
    79131    public function get_font_weights( $font_id ) {
     132        // Check if font exists in the array.
     133        if ( ! array_key_exists( $font_id, self::$google_fonts ) ) {
     134            return array();
     135        }
     136
     137        // Check if the font has variants data.
     138        if ( ! isset( self::$google_fonts[ $font_id ]['v'] ) ) {
     139            return array();
     140        }
     141
    80142        $weights = self::$google_fonts[ $font_id ]['v'];
    81143
     
    95157     */
    96158    public function get_font_subsets( $font_id ) {
     159        // Check if font exists in the array.
     160        if ( ! array_key_exists( $font_id, self::$google_fonts ) ) {
     161            return array();
     162        }
     163
     164        // Check if the font has subsets data.
     165        if ( ! isset( self::$google_fonts[ $font_id ]['s'] ) ) {
     166            return array();
     167        }
     168
    97169        $subsets = self::$google_fonts[ $font_id ]['s'];
    98170
     
    113185     */
    114186    public function get_font_name( $font_id ) {
    115         if ( array_key_exists( $font_id, self::$google_fonts ) ) {
     187        if ( array_key_exists( $font_id, self::$google_fonts ) && isset( self::$google_fonts[ $font_id ]['f'] ) ) {
    116188            return self::$google_fonts[ $font_id ]['f'];
    117189        } else {
     
    203275        if ( false === ( $external_font_css ) ) {
    204276            // It wasn't there, so regenerate the data and save the transient.
    205             $external_font_css  = '/* Cached: ' . date( 'F j, Y \a\t g:ia' ) . ' */' . PHP_EOL;
     277            $external_font_css  = '/* Cached: ' . gmdate( 'F j, Y \a\t g:ia' ) . ' */' . PHP_EOL;
    206278            $external_font_css .= $this->get_remote_url_contents( $url ) . PHP_EOL;
    207279            set_transient( 'ogf_external_font_css_' . $url_to_id, $external_font_css, DAY_IN_SECONDS );
  • olympus-google-fonts/trunk/includes/class-ogf-typekit.php

    r3128267 r3323421  
    138138     */
    139139    public function css_styles() {
    140         if ( get_current_screen()->id !== 'fonts-plugin_page_fonts-plugin-typekit' ) {
     140        $screen = get_current_screen();
     141        if ( ! $screen || $screen->id !== 'fonts-plugin_page_fonts-plugin-typekit' ) {
    141142            return;
    142143        }
     
    159160
    160161        // Only perform action on the Fonts Plugin Typekit Page.
    161         if ( get_current_screen()->id !== 'fonts-plugin_page_fonts-plugin-typekit' ) {
     162        $screen = get_current_screen();
     163        if ( ! $screen || $screen->id !== 'fonts-plugin_page_fonts-plugin-typekit' ) {
    162164            return;
    163165        }
     
    231233    public function manage_kits() {
    232234        // Only perform action on the Fonts Plugin Typekit Page.
    233         if ( get_current_screen()->id !== 'fonts-plugin_page_fonts-plugin-typekit' ) {
     235        $screen = get_current_screen();
     236        if ( ! $screen || $screen->id !== 'fonts-plugin_page_fonts-plugin-typekit' ) {
    234237            return;
    235238        }
  • olympus-google-fonts/trunk/includes/customizer/output-css.php

    r3254070 r3323421  
    208208    $cache_key    = 'ogf_font_stack_' . md5( $font_id );
    209209    $cached_stack = wp_cache_get( $cache_key );
    210    
    211210    if ( $cached_stack !== false ) {
    212211        return $cached_stack;
     
    216215    $stack = '';
    217216
    218     if ( str_starts_with( $font_id, 'sf-' ) !== false ) {
     217    if ( 0 === strpos( $font_id, 'sf-' ) ) {
    219218        $system_fonts = ogf_system_fonts();
    220219        $font_id      = str_replace( 'sf-', '', $font_id );
     
    223222            $stack = $system_fonts[ $font_id ]['stack'];
    224223        }
    225     } elseif ( str_starts_with( $font_id, 'cf-' ) !== false ) {
     224    } elseif ( 0 === strpos( $font_id, 'cf-' ) ) {
    226225        $custom_fonts = ogf_custom_fonts();
    227226        $font_id      = str_replace( 'cf-', '', $font_id );
     
    235234            $stack = '"' . $font . '"';
    236235        }
    237     } elseif ( str_starts_with( $font_id, 'tk-' ) !== false ) {
     236    } elseif ( 0 === strpos( $font_id, 'tk-' ) ) {
    238237        $typekit_fonts = ogf_typekit_fonts();
    239238
     
    250249
    251250    // Cache the result.
    252     wp_cache_set( $cache_key, $stack, 'ogf_font_stacks', HOUR_IN_SECONDS );
    253    
     251    wp_cache_set( $cache_key, $stack, 'ogf_font_stacks', HOUR_IN_SECONDS );
    254252    // Allow filtering of the final stack.
    255253    return apply_filters( "ogf_{$font_id}_stack", $stack );
  • olympus-google-fonts/trunk/includes/customizer/settings.php

    r3100693 r3323421  
    298298    );
    299299
    300     $fonts   = new OGF_Fonts();
     300            $fonts   = OGF_Fonts::get_instance();
    301301    $subsets = array();
    302302
  • olympus-google-fonts/trunk/includes/functions.php

    r3254070 r3323421  
    156156
    157157/**
     158 * Get the OGF_Fonts singleton instance.
     159 *
     160 * @return OGF_Fonts The singleton instance.
     161 */
     162function ogf_get_fonts_instance() {
     163    return OGF_Fonts::get_instance();
     164}
     165
     166
     167
     168/**
    158169 * Return an array of all available Google Fonts.
    159170 *
     
    167178    }
    168179
    169     $fonts_json = file_get_contents( OGF_DIR_PATH . '/blocks/src/google-fonts/fonts.json' );
    170 
    171     // Change the object to a multidimensional array.
     180    $fonts_file = OGF_DIR_PATH . '/blocks/src/google-fonts/fonts.json';
     181
     182    if ( ! file_exists( $fonts_file ) ) {
     183        return array();
     184    }
     185
     186    $fonts_json = file_get_contents( $fonts_file );
     187    if ( false === $fonts_json ) {
     188        return array();
     189    }
     190
    172191    $fonts_array = json_decode( $fonts_json, true );
    173 
    174     // Format the variants array for easier use.
    175     foreach ( $fonts_array as $key => $font ) {
    176         $fonts_array[ $key ] = $font;
    177     }
    178 
    179     // Change the array key to the font's ID.
     192    if ( null === $fonts_array ) {
     193        return array();
     194    }
     195
     196    // Existing processing logic...
    180197    foreach ( $fonts_array as $font ) {
    181         $id                = trim( strtolower( str_replace( ' ', '-', $font['f'] ) ) );
    182         $fonts[ $id ]      = $font;
     198        $id = trim( strtolower( str_replace( ' ', '-', $font['f'] ) ) );
     199        $fonts[ $id ] = $font;
    183200        $fonts[ $id ]['v'] = array_flip( $fonts[ $id ]['v'] );
    184201    }
  • olympus-google-fonts/trunk/includes/gutenberg/class-ogf-gutenberg-filters.php

    r3320024 r3323421  
    3636        }
    3737
    38         $fonts = new OGF_Fonts();
     38        $fonts = OGF_Fonts::get_instance();
    3939        $fonts = $fonts->choices;
    4040
  • olympus-google-fonts/trunk/includes/gutenberg/output-css.php

    r3254070 r3323421  
    1212 */
    1313function ogf_gutenberg_enqueue_fonts() {
    14     $fonts = new OGF_Fonts();
     14    $fonts = OGF_Fonts::get_instance();
    1515
    1616    if ( $fonts->has_google_fonts() ) {
     
    2828    global $current_screen;
    2929    $current_screen = get_current_screen();
    30     if ( ! method_exists( $current_screen, 'is_block_editor' ) || ! $current_screen->is_block_editor() ) {
    31             return;
     30    if ( ! $current_screen || ! method_exists( $current_screen, 'is_block_editor' ) || ! $current_screen->is_block_editor() ) {
     31        return;
    3232    }
    3333    ?>
  • olympus-google-fonts/trunk/olympus-google-fonts.php

    r3320024 r3323421  
    66 * Plugin URI:  https://wordpress.org/plugins/olympus-google-fonts/
    77 * Description: The easiest to customize fonts in WordPress. Optimized for Speed. 1000+ font choices. Supports Google Fonts, Adobe Fonts and Upload Fonts.
    8  * Version:     3.9.4
     8 * Version:     3.9.5
    99 * Author:      Fonts Plugin
    1010 * Author URI:  https://fontsplugin.com/?utm_source=wporg&utm_medium=readme&utm_campaign=description
  • olympus-google-fonts/trunk/readme.txt

    r3320024 r3323421  
    66Tested up to: 6.8
    77License: GPLv2 or later
    8 Stable tag: 3.9.4
     8Stable tag: 3.9.5
    99
    1010The easiest to customize fonts in WordPress. Optimized for Speed. 1000+ font choices. Supports Google Fonts, Adobe Fonts and Upload Fonts.
Note: See TracChangeset for help on using the changeset viewer.