Advanced Custom Fields: Font Awesome Field - Version 3.0.0-beta2

Version Description

  • Adding support for FontAwesome Pro icons
Download this release

Release Info

Developer mattkeys
Plugin Icon 128x128 Advanced Custom Fields: Font Awesome Field
Version 3.0.0-beta2
Comparing to
See all releases

Code changes from version 3.0.0-beta1 to 3.0.0-beta2

acf-font-awesome.php CHANGED
@@ -4,7 +4,7 @@
4
  Plugin Name: Advanced Custom Fields: Font Awesome
5
  Plugin URI: https://wordpress.org/plugins/advanced-custom-fields-font-awesome/
6
  Description: Adds a new 'Font Awesome Icon' field to the popular Advanced Custom Fields plugin.
7
- Version: 3.0.0-beta1
8
  Author: mattkeys
9
  Author URI: http://mattkeys.me/
10
  License: GPLv2 or later
@@ -37,7 +37,7 @@ if ( ! class_exists('acf_plugin_font_awesome') ) :
37
  public function __construct()
38
  {
39
  $this->settings = array(
40
- 'version' => '3.0.0-beta1',
41
  'url' => plugin_dir_url( __FILE__ ),
42
  'path' => plugin_dir_path( __FILE__ )
43
  );
4
  Plugin Name: Advanced Custom Fields: Font Awesome
5
  Plugin URI: https://wordpress.org/plugins/advanced-custom-fields-font-awesome/
6
  Description: Adds a new 'Font Awesome Icon' field to the popular Advanced Custom Fields plugin.
7
+ Version: 3.0.0-beta2
8
  Author: mattkeys
9
  Author URI: http://mattkeys.me/
10
  License: GPLv2 or later
37
  public function __construct()
38
  {
39
  $this->settings = array(
40
+ 'version' => '3.0.0-beta2',
41
  'url' => plugin_dir_url( __FILE__ ),
42
  'path' => plugin_dir_path( __FILE__ )
43
  );
admin/class-ACFFA-Admin.php CHANGED
@@ -44,6 +44,7 @@ class ACFFA_Admin
44
  {
45
  if ( isset( $_GET['settings-updated'] ) ) {
46
  add_settings_error( 'acffa_messages', 'acffa_message', __( 'Settings Saved', 'acf-font-awesome' ), 'updated' );
 
47
  }
48
 
49
  settings_errors( 'acffa_messages' );
@@ -81,8 +82,20 @@ class ACFFA_Admin
81
  'acffa',
82
  'acffa_section_developers',
83
  array(
84
- 'label_for' => 'acffa_major_version',
85
- 'class' => 'acffa_row'
 
 
 
 
 
 
 
 
 
 
 
 
86
  )
87
  );
88
  }
@@ -91,7 +104,7 @@ class ACFFA_Admin
91
  {
92
  ?>
93
  <p id="<?php echo esc_attr( $args['id'] ); ?>">
94
- <?php esc_html_e( 'FontAwesome underwent big changes with the release of version 5. It is best to choose a version and stick with it.', 'acf-font-awesome' ); ?><br />
95
  <em><?php _e( 'Any icon selections saved prior to switching versions will need to be re-selected and re-saved after switching.', 'acf-font-awesome' ); ?></em>
96
  </p>
97
  <?php
@@ -109,6 +122,44 @@ class ACFFA_Admin
109
  <?php esc_html_e( '5.x', 'acf-font-awesome' ); ?>
110
  </option>
111
  </select>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  <?php
113
  }
114
 
44
  {
45
  if ( isset( $_GET['settings-updated'] ) ) {
46
  add_settings_error( 'acffa_messages', 'acffa_message', __( 'Settings Saved', 'acf-font-awesome' ), 'updated' );
47
+ do_action( 'ACFFA_refresh_latest_icons' );
48
  }
49
 
50
  settings_errors( 'acffa_messages' );
82
  'acffa',
83
  'acffa_section_developers',
84
  array(
85
+ 'label_for' => 'acffa_major_version',
86
+ 'class' => 'acffa_row'
87
+ )
88
+ );
89
+
90
+ add_settings_field(
91
+ 'acffa_pro_cdn',
92
+ __( 'Enable Pro Icons?', 'acf-font-awesome' ),
93
+ array( $this, 'acffa_pro_cdn_cb' ),
94
+ 'acffa',
95
+ 'acffa_section_developers',
96
+ array(
97
+ 'label_for' => 'acffa_pro_cdn',
98
+ 'class' => 'acffa_row pro_icons'
99
  )
100
  );
101
  }
104
  {
105
  ?>
106
  <p id="<?php echo esc_attr( $args['id'] ); ?>">
107
+ <?php esc_html_e( 'FontAwesome underwent big changes with the release of version 5. It is best to choose a version and stick with it.', 'acf-font-awesome' ); ?><br>
108
  <em><?php _e( 'Any icon selections saved prior to switching versions will need to be re-selected and re-saved after switching.', 'acf-font-awesome' ); ?></em>
109
  </p>
110
  <?php
122
  <?php esc_html_e( '5.x', 'acf-font-awesome' ); ?>
123
  </option>
124
  </select>
125
+
126
+
127
+ <?php
128
+ }
129
+
130
+ public function acffa_pro_cdn_cb( $args )
131
+ {
132
+ $options = get_option( 'acffa_settings' );
133
+ ?>
134
+ <p id="<?php echo esc_attr( $args['id'] ); ?>">
135
+ <?php _e( 'If you have a FontAwesome Pro license, check the box below to enable the pro icons.', 'acf-font-awesome' ); ?><br>
136
+ <em><?php _e( 'NOTE: You MUST add this domain in your FontAwesome "Pro CDN Domains" in order for this to work!', 'acf-font-awesome' ); ?></em>
137
+ </p>
138
+ <br>
139
+ <p>
140
+ <input type="checkbox" value="1" id="<?php echo esc_attr( $args['label_for'] ); ?>" name="acffa_settings[<?php echo esc_attr( $args['label_for'] ); ?>]" <?php echo isset( $options[ $args[ 'label_for'] ] ) ? ( checked( $options[ $args[ 'label_for'] ] ) ) : ( '' ); ?> />
141
+ <label for="<?php echo esc_attr( $args['label_for'] ); ?>"><?php _e( 'I have enabled this domain for CDN use. Turn on the pro icons!', 'acf-font-awesome' ); ?></label>
142
+ </p>
143
+ <script>
144
+ function evaluate_pro_visibility() {
145
+ var selected_major_version = jQuery('#acffa_major_version').val();
146
+
147
+ if ( 5 == selected_major_version ) {
148
+ jQuery('.acffa_row.pro_icons').show();
149
+ } else {
150
+ jQuery('.acffa_row.pro_icons').hide();
151
+ jQuery('#pro_icons').prop( 'checked', false );
152
+ }
153
+ }
154
+
155
+ jQuery(document).ready( function() {
156
+ evaluate_pro_visibility();
157
+ });
158
+
159
+ jQuery('#acffa_major_version').on( 'change', function() {
160
+ evaluate_pro_visibility();
161
+ });
162
+ </script>
163
  <?php
164
  }
165
 
assets/inc/class-ACFFA-Loader-5.php CHANGED
@@ -15,25 +15,48 @@ if ( ! defined( 'ABSPATH' ) ) {
15
 
16
  class ACFFA_Loader_5
17
  {
18
- public $api_endpoint = 'https://data.jsdelivr.com/v1/package/resolve/gh/FortAwesome/Font-Awesome@5';
19
- public $cdn_baseurl = 'https://cdn.jsdelivr.net/gh/FortAwesome/Font-Awesome@';
20
- public $free_icon_manifest = '/advanced-options/metadata/icons.yml';
21
- public $cdn_filepath = '/web-fonts-with-css/css/fontawesome-all.min.css';
22
- public $override_version = false;
23
- public $current_version = false;
 
 
 
 
 
 
 
 
24
 
25
  public function init()
26
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  $this->api_endpoint = apply_filters( 'ACFFA_api_endpoint', $this->api_endpoint );
28
  $this->cdn_baseurl = apply_filters( 'ACFFA_cdn_baseurl', $this->cdn_baseurl );
 
29
  $this->cdn_filepath = apply_filters( 'ACFFA_cdn_filepath', $this->cdn_filepath );
30
  $this->override_version = apply_filters( 'ACFFA_override_version', false );
31
 
32
  $this->current_version = get_option( 'ACFFA_current_version' );
 
33
 
34
  if ( $this->override_version ) {
35
  $this->current_version = $this->override_version;
36
- } else if ( ! $this->current_version || version_compare( $this->current_version, '5.0.0', '<' ) ) {
37
  $this->current_version = $this->check_latest_version();
38
  }
39
 
@@ -122,7 +145,7 @@ class ACFFA_Loader_5
122
  return;
123
  }
124
 
125
- if ( version_compare( $this->current_version, $latest_version, '<' ) ) {
126
  update_option( 'ACFFA_current_version', $latest_version, false );
127
  $this->current_version = $latest_version;
128
 
@@ -132,7 +155,7 @@ class ACFFA_Loader_5
132
 
133
  private function check_latest_version( $update_option = true )
134
  {
135
- $latest_version = 'latest';
136
 
137
  $remote_get = wp_remote_get( $this->api_endpoint );
138
 
@@ -166,11 +189,10 @@ class ACFFA_Loader_5
166
  {
167
  $fa_icons = get_option( 'ACFFA_icon_data' );
168
 
169
- if ( empty( $fa_icons ) || ! isset( $fa_icons[ $this->current_version ] ) ) {
170
- $request_url = $this->cdn_baseurl . $this->current_version . $this->free_icon_manifest;
171
- $remote_get = wp_remote_get( $request_url );
172
 
173
- if ( ! is_wp_error( $remote_get ) ) {
174
  $response = wp_remote_retrieve_body( $remote_get );
175
 
176
  if ( ! empty( $response ) ) {
@@ -185,10 +207,15 @@ class ACFFA_Loader_5
185
  $this->current_version => $icons
186
  );
187
 
 
 
188
  update_option( 'ACFFA_icon_data', $fa_icons, true );
 
189
  }
190
  }
191
  }
 
 
192
  }
193
  }
194
 
@@ -207,8 +234,8 @@ class ACFFA_Loader_5
207
  private function find_icons( $manifest )
208
  {
209
  $icons = array(
210
- 'list' => array(),
211
- 'details' => array()
212
  );
213
 
214
  foreach ( $manifest as $icon => $details ) {
15
 
16
  class ACFFA_Loader_5
17
  {
18
+ private $api_endpoint = false;
19
+ private $free_api_endpoint = 'https://data.jsdelivr.com/v1/package/resolve/gh/mattkeys/FontAwesome-Free-Manifest@5';
20
+ private $pro_api_endpoint = 'https://data.jsdelivr.com/v1/package/resolve/gh/mattkeys/FontAwesome-Pro-Manifest@5';
21
+ private $cdn_baseurl = false;
22
+ private $free_cdn_baseurl = 'https://use.fontawesome.com/releases/v';
23
+ private $pro_cdn_baseurl = 'https://pro.fontawesome.com/releases/v';
24
+ private $manifest_url = false;
25
+ private $free_manifest_url = 'http://cdn.jsdelivr.net/gh/mattkeys/FontAwesome-Free-Manifest/5.x/manifest.yml';
26
+ private $pro_manifest_url = 'http://cdn.jsdelivr.net/gh/mattkeys/FontAwesome-Pro-Manifest/5.x/manifest.yml';
27
+ private $cdn_filepath = '/css/all.css';
28
+ private $override_version = false;
29
+ private $current_version = false;
30
+ private $pro_icons_enabled = false;
31
+ private $active_icon_set = false;
32
 
33
  public function init()
34
  {
35
+ $acffa_settings = get_option( 'acffa_settings' );
36
+ $this->pro_icons_enabled = isset( $acffa_settings['acffa_pro_cdn'] ) ? true : false;
37
+
38
+ if ( $this->pro_icons_enabled ) {
39
+ $this->api_endpoint = $this->pro_api_endpoint;
40
+ $this->cdn_baseurl = $this->pro_cdn_baseurl;
41
+ $this->manifest_url = $this->pro_manifest_url;
42
+ } else {
43
+ $this->api_endpoint = $this->free_api_endpoint;
44
+ $this->cdn_baseurl = $this->free_cdn_baseurl;
45
+ $this->manifest_url = $this->free_manifest_url;
46
+ }
47
+
48
  $this->api_endpoint = apply_filters( 'ACFFA_api_endpoint', $this->api_endpoint );
49
  $this->cdn_baseurl = apply_filters( 'ACFFA_cdn_baseurl', $this->cdn_baseurl );
50
+ $this->manifest_url = apply_filters( 'ACFFA_manifest_url', $this->manifest_url );
51
  $this->cdn_filepath = apply_filters( 'ACFFA_cdn_filepath', $this->cdn_filepath );
52
  $this->override_version = apply_filters( 'ACFFA_override_version', false );
53
 
54
  $this->current_version = get_option( 'ACFFA_current_version' );
55
+ $this->active_icon_set = get_option( 'ACFFA_active_icon_set' );
56
 
57
  if ( $this->override_version ) {
58
  $this->current_version = $this->override_version;
59
+ } else if ( ! $this->current_version || version_compare( $this->current_version, '5.0.0', '<' ) || ! $this->active_icon_set || ( $this->pro_icons_enabled && 'pro' !== $this->active_icon_set ) || ( ! $this->pro_icons_enabled && 'free' !== $this->active_icon_set ) ) {
60
  $this->current_version = $this->check_latest_version();
61
  }
62
 
145
  return;
146
  }
147
 
148
+ if ( version_compare( $this->current_version, $latest_version, '<' ) || ! $this->active_icon_set || ( $this->pro_icons_enabled && 'pro' !== $this->active_icon_set ) || ( ! $this->pro_icons_enabled && 'free' !== $this->active_icon_set ) ) {
149
  update_option( 'ACFFA_current_version', $latest_version, false );
150
  $this->current_version = $latest_version;
151
 
155
 
156
  private function check_latest_version( $update_option = true )
157
  {
158
+ $latest_version = false;
159
 
160
  $remote_get = wp_remote_get( $this->api_endpoint );
161
 
189
  {
190
  $fa_icons = get_option( 'ACFFA_icon_data' );
191
 
192
+ if ( empty( $fa_icons ) || ! isset( $fa_icons[ $this->current_version ] ) || ! $this->active_icon_set || ( $this->pro_icons_enabled && 'pro' !== $this->active_icon_set ) || ( ! $this->pro_icons_enabled && 'free' !== $this->active_icon_set ) ) {
193
+ $remote_get = wp_remote_get( $this->manifest_url );
 
194
 
195
+ if ( ! is_wp_error( $remote_get ) && isset( $remote_get['response']['code'] ) && '200' == $remote_get['response']['code'] ) {
196
  $response = wp_remote_retrieve_body( $remote_get );
197
 
198
  if ( ! empty( $response ) ) {
207
  $this->current_version => $icons
208
  );
209
 
210
+ $active_set = ( $this->pro_icons_enabled ) ? 'pro' : 'free';
211
+
212
  update_option( 'ACFFA_icon_data', $fa_icons, true );
213
+ update_option( 'ACFFA_active_icon_set', $active_set, true );
214
  }
215
  }
216
  }
217
+ } else {
218
+ // There was an error getting the icons, maybe CDN not enabled for Pro? Or CDN down?
219
  }
220
  }
221
 
234
  private function find_icons( $manifest )
235
  {
236
  $icons = array(
237
+ 'list' => array(),
238
+ 'details' => array()
239
  );
240
 
241
  foreach ( $manifest as $icon => $details ) {
readme.txt CHANGED
@@ -51,6 +51,9 @@ This ACF field type is compatible with:
51
 
52
  == Changelog ==
53
 
 
 
 
54
  = 3.0.0-beta1 =
55
  * Adding support for new FontAwesome 5.x free icon set
56
  * Adding new FontAwesome Settings admin menu under the ACF primary menu area for global configuration options.
@@ -165,6 +168,9 @@ This ACF field type is compatible with:
165
 
166
  == Upgrade Notice ==
167
 
 
 
 
168
  = 3.0.0-beta1 =
169
  * Adding support for new FontAwesome 5.x free icon set
170
  * Adding new FontAwesome Settings admin menu under the ACF primary menu area for global configuration options.
51
 
52
  == Changelog ==
53
 
54
+ = 3.0.0-beta2 =
55
+ * Adding support for FontAwesome Pro icons
56
+
57
  = 3.0.0-beta1 =
58
  * Adding support for new FontAwesome 5.x free icon set
59
  * Adding new FontAwesome Settings admin menu under the ACF primary menu area for global configuration options.
168
 
169
  == Upgrade Notice ==
170
 
171
+ = 3.0.0-beta2 =
172
+ * Adding support for FontAwesome Pro icons
173
+
174
  = 3.0.0-beta1 =
175
  * Adding support for new FontAwesome 5.x free icon set
176
  * Adding new FontAwesome Settings admin menu under the ACF primary menu area for global configuration options.