Warning: Array to string conversion in /mnt/data/home/502433.cloudwaysapps.com/rhbymdevka/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 808
Warning: foreach() argument must be of type array|object, string given in /mnt/data/home/502433.cloudwaysapps.com/rhbymdevka/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 813
Warning: Array to string conversion in /mnt/data/home/502433.cloudwaysapps.com/rhbymdevka/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 808
PUM_Integration_GoogleFonts::fetch_fonts( string $sort = 'alpha' )
Fetch list of Google Fonts or fallback to local list.
Description Description
Warning: Array to string conversion in /mnt/data/home/502433.cloudwaysapps.com/rhbymdevka/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 808
Warning: foreach() argument must be of type array|object, string given in /mnt/data/home/502433.cloudwaysapps.com/rhbymdevka/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 813
Warning: Array to string conversion in /mnt/data/home/502433.cloudwaysapps.com/rhbymdevka/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 808
Parameters Parameters
- $sort
-
(Optional)
Default value: 'alpha'
Return Return
(array|mixed)
Source Source
File: classes/Integration/GoogleFonts.php
public static function fetch_fonts( $sort = 'alpha' ) { if ( false !== $font_list = get_site_transient( 'pum_google_fonts_list' ) ) { return $font_list; } $google_api_url = 'https://www.googleapis.com/webfonts/v1/webfonts?key=' . self::$api_key . '&sort=' . $sort; $response = wp_remote_retrieve_body( wp_remote_get( $google_api_url, array( 'sslverify' => false ) ) ); if ( ! is_wp_error( $response ) ) { $data = json_decode( $response, true ); } // Store transient for a long time after fetching from Google to save API key hits. $transient_time = self::$api_key == self::$default_api_key ? 8 * WEEK_IN_SECONDS : 1 * WEEK_IN_SECONDS; if ( ! empty( $data['errors'] ) || empty( $data['items'] ) ) { $data = self::load_backup_fonts(); // Store transient for short period. $transient_time = 1 * DAY_IN_SECONDS; } $items = $data['items']; $font_list = array(); if ( count( $items ) ) { foreach ( $items as $item ) { $font_list[ $item['family'] ] = $item; } } set_site_transient( 'pum_google_fonts_list', $font_list, $transient_time ); return $font_list; }
Expand full source code Collapse full source code View on Trac