['family' => 'Family Name', 'variants' => [...]]] */ public static function fetch_fonts( $sort = 'alpha' ) { // Return cached fonts if already loaded. if ( null !== self::$font_cache ) { return self::$font_cache; } // Load fonts from optimized JSON file. $json_file = Popup_Maker::$DIR . 'includes/google-fonts.json'; if ( ! file_exists( $json_file ) ) { self::$font_cache = []; return self::$font_cache; } $json_data = file_get_contents( $json_file ); $font_list = json_decode( $json_data, true ); // Cache the result for this request. self::$font_cache = is_array( $font_list ) ? $font_list : []; return self::$font_cache; } /** * Adds options to the font family dropdowns. * * @param $options * * @return array */ public static function font_family_options( $options ) { // If Google Fonts are disabled, return early preventing font loading. if ( pum_get_option( 'disable_google_font_loading', false ) ) { return $options; } $font_list = self::fetch_fonts(); if ( empty( $font_list ) ) { return $options; } $new_options = []; // $options = array_merge( $options, array( // '' => __( 'Google Web Fonts', 'popup-maker' ) . ' ⤵', // ) ); foreach ( $font_list as $font_family => $font ) { $new_options[ $font_family ] = $font_family; } $options[ __( 'Google Web Fonts', 'popup-maker' ) ] = $new_options; return $options; } }