Google Fonts for WordPress - Version 2.5.1

Version Description

Download this release

Release Info

Developer DannyCooper
Plugin Icon 128x128 Google Fonts for WordPress
Version 2.5.1
Comparing to
See all releases

Code changes from version 2.5.0 to 2.5.1

changelog.txt CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  = 2.5.0 =
2
 
3
  * Add support for Adobe Fonts / Typekit
1
+ = 2.5.1 =
2
+
3
+ * Hotfix for API error
4
+
5
  = 2.5.0 =
6
 
7
  * Add support for Adobe Fonts / Typekit
includes/class-ogf-typekit.php CHANGED
@@ -28,8 +28,8 @@ class OGF_Typekit {
28
  public function add_settings_page() {
29
  add_submenu_page(
30
  'fonts-plugin',
31
- __( 'Adobe Fonts (Typekit)', 'olympus-google-fonts' ),
32
- __( 'Adobe Fonts (Typekit)', 'olympus-google-fonts' ),
33
  'manage_options',
34
  'fonts-plugin-typekit',
35
  array( $this, 'render_settings_page' ),
@@ -76,8 +76,12 @@ class OGF_Typekit {
76
  * Render the Typekit settings.
77
  */
78
  public function render_settings() {
79
- $settings = (array) get_option( 'fp-typekit' );
80
- $value = $settings['api_key'];
 
 
 
 
81
 
82
  echo '<input type="text" name="fp-typekit[api_key]" value="' . esc_attr( $value ) . '" />';
83
  echo '<input name="submit" class="button button-primary" type="submit" value="' . esc_attr__( 'Save', 'olympus-google-fonts' ) . '" />';
@@ -90,6 +94,11 @@ class OGF_Typekit {
90
  echo '<p>' . esc_html__( 'The following data was retrieved from the Typekit API:', 'olympus-google-fonts' ) . '</p>';
91
  echo '<ul class="fp-typekit-results">';
92
  $kits = get_option( 'fp-typekit-data' );
 
 
 
 
 
93
  foreach ( $kits as $id => $kit ) {
94
  echo '<li><strong>' . esc_html__( 'Kit: ', 'olympus-google-fonts' ) . '</strong>' . esc_attr( $id ) . '</li><ul>';
95
  foreach ( $kit['families'] as $family ) {
@@ -127,11 +136,21 @@ class OGF_Typekit {
127
  return;
128
  }
129
 
130
- $settings = get_option( 'fp-typekit', false );
131
- $api_key = $settings['api_key'];
132
- $url = 'https://typekit.com/api/v1/json/kits/';
133
- $curl_args = array();
134
- $response = wp_remote_request( $url . '?token=' . esc_attr( $api_key ), $curl_args );
 
 
 
 
 
 
 
 
 
 
135
  $response_body = json_decode( wp_remote_retrieve_body( $response ) );
136
  $kits = array();
137
 
@@ -140,16 +159,19 @@ class OGF_Typekit {
140
  foreach ( $response_body->kits as $kit ) {
141
  // perform an API request for the individual kit.
142
  $data = $this->get_kit_from_api( $api_key, $kit->id );
143
- // Enable kits by default.
144
- $kits[ $kit->id ]['enabled'] = true;
145
- // loop through the kit and standardize the data.
146
- foreach ( $data->families as $family ) {
147
- $kits[ $kit->id ]['families'][] = array(
148
- 'label' => $family->name,
149
- 'id' => $family->slug,
150
- 'variants' => array_map( array( $this, 'standardize_variant_names' ), $family->variations ),
151
- 'stack' => $family->css_stack,
152
- );
 
 
 
153
  }
154
  }
155
  }
@@ -167,8 +189,13 @@ class OGF_Typekit {
167
  $url = 'https://typekit.com/api/v1/json/kits/' . esc_attr( $kit_id ) . '?token=' . esc_attr( $api_key );
168
  $curl_args = array();
169
  $response = wp_remote_request( $url, $curl_args );
170
- $response_body = json_decode( wp_remote_retrieve_body( $response ) );
171
- return $response_body->kit;
 
 
 
 
 
172
  }
173
 
174
  /**
@@ -210,7 +237,12 @@ class OGF_Typekit {
210
  */
211
  public static function get_fonts() {
212
  $fonts = array();
213
- $kits = get_option( 'fp-typekit-data' );
 
 
 
 
 
214
  foreach ( $kits as $kit ) {
215
  foreach ( $kit['families'] as $family ) {
216
  $fonts[ 'tk-' . $family['id'] ] = array(
@@ -228,10 +260,13 @@ class OGF_Typekit {
228
  * Enqueue typekit CSS files.
229
  */
230
  public function enqueue_css() {
231
- $typekit_data = get_option( 'fp-typekit-data' );
 
 
232
 
233
- foreach ( $typekit_data as $id => $values ) {
234
- wp_enqueue_style( 'typekit-' . $id, 'https://use.typekit.com/' . $id . '.css', array(), OGF_VERSION );
 
235
  }
236
  }
237
 
28
  public function add_settings_page() {
29
  add_submenu_page(
30
  'fonts-plugin',
31
+ __( 'Adobe Fonts', 'olympus-google-fonts' ),
32
+ __( 'Adobe Fonts', 'olympus-google-fonts' ),
33
  'manage_options',
34
  'fonts-plugin-typekit',
35
  array( $this, 'render_settings_page' ),
76
  * Render the Typekit settings.
77
  */
78
  public function render_settings() {
79
+ $settings = get_option( 'fp-typekit', array() );
80
+ $value = '';
81
+
82
+ if ( array_key_exists( 'api_key', $settings ) ) {
83
+ $value = $settings['api_key'];
84
+ }
85
 
86
  echo '<input type="text" name="fp-typekit[api_key]" value="' . esc_attr( $value ) . '" />';
87
  echo '<input name="submit" class="button button-primary" type="submit" value="' . esc_attr__( 'Save', 'olympus-google-fonts' ) . '" />';
94
  echo '<p>' . esc_html__( 'The following data was retrieved from the Typekit API:', 'olympus-google-fonts' ) . '</p>';
95
  echo '<ul class="fp-typekit-results">';
96
  $kits = get_option( 'fp-typekit-data' );
97
+
98
+ if ( ! is_array( $kits ) ) {
99
+ return;
100
+ }
101
+
102
  foreach ( $kits as $id => $kit ) {
103
  echo '<li><strong>' . esc_html__( 'Kit: ', 'olympus-google-fonts' ) . '</strong>' . esc_attr( $id ) . '</li><ul>';
104
  foreach ( $kit['families'] as $family ) {
136
  return;
137
  }
138
 
139
+ $settings = get_option( 'fp-typekit', array() );
140
+
141
+ if ( ! array_key_exists( 'api_key', $settings ) ) {
142
+ return;
143
+ }
144
+
145
+ $api_key = $settings['api_key'];
146
+ $url = 'https://typekit.com/api/v1/json/kits/';
147
+ $curl_args = array();
148
+ $response = wp_remote_request( $url . '?token=' . esc_attr( $api_key ), $curl_args );
149
+
150
+ if ( wp_remote_retrieve_response_code( $response ) != '200' ) {
151
+ return;
152
+ }
153
+
154
  $response_body = json_decode( wp_remote_retrieve_body( $response ) );
155
  $kits = array();
156
 
159
  foreach ( $response_body->kits as $kit ) {
160
  // perform an API request for the individual kit.
161
  $data = $this->get_kit_from_api( $api_key, $kit->id );
162
+
163
+ if ( $data ) {
164
+ // Enable kits by default.
165
+ $kits[ $kit->id ]['enabled'] = true;
166
+ // loop through the kit and standardize the data.
167
+ foreach ( $data->families as $family ) {
168
+ $kits[ $kit->id ]['families'][] = array(
169
+ 'label' => $family->name,
170
+ 'id' => $family->slug,
171
+ 'variants' => array_map( array( $this, 'standardize_variant_names' ), $family->variations ),
172
+ 'stack' => $family->css_stack,
173
+ );
174
+ }
175
  }
176
  }
177
  }
189
  $url = 'https://typekit.com/api/v1/json/kits/' . esc_attr( $kit_id ) . '?token=' . esc_attr( $api_key );
190
  $curl_args = array();
191
  $response = wp_remote_request( $url, $curl_args );
192
+
193
+ if ( wp_remote_retrieve_response_code( $response ) == '200' ) {
194
+ $response_body = json_decode( wp_remote_retrieve_body( $response ) );
195
+ return $response_body->kit;
196
+ }
197
+
198
+ return false;
199
  }
200
 
201
  /**
237
  */
238
  public static function get_fonts() {
239
  $fonts = array();
240
+ $kits = get_option( 'fp-typekit-data', array() );
241
+
242
+ if ( ! is_array( $kits ) ) {
243
+ return $fonts;
244
+ }
245
+
246
  foreach ( $kits as $kit ) {
247
  foreach ( $kit['families'] as $family ) {
248
  $fonts[ 'tk-' . $family['id'] ] = array(
260
  * Enqueue typekit CSS files.
261
  */
262
  public function enqueue_css() {
263
+ $typekit_data = get_option( 'fp-typekit-data', array() );
264
+
265
+ if ( is_array( $typekit_data ) ) {
266
 
267
+ foreach ( $typekit_data as $id => $values ) {
268
+ wp_enqueue_style( 'typekit-' . $id, 'https://use.typekit.com/' . $id . '.css', array(), OGF_VERSION );
269
+ }
270
  }
271
  }
272
 
olympus-google-fonts.php CHANGED
@@ -5,7 +5,7 @@
5
  * Plugin Name: Fonts Plugin | Google Fonts Typography
6
  * Plugin URI: https://wordpress.org/plugins/olympus-google-fonts/
7
  * Description: The easiest to use Google Fonts typography plugin. No coding required. 900+ font choices.
8
- * Version: 2.5.0
9
  * Author: Fonts Plugin
10
  * Author URI: https://fontsplugin.com/?utm_source=wporg&utm_medium=readme&utm_campaign=description
11
  * Text Domain: olympus-google-fonts
@@ -19,7 +19,7 @@
19
  */
20
 
21
  if ( ! defined( 'OGF_VERSION' ) ) {
22
- define( 'OGF_VERSION', '2.5.0' );
23
  }
24
 
25
  if ( ! defined( 'OGF_DIR_PATH' ) ) {
5
  * Plugin Name: Fonts Plugin | Google Fonts Typography
6
  * Plugin URI: https://wordpress.org/plugins/olympus-google-fonts/
7
  * Description: The easiest to use Google Fonts typography plugin. No coding required. 900+ font choices.
8
+ * Version: 2.5.1
9
  * Author: Fonts Plugin
10
  * Author URI: https://fontsplugin.com/?utm_source=wporg&utm_medium=readme&utm_campaign=description
11
  * Text Domain: olympus-google-fonts
19
  */
20
 
21
  if ( ! defined( 'OGF_VERSION' ) ) {
22
+ define( 'OGF_VERSION', '2.5.1' );
23
  }
24
 
25
  if ( ! defined( 'OGF_DIR_PATH' ) ) {
readme.txt CHANGED
@@ -5,7 +5,7 @@ Donate link: https://fontsplugin.com/#pricing
5
  Requires at least: 4.0
6
  Tested up to: 5.6
7
  License: GPLv2 or later
8
- Stable tag: 2.5.0
9
 
10
  The easiest to use Google Fonts Typography Plugin. No coding required. 900+ font choices.
11
 
5
  Requires at least: 4.0
6
  Tested up to: 5.6
7
  License: GPLv2 or later
8
+ Stable tag: 2.5.1
9
 
10
  The easiest to use Google Fonts Typography Plugin. No coding required. 900+ font choices.
11