Advanced Custom Fields: Font Awesome Field - Version 4.0.0

Version Description

  • Added support for FontAwesome 6 icons
  • Added support for FontAwesome Kits including Custom Uploaded Icons
  • Now utilizes the FontAwesome GraphQL API for quicker searching, fuzzy matching
  • Added new compatibility mode to make updating from v4 and v5 icons easier
Download this release

Release Info

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

Code changes from version 3.1.2 to 4.0.0

acf-font-awesome.php CHANGED
@@ -4,8 +4,8 @@
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.1.2
8
- Author: mattkeys
9
  Author URI: http://mattkeys.me/
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -16,7 +16,7 @@ if ( ! defined( 'ABSPATH' ) ) {
16
  }
17
 
18
  if ( ! defined( 'ACFFA_VERSION' ) ) {
19
- define( 'ACFFA_VERSION', '3.1.2' );
20
  }
21
 
22
  if ( ! defined( 'ACFFA_PUBLIC_PATH' ) ) {
@@ -27,8 +27,8 @@ if ( ! defined( 'ACFFA_BASENAME' ) ) {
27
  define( 'ACFFA_BASENAME', plugin_basename( __FILE__ ) );
28
  }
29
 
30
- if ( is_admin() ) {
31
- require 'admin/class-ACFFA-Admin.php';
32
  }
33
 
34
  if ( ! class_exists('acf_plugin_font_awesome') ) :
@@ -39,37 +39,48 @@ if ( ! class_exists('acf_plugin_font_awesome') ) :
39
  {
40
  $acffa_major_version = $this->get_major_version();
41
 
 
 
 
 
42
  $this->check_for_updates( $acffa_major_version );
43
 
44
- if ( version_compare( $acffa_major_version, 5, '<' ) ) {
45
  require 'assets/inc/class-ACFFA-Loader-4.php';
46
- } else {
47
  require 'assets/inc/class-ACFFA-Loader-5.php';
 
 
48
  }
49
 
50
- $this->settings = array(
51
  'version' => ACFFA_VERSION,
52
  'url' => plugin_dir_url( __FILE__ ),
53
  'path' => plugin_dir_path( __FILE__ )
54
- );
55
 
56
  load_plugin_textdomain( 'acf-font-awesome', false, plugin_basename( dirname( __FILE__ ) ) . '/lang' );
57
 
58
- include_once('fields/acf-font-awesome-v5.php');
 
 
 
 
 
59
  }
60
 
61
  private function get_major_version()
62
  {
63
  $current_version = get_option( 'ACFFA_current_version' );
64
- $acffa_settings = get_option( 'acffa_settings', array() );
65
- $default_version = ( $current_version && empty( $acffa_settings ) ) ? 4 : 5;
66
 
67
  $acffa_major_version = isset( $acffa_settings['acffa_major_version'] ) ? intval( $acffa_settings['acffa_major_version'] ) : $default_version;
68
  $override_major_version = (int) apply_filters( 'ACFFA_override_major_version', false );
69
  if ( $override_major_version ) {
70
  $override_major_version = floor( $override_major_version );
71
 
72
- if ( 4 == $override_major_version || 5 == $override_major_version ) {
73
  if ( $acffa_major_version !== $override_major_version ) {
74
  $acffa_settings['acffa_major_version'] = $override_major_version;
75
  update_option( 'acffa_settings', $acffa_settings, false );
@@ -101,7 +112,7 @@ if ( ! class_exists('acf_plugin_font_awesome') ) :
101
 
102
  private function check_for_updates( $acffa_major_version )
103
  {
104
- $acffa_settings = get_option( 'acffa_settings', array() );
105
  $acffa_internal_version = isset( $acffa_settings['acffa_plugin_version'] ) ? $acffa_settings['acffa_plugin_version'] : false;
106
 
107
  if ( ! $acffa_internal_version ) {
@@ -109,11 +120,18 @@ if ( ! class_exists('acf_plugin_font_awesome') ) :
109
  }
110
 
111
  switch ( $acffa_major_version ) {
 
 
 
 
112
  case 5:
113
  if ( version_compare( $acffa_internal_version, '3.1.1', '<' ) ) {
114
  define( 'ACFFA_FORCE_REFRESH', true );
115
  do_action( 'ACFFA_refresh_latest_icons' );
116
  }
 
 
 
117
  break;
118
  }
119
 
@@ -124,6 +142,6 @@ if ( ! class_exists('acf_plugin_font_awesome') ) :
124
  }
125
  }
126
 
127
- add_action( 'acf/include_field_types', array( new acf_plugin_font_awesome, 'init' ), 10 );
128
 
129
  endif;
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: 4.0.0
8
+ Author: Matt Keys
9
  Author URI: http://mattkeys.me/
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
16
  }
17
 
18
  if ( ! defined( 'ACFFA_VERSION' ) ) {
19
+ define( 'ACFFA_VERSION', '4.0.0' );
20
  }
21
 
22
  if ( ! defined( 'ACFFA_PUBLIC_PATH' ) ) {
27
  define( 'ACFFA_BASENAME', plugin_basename( __FILE__ ) );
28
  }
29
 
30
+ if ( ! defined( 'ACFFA_DIRECTORY' ) ) {
31
+ define( 'ACFFA_DIRECTORY', dirname( __FILE__ ) );
32
  }
33
 
34
  if ( ! class_exists('acf_plugin_font_awesome') ) :
39
  {
40
  $acffa_major_version = $this->get_major_version();
41
 
42
+ if ( is_admin() ) {
43
+ require 'admin/class-ACFFA-Admin.php';
44
+ }
45
+
46
  $this->check_for_updates( $acffa_major_version );
47
 
48
+ if ( $acffa_major_version == 4 ) {
49
  require 'assets/inc/class-ACFFA-Loader-4.php';
50
+ } else if ( $acffa_major_version == 5 ) {
51
  require 'assets/inc/class-ACFFA-Loader-5.php';
52
+ } else {
53
+ require 'assets/inc/class-ACFFA-Loader-6.php';
54
  }
55
 
56
+ $this->settings = [
57
  'version' => ACFFA_VERSION,
58
  'url' => plugin_dir_url( __FILE__ ),
59
  'path' => plugin_dir_path( __FILE__ )
60
+ ];
61
 
62
  load_plugin_textdomain( 'acf-font-awesome', false, plugin_basename( dirname( __FILE__ ) ) . '/lang' );
63
 
64
+ if ( version_compare( $acffa_major_version, 6, '<' ) ) {
65
+ include_once('fields/acf-font-awesome-v5.php');
66
+ } else {
67
+ include_once('fields/acf-font-awesome-v6.php');
68
+ }
69
+
70
  }
71
 
72
  private function get_major_version()
73
  {
74
  $current_version = get_option( 'ACFFA_current_version' );
75
+ $acffa_settings = get_option( 'acffa_settings', [] );
76
+ $default_version = ( $current_version && empty( $acffa_settings ) ) ? 4 : 6;
77
 
78
  $acffa_major_version = isset( $acffa_settings['acffa_major_version'] ) ? intval( $acffa_settings['acffa_major_version'] ) : $default_version;
79
  $override_major_version = (int) apply_filters( 'ACFFA_override_major_version', false );
80
  if ( $override_major_version ) {
81
  $override_major_version = floor( $override_major_version );
82
 
83
+ if ( 4 == $override_major_version || 5 == $override_major_version || 6 == $override_major_version ) {
84
  if ( $acffa_major_version !== $override_major_version ) {
85
  $acffa_settings['acffa_major_version'] = $override_major_version;
86
  update_option( 'acffa_settings', $acffa_settings, false );
112
 
113
  private function check_for_updates( $acffa_major_version )
114
  {
115
+ $acffa_settings = get_option( 'acffa_settings', [] );
116
  $acffa_internal_version = isset( $acffa_settings['acffa_plugin_version'] ) ? $acffa_settings['acffa_plugin_version'] : false;
117
 
118
  if ( ! $acffa_internal_version ) {
120
  }
121
 
122
  switch ( $acffa_major_version ) {
123
+ case 4:
124
+ if ( version_compare( $acffa_internal_version, '4.0.0', '<' ) ) {
125
+ $acffa_settings['acffa_v5_compatibility_mode'] = 1;
126
+ }
127
  case 5:
128
  if ( version_compare( $acffa_internal_version, '3.1.1', '<' ) ) {
129
  define( 'ACFFA_FORCE_REFRESH', true );
130
  do_action( 'ACFFA_refresh_latest_icons' );
131
  }
132
+ if ( version_compare( $acffa_internal_version, '4.0.0', '<' ) ) {
133
+ $acffa_settings['acffa_v5_compatibility_mode'] = 1;
134
+ }
135
  break;
136
  }
137
 
142
  }
143
  }
144
 
145
+ add_action( 'acf/include_field_types', [ new acf_plugin_font_awesome, 'init' ], 10 );
146
 
147
  endif;
admin/class-ACFFA-Admin.php CHANGED
@@ -11,21 +11,32 @@
11
  class ACFFA_Admin
12
  {
13
 
 
14
  private $version;
15
 
16
  public function init()
17
  {
18
  $this->version = 'v' . ACFFA_MAJOR_VERSION;
19
 
20
- add_action( 'admin_notices', array( $this, 'show_upgrade_notice' ) );
21
- add_action( 'admin_notices', array( $this, 'maybe_notify_cdn_error' ) );
22
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
23
- add_filter( 'plugin_action_links', array( $this, 'add_settings_link' ), 10, 2 );
24
- add_action( 'admin_menu', array( $this, 'add_settings_page' ), 100 );
25
- add_action( 'admin_init', array( $this, 'register_settings' ) );
26
- add_filter( 'pre_update_option_acffa_settings', array( $this, 'intercept_icon_set_save' ), 10, 2 );
27
- add_filter( 'pre_update_option_acffa_settings', array( $this, 'maybe_refresh_icons' ), 20, 2 );
28
- add_action( 'wp_ajax_ACFFA_delete_icon_set', array( $this, 'ajax_remove_icon_set' ) );
 
 
 
 
 
 
 
 
 
 
29
  }
30
 
31
  public function show_upgrade_notice()
@@ -58,23 +69,122 @@ class ACFFA_Admin
58
  <?php
59
  }
60
 
61
- public function enqueue_scripts( $hook )
62
  {
63
  if ( 'custom-fields_page_fontawesome-settings' != $hook ) {
64
  return;
65
  }
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  wp_register_style( 'font-awesome', apply_filters( 'ACFFA_get_fa_url', '' ) );
68
- wp_enqueue_style( 'multi-select-css', ACFFA_PUBLIC_PATH . 'assets/inc/multi-select/multi-select.css', array( 'font-awesome' ) );
69
 
70
- wp_register_script( 'quicksearch-js', ACFFA_PUBLIC_PATH . 'assets/inc/quicksearch/jquery.quicksearch.js', array( 'jquery' ), '1.0.0', true );
71
- wp_register_script( 'multi-select-js', ACFFA_PUBLIC_PATH . 'assets/inc/multi-select/jquery.multi-select.js', array( 'jquery' ), '0.9.12', true );
72
- wp_enqueue_script( 'acffa-settings', ACFFA_PUBLIC_PATH . 'assets/js/settings.js', array( 'multi-select-js', 'quicksearch-js' ), '1.0.0', true );
73
- wp_localize_script( 'acffa-settings', 'ACFFA', array(
74
  'search_string' => __( 'Search List', 'acf-font-awesome' ),
75
  'confirm_delete' => __( 'Are you sure you want to delete this icon set?', 'acf-font-awesome' ),
76
  'delete_fail' => __( 'There was an error while trying to delete the icon set, please refresh the page and try again.', 'acf-font-awesome' )
77
- ));
78
  }
79
 
80
  public function add_settings_link( $links, $file )
@@ -85,6 +195,10 @@ class ACFFA_Admin
85
 
86
  array_unshift( $links, '<a href="' . esc_url( admin_url( '/edit.php?post_type=acf-field-group&page=fontawesome-settings' ) ) . '">' . esc_html__( 'Settings', 'acf-font-awesome' ) . '</a>' );
87
 
 
 
 
 
88
  return $links;
89
  }
90
 
@@ -94,11 +208,11 @@ class ACFFA_Admin
94
 
95
  add_submenu_page(
96
  'edit.php?post_type=acf-field-group',
97
- 'FontAwesome Settings',
98
  'FontAwesome Settings',
99
  $capability,
100
  'fontawesome-settings',
101
- array( $this, 'fontawesome_settings' )
102
  );
103
  }
104
 
@@ -113,6 +227,36 @@ class ACFFA_Admin
113
  ?>
114
  <div class="wrap">
115
  <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  <form action="options.php" method="post">
117
  <?php
118
  settings_fields( 'acffa' );
@@ -131,95 +275,143 @@ class ACFFA_Admin
131
  register_setting(
132
  'acffa',
133
  'acffa_settings',
134
- array(
135
- 'sanitize_callback' => array( $this, 'sanitize_new_icon_set' )
136
- )
137
  );
138
 
139
  add_settings_section(
140
  'acffa_section_developers',
141
- __( 'Major Version', 'acf-font-awesome' ),
142
- array( $this, 'acffa_section_developers_cb' ),
143
  'acffa'
144
  );
145
 
146
  add_settings_field(
147
  'acffa_major_version',
148
- __( 'Version', 'acf-font-awesome' ),
149
- array( $this, 'acffa_major_version_cb' ),
150
  'acffa',
151
  'acffa_section_developers',
152
- array(
153
  'label_for' => 'acffa_major_version',
154
  'class' => 'acffa_row'
155
- )
 
 
 
 
 
 
 
 
 
 
 
 
156
  );
157
 
158
  add_settings_field(
159
  'acffa_pro_cdn',
160
  __( 'Enable Pro Icons?', 'acf-font-awesome' ),
161
- array( $this, 'acffa_pro_cdn_cb' ),
162
  'acffa',
163
  'acffa_section_developers',
164
- array(
165
  'label_for' => 'acffa_pro_cdn',
166
  'class' => 'acffa_row pro_icons'
167
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  );
169
 
170
  add_settings_field(
171
  'acffa_plugin_version',
172
  'Plugin Version',
173
- array( $this, 'acffa_plugin_version_cb' ),
174
  'acffa',
175
  'acffa_section_developers',
176
- array(
177
  'label_for' => 'acffa_plugin_version',
178
  'class' => 'acffa_row hidden'
179
- )
180
  );
181
 
182
  add_settings_section(
183
  'acffa_section_icon_set_builder',
184
  __( 'Icon Set Builder', 'acf-font-awesome' ),
185
- array( $this, 'acffa_section_icon_set_builder_cb' ),
186
  'acffa'
187
  );
188
 
189
  add_settings_field(
190
  'acffa_new_icon_set_label',
191
  __( 'New Icon Set Label', 'acf-font-awesome' ),
192
- array( $this, 'acffa_new_icon_set_label_cb' ),
193
  'acffa',
194
  'acffa_section_icon_set_builder',
195
- array(
196
  'label_for' => 'acffa_new_icon_set_label',
197
  'class' => 'acffa_row custom-icon-set'
198
- )
199
  );
200
 
201
  add_settings_field(
202
  'acffa_new_icon_set',
203
  __( 'New Icon Set', 'acf-font-awesome' ),
204
- array( $this, 'acffa_new_icon_set_cb' ),
205
  'acffa',
206
  'acffa_section_icon_set_builder',
207
- array(
208
  'label_for' => 'acffa_new_icon_set',
209
  'class' => 'acffa_row custom-icon-set'
210
- )
211
  );
212
 
213
  add_settings_field(
214
  'acffa_existing_icon_sets',
215
  __( 'Existing Icon Sets', 'acf-font-awesome' ),
216
- array( $this, 'acffa_existing_icon_sets_cb' ),
217
  'acffa',
218
  'acffa_section_icon_set_builder',
219
- array(
220
  'label_for' => 'acffa_existing_icon_sets',
221
  'class' => 'acffa_row custom-icon-set'
222
- )
223
  );
224
  }
225
 
@@ -249,21 +441,17 @@ class ACFFA_Admin
249
  return $data;
250
  }
251
 
252
- public function acffa_section_developers_cb( $args )
253
- {
254
- ?>
255
- <p id="<?php echo esc_attr( $args['id'] ); ?>">
256
- <?php _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>
257
- <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>
258
- </p>
259
- <?php
260
- }
261
 
262
  public function acffa_major_version_cb( $args )
263
  {
264
  $options = get_option( 'acffa_settings' );
265
  $attributes = defined( 'ACFFA_OVERRIDE_MAJOR_VERSION' ) ? 'disabled' : false;
266
  ?>
 
 
 
 
267
  <select <?php echo $attributes; ?> id="<?php echo esc_attr( $args['label_for'] ); ?>" name="acffa_settings[<?php echo esc_attr( $args['label_for'] ); ?>]">
268
  <option value="4" <?php echo isset( $options[ $args[ 'label_for'] ] ) ? ( selected( $options[ $args[ 'label_for'] ], 4, false ) ) : ( '' ); ?>>
269
  <?php _e( '4.x', 'acf-font-awesome' ); ?>
@@ -271,17 +459,36 @@ class ACFFA_Admin
271
  <option value="5" <?php echo isset( $options[ $args[ 'label_for'] ] ) ? ( selected( $options[ $args[ 'label_for'] ], 5, false ) ) : ( '' ); ?>>
272
  <?php _e( '5.x', 'acf-font-awesome' ); ?>
273
  </option>
 
 
 
274
  </select>
275
  <?php
276
  if ( defined( 'ACFFA_OVERRIDE_MAJOR_VERSION' ) ) :
277
  ?>
278
  <p>
279
- <em><?php _e( 'The major version is manually set with the "ACFFA_override_major_version" filter, and cannot be modified from this screen. Please remove or update the filter to make changes.', 'acf-font-awesome' ); ?></em>
280
  </p>
281
  <?php
282
  endif;
283
  }
284
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
  public function acffa_pro_cdn_cb( $args )
286
  {
287
  $options = get_option( 'acffa_settings' );
@@ -298,6 +505,71 @@ class ACFFA_Admin
298
  <?php
299
  }
300
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
  public function acffa_plugin_version_cb( $args )
302
  {
303
  ?>
@@ -330,42 +602,50 @@ class ACFFA_Admin
330
 
331
  public function acffa_new_icon_set_cb( $args )
332
  {
333
- $options = get_option( 'acffa_settings' );
334
- ?>
335
- <select multiple="multiple" id="<?php echo esc_attr( $args['label_for'] ); ?>" name="acffa_settings[<?php echo esc_attr( $args['label_for'] ); ?>][]">
 
 
336
  <?php
337
- $fa_icons = apply_filters( 'ACFFA_get_icons', array() );
338
- if ( $fa_icons ) {
339
- if ( version_compare( ACFFA_MAJOR_VERSION, 5, '>=' ) ) {
340
- foreach ( $fa_icons['list'] as $prefix => $icons ) {
341
- $optgroup_label = apply_filters( 'ACFFA_icon_prefix_label', 'Regular', $prefix );
342
- echo '<optgroup label="' . $optgroup_label . '">';
343
-
344
- foreach( $icons as $k => $v ) {
345
- $value = str_replace( array( 'fas ', 'far ', 'fab ', 'fal ', 'fad ', 'fa-' ), '', $k );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
346
  ?>
347
  <option value="<?php echo $k; ?>"><?php echo $value; ?></option>
348
  <?php
349
  }
350
-
351
- echo '</optgroup>';
352
  }
353
  } else {
354
- foreach ( $fa_icons['list'] as $k => $v ) {
355
- $value = str_replace( array( 'fa-' ), '', $k );
356
- ?>
357
- <option value="<?php echo $k; ?>"><?php echo $value; ?></option>
358
- <?php
359
- }
360
  }
361
- } else {
362
- ?>
363
- <option value=""><?php _e( 'No Icons Found', 'acf-font-awesome' ); ?></option>
364
- <?php
365
- }
366
- ?>
367
- </select>
368
- <?php
369
  }
370
 
371
  public function acffa_existing_icon_sets_cb( $args )
@@ -387,7 +667,28 @@ class ACFFA_Admin
387
  <span><strong><?php echo esc_html( $icon_set_label ); ?></strong> <span class="actions">( <a href="#" class="edit-icon-set"><?php _e( 'Load For Editing', 'acf-font-awesome' ); ?></a> | <a href="#" class="view-icon-list"><?php _e( 'Toggle Icon List', 'acf-font-awesome' ); ?></a> | <a href="#" class="delete-icon-set" data-icon-set-name="<?php echo esc_html( $icon_set_name ); ?>" data-nonce="<?php echo wp_create_nonce( 'acffa_delete_set_' . $icon_set_name ); ?>"><?php _e( 'Delete Icon Set', 'acf-font-awesome' ); ?></a> )</span></span>
388
  <ul class="icon-list">
389
  <?php
390
- if ( version_compare( ACFFA_MAJOR_VERSION, 5, '>=' ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
391
  foreach ( $icon_set as $prefix => $icons ) {
392
  ?>
393
  <li>
@@ -443,6 +744,10 @@ class ACFFA_Admin
443
 
444
  public function maybe_refresh_icons( $new_value, $old_value )
445
  {
 
 
 
 
446
  unset( $new_value['acffa_new_icon_set_label'] );
447
  unset( $new_value['acffa_new_icon_set'] );
448
 
@@ -467,19 +772,95 @@ class ACFFA_Admin
467
  return $new_value;
468
  }
469
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
470
  private function save_new_icon_set( $label, $icons )
471
  {
472
- $new_icon_set = array();
473
 
474
- $fa_icons = apply_filters( 'ACFFA_get_icons', array() );
475
 
476
- if ( version_compare( ACFFA_MAJOR_VERSION, 5, '>=' ) ) {
 
 
 
 
 
 
 
 
477
  foreach( $icons as $icon ) {
478
  $prefix = substr( $icon, 0, 3 );
479
 
480
  if ( isset( $fa_icons['list'][ $prefix ][ $icon ] ) ) {
481
  if ( ! isset( $new_icon_set[ $prefix ] ) ) {
482
- $new_icon_set[ $prefix ] = array();
483
  }
484
  $new_icon_set[ $prefix ][ $icon ] = $fa_icons['list'][ $prefix ][ $icon ];
485
  }
@@ -504,11 +885,11 @@ class ACFFA_Admin
504
  $icon_sets_list = get_option( 'ACFFA_custom_icon_sets_list' );
505
 
506
  if ( ! $icon_sets_list ) {
507
- $icon_sets_list = array();
508
  }
509
 
510
  if ( ! isset( $icon_sets_list[ $this->version ] ) ) {
511
- $icon_sets_list[ $this->version ] = array();
512
  }
513
 
514
  if ( ! isset( $icon_sets_list[ $this->version ][ 'ACFFA_custom_icon_list_' . $option_name ] ) ) {
@@ -550,6 +931,22 @@ class ACFFA_Admin
550
  wp_die( 'success' );
551
  }
552
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
553
  }
554
 
555
- add_action( 'acf/init', array( new ACFFA_Admin, 'init' ), 10 );
11
  class ACFFA_Admin
12
  {
13
 
14
+
15
  private $version;
16
 
17
  public function init()
18
  {
19
  $this->version = 'v' . ACFFA_MAJOR_VERSION;
20
 
21
+ add_action( 'admin_notices', [ $this, 'show_upgrade_notice' ] );
22
+ add_action( 'admin_notices', [ $this, 'maybe_notify_cdn_error' ] );
23
+ add_filter( 'plugin_action_links', [ $this, 'add_settings_link' ], 10, 2 );
24
+ add_action( 'admin_menu', [ $this, 'add_settings_page' ], 100 );
25
+ add_action( 'admin_init', [ $this, 'register_settings' ] );
26
+ add_filter( 'pre_update_option_acffa_settings', [ $this, 'intercept_icon_set_save' ], 10, 2 );
27
+ add_filter( 'pre_update_option_acffa_settings', [ $this, 'maybe_refresh_icons' ], 20, 2 );
28
+ add_filter( 'pre_update_option_acffa_settings', [ $this, 'revoke_access_token' ], 20, 2 );
29
+ add_filter( 'pre_update_option_acffa_settings', [ $this, 'clear_search_config_cache' ], 20, 2 );
30
+ add_filter( 'pre_update_option_acffa_settings', [ $this, 'get_fontawesome_kits' ], 25, 2 );
31
+ add_action( 'wp_ajax_ACFFA_delete_icon_set', [ $this, 'ajax_remove_icon_set' ] );
32
+ add_filter( 'ACFFA_show_fontawesome_pro_blurbs', [ $this, 'hide_fontawesome_pro_blurbs' ], 5, 1 );
33
+
34
+ if ( version_compare( ACFFA_MAJOR_VERSION, 6, '=' ) ) {
35
+ add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_acf_select2' ] );
36
+ add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts_v6' ] );
37
+ } else {
38
+ add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts_v5' ] );
39
+ }
40
  }
41
 
42
  public function show_upgrade_notice()
69
  <?php
70
  }
71
 
72
+ public function enqueue_acf_select2( $hook )
73
  {
74
  if ( 'custom-fields_page_fontawesome-settings' != $hook ) {
75
  return;
76
  }
77
 
78
+ // globals
79
+ global $wp_scripts, $wp_styles;
80
+
81
+ // vars
82
+ $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
83
+ $major = acf_get_setting( 'select2_version' );
84
+ $version = '';
85
+ $script = '';
86
+ $style = '';
87
+
88
+ // attempt to find 3rd party Select2 version
89
+ // - avoid including v3 CSS when v4 JS is already enququed
90
+ if ( isset( $wp_scripts->registered['select2'] ) ) {
91
+
92
+ $major = (int) $wp_scripts->registered['select2']->ver;
93
+
94
+ }
95
+
96
+ // v4
97
+ if ( $major == 4 ) {
98
+
99
+ $version = '4.0.13';
100
+ $script = acf_get_url( "assets/inc/select2/4/select2.full{$min}.js" );
101
+ $style = acf_get_url( "assets/inc/select2/4/select2{$min}.css" );
102
+
103
+ // v3
104
+ } else {
105
+
106
+ $version = '3.5.2';
107
+ $script = acf_get_url( "assets/inc/select2/3/select2{$min}.js" );
108
+ $style = acf_get_url( 'assets/inc/select2/3/select2.css' );
109
+
110
+ }
111
+
112
+ // enqueue
113
+ wp_enqueue_script( 'select2', $script, [ 'jquery' ], $version );
114
+ wp_enqueue_style( 'select2', $style, '', $version );
115
+
116
+ // localize
117
+ acf_localize_data(
118
+ [
119
+ 'select2L10n' => [
120
+ 'matches_1' => _x( 'One result is available, press enter to select it.', 'Select2 JS matches_1', 'acf' ),
121
+ 'matches_n' => _x( '%d results are available, use up and down arrow keys to navigate.', 'Select2 JS matches_n', 'acf' ),
122
+ 'matches_0' => _x( 'No matches found', 'Select2 JS matches_0', 'acf' ),
123
+ 'input_too_short_1' => _x( 'Please enter 1 or more characters', 'Select2 JS input_too_short_1', 'acf' ),
124
+ 'input_too_short_n' => _x( 'Please enter %d or more characters', 'Select2 JS input_too_short_n', 'acf' ),
125
+ 'input_too_long_1' => _x( 'Please delete 1 character', 'Select2 JS input_too_long_1', 'acf' ),
126
+ 'input_too_long_n' => _x( 'Please delete %d characters', 'Select2 JS input_too_long_n', 'acf' ),
127
+ 'selection_too_long_1' => _x( 'You can only select 1 item', 'Select2 JS selection_too_long_1', 'acf' ),
128
+ 'selection_too_long_n' => _x( 'You can only select %d items', 'Select2 JS selection_too_long_n', 'acf' ),
129
+ 'load_more' => _x( 'Loading more results&hellip;', 'Select2 JS load_more', 'acf' ),
130
+ 'searching' => _x( 'Searching&hellip;', 'Select2 JS searching', 'acf' ),
131
+ 'load_fail' => _x( 'Loading failed', 'Select2 JS load_fail', 'acf' ),
132
+ ],
133
+ ]
134
+ );
135
+ }
136
+
137
+ public function enqueue_scripts_v6( $hook )
138
+ {
139
+ if ( 'custom-fields_page_fontawesome-settings' != $hook ) {
140
+ return;
141
+ }
142
+
143
+ $options = get_option( 'acffa_settings' );
144
+
145
+ $fa_url = apply_filters( 'ACFFA_get_fa_url', '' );
146
+ if ( stristr( $fa_url, 'https://kit.fontawesome.com/' ) ) {
147
+ wp_enqueue_script( 'acffa_font-awesome-kit', $fa_url );
148
+ } else {
149
+ wp_enqueue_style( 'acffa_font-awesome', $fa_url );
150
+ }
151
+
152
+ wp_enqueue_style( 'acffa-settings', ACFFA_PUBLIC_PATH . 'assets/css/settings.css' );
153
+ wp_enqueue_script( 'acffa-settings', ACFFA_PUBLIC_PATH . 'assets/js/settings-v6.js', [ 'select2', 'wp-util' ], '1.0.0', true );
154
+ wp_localize_script( 'acffa-settings', 'ACFFA', [
155
+ 'search_string' => __( 'Add New Icon', 'acf-font-awesome' ),
156
+ 'confirm_delete' => __( 'Are you sure you want to delete this icon set?', 'acf-font-awesome' ),
157
+ 'remove_icon' => __( 'Remove this icon from this set?', 'acf-font-awesome' ),
158
+ 'delete_fail' => __( 'There was an error while trying to delete the icon set, please refresh the page and try again.', 'acf-font-awesome' ),
159
+ 'acffa_major_version' => isset( $options['acffa_major_version'] ) ? $options['acffa_major_version'] : '',
160
+ 'acffa_kit' => isset( $options['acffa_kit'] ) ? $options['acffa_kit'] : '',
161
+ 'acf_nonce' => wp_create_nonce( 'acf_nonce' ),
162
+ 'kits' => get_option( 'ACFFA_kits', [] ),
163
+ 'api_key_status' => get_option( 'ACFFA_last_api_call_status', 'na' )
164
+ ] );
165
+
166
+ add_action( 'admin_footer', [ $this, 'js_templates' ] );
167
+ }
168
+
169
+ public function enqueue_scripts_v5( $hook )
170
+ {
171
+ if ( 'custom-fields_page_fontawesome-settings' != $hook ) {
172
+ return;
173
+ }
174
+
175
+ wp_enqueue_style( 'acffa-settings', ACFFA_PUBLIC_PATH . 'assets/css/settings.css' );
176
+
177
  wp_register_style( 'font-awesome', apply_filters( 'ACFFA_get_fa_url', '' ) );
178
+ wp_enqueue_style( 'multi-select-css', ACFFA_PUBLIC_PATH . 'assets/inc/multi-select/multi-select.css', [ 'font-awesome' ] );
179
 
180
+ wp_register_script( 'quicksearch-js', ACFFA_PUBLIC_PATH . 'assets/inc/quicksearch/jquery.quicksearch.js', [ 'jquery' ], '1.0.0', true );
181
+ wp_register_script( 'multi-select-js', ACFFA_PUBLIC_PATH . 'assets/inc/multi-select/jquery.multi-select.js', [ 'jquery' ], '0.9.12', true );
182
+ wp_enqueue_script( 'acffa-settings', ACFFA_PUBLIC_PATH . 'assets/js/settings-v5.js', [ 'multi-select-js', 'quicksearch-js' ], '1.0.0', true );
183
+ wp_localize_script( 'acffa-settings', 'ACFFA', [
184
  'search_string' => __( 'Search List', 'acf-font-awesome' ),
185
  'confirm_delete' => __( 'Are you sure you want to delete this icon set?', 'acf-font-awesome' ),
186
  'delete_fail' => __( 'There was an error while trying to delete the icon set, please refresh the page and try again.', 'acf-font-awesome' )
187
+ ] );
188
  }
189
 
190
  public function add_settings_link( $links, $file )
195
 
196
  array_unshift( $links, '<a href="' . esc_url( admin_url( '/edit.php?post_type=acf-field-group&page=fontawesome-settings' ) ) . '">' . esc_html__( 'Settings', 'acf-font-awesome' ) . '</a>' );
197
 
198
+ if ( apply_filters( 'ACFFA_show_fontawesome_pro_blurbs', true ) ) {
199
+ $links[] = '<a target="_blank" style="color:#20c997;" href="https://fontawesome.com/referral?a=0032f3e781">' . __( 'Get Font Awesome Pro!', 'acf-font-awesome' ) . '</a>';
200
+ }
201
+
202
  return $links;
203
  }
204
 
208
 
209
  add_submenu_page(
210
  'edit.php?post_type=acf-field-group',
211
+ 'FontAwesome for Advanced Custom Fields',
212
  'FontAwesome Settings',
213
  $capability,
214
  'fontawesome-settings',
215
+ [ $this, 'fontawesome_settings' ]
216
  );
217
  }
218
 
227
  ?>
228
  <div class="wrap">
229
  <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
230
+ <?php
231
+ if ( apply_filters( 'ACFFA_show_fontawesome_pro_blurbs', true ) ) :
232
+ switch( ACFFA_MAJOR_VERSION ) {
233
+ case '6':
234
+ $fortawesome = 'fa-solid fa-font-awesome';
235
+ $carrot_icon = 'fa-solid fa-carrot';
236
+ break;
237
+
238
+ case '5':
239
+ $fortawesome = 'fab fa-font-awesome-flag';
240
+ $carrot_icon = 'fas fa-carrot';
241
+ break;
242
+
243
+ default:
244
+ $fortawesome = 'fa fa-font-awesome';
245
+ $carrot_icon = 'fa fa-tree';
246
+ break;
247
+ }
248
+ ?>
249
+ <div class="get-fontawesome-pro">
250
+ <div class="title-button-wrap">
251
+ <i class="<?php echo $fortawesome; ?>"></i>
252
+ <h3><?php _e( 'Get more icons, styles, tools, & tech support. Upgrade to Font Awesome Pro!', 'acf-font-awesome' ); ?></h3>
253
+ <a target="_blank" href="https://fontawesome.com/referral?a=0032f3e781"><i class="<?php echo $carrot_icon; ?>"></i><?php _e( 'Get More with Pro', 'acf-font-awesome' ); ?></a>
254
+ </div>
255
+ <p><?php _e( 'A subscription to a Font Awesome Pro Plan gives you access to 7,000+ icons, all 5 icon styles, handy services and tools, software and icon updates, a lifetime license to use Pro icons, and actual human support. Signing up with the button above helps to support development on this plugin.', 'acf-font-awesome' ); ?></p>
256
+ </div>
257
+ <?php
258
+ endif;
259
+ ?>
260
  <form action="options.php" method="post">
261
  <?php
262
  settings_fields( 'acffa' );
275
  register_setting(
276
  'acffa',
277
  'acffa_settings',
278
+ [
279
+ 'sanitize_callback' => [ $this, 'sanitize_new_icon_set' ]
280
+ ]
281
  );
282
 
283
  add_settings_section(
284
  'acffa_section_developers',
285
+ __( 'Settings', 'acf-font-awesome' ),
286
+ [ $this, 'acffa_section_developers_cb' ],
287
  'acffa'
288
  );
289
 
290
  add_settings_field(
291
  'acffa_major_version',
292
+ __( 'FontAwesome Version', 'acf-font-awesome' ),
293
+ [ $this, 'acffa_major_version_cb' ],
294
  'acffa',
295
  'acffa_section_developers',
296
+ [
297
  'label_for' => 'acffa_major_version',
298
  'class' => 'acffa_row'
299
+ ]
300
+ );
301
+
302
+ add_settings_field(
303
+ 'acffa_v5_compatibility_mode',
304
+ __( 'Compatibility Mode', 'acf-font-awesome' ),
305
+ [ $this, 'acffa_v5_compatibility_mode_cb' ],
306
+ 'acffa',
307
+ 'acffa_section_developers',
308
+ [
309
+ 'label_for' => 'acffa_v5_compatibility_mode',
310
+ 'class' => 'acffa_row v5_compatibility_mode'
311
+ ]
312
  );
313
 
314
  add_settings_field(
315
  'acffa_pro_cdn',
316
  __( 'Enable Pro Icons?', 'acf-font-awesome' ),
317
+ [ $this, 'acffa_pro_cdn_cb' ],
318
  'acffa',
319
  'acffa_section_developers',
320
+ [
321
  'label_for' => 'acffa_pro_cdn',
322
  'class' => 'acffa_row pro_icons'
323
+ ]
324
+ );
325
+
326
+ add_settings_field(
327
+ 'acffa_api_key',
328
+ __( 'FontAwesome API Token', 'acf-font-awesome' ),
329
+ [ $this, 'acffa_api_key_cb' ],
330
+ 'acffa',
331
+ 'acffa_section_developers',
332
+ [
333
+ 'label_for' => 'acffa_api_key',
334
+ 'class' => 'acffa_row api_key'
335
+ ]
336
+ );
337
+
338
+ add_settings_field(
339
+ 'acffa_kit',
340
+ __( 'FontAwesome Kit', 'acf-font-awesome' ),
341
+ [ $this, 'acffa_kit_cb' ],
342
+ 'acffa',
343
+ 'acffa_section_developers',
344
+ [
345
+ 'label_for' => 'acffa_kit',
346
+ 'class' => 'acffa_row kit'
347
+ ]
348
+ );
349
+
350
+ add_settings_field(
351
+ 'acffa_kit_has_pro',
352
+ 'Has Pro Kit',
353
+ [ $this, 'acffa_kit_has_pro_cb' ],
354
+ 'acffa',
355
+ 'acffa_section_developers',
356
+ [
357
+ 'label_for' => 'acffa_kit_has_pro',
358
+ 'class' => 'acffa_row hidden'
359
+ ]
360
  );
361
 
362
  add_settings_field(
363
  'acffa_plugin_version',
364
  'Plugin Version',
365
+ [ $this, 'acffa_plugin_version_cb' ],
366
  'acffa',
367
  'acffa_section_developers',
368
+ [
369
  'label_for' => 'acffa_plugin_version',
370
  'class' => 'acffa_row hidden'
371
+ ]
372
  );
373
 
374
  add_settings_section(
375
  'acffa_section_icon_set_builder',
376
  __( 'Icon Set Builder', 'acf-font-awesome' ),
377
+ [ $this, 'acffa_section_icon_set_builder_cb' ],
378
  'acffa'
379
  );
380
 
381
  add_settings_field(
382
  'acffa_new_icon_set_label',
383
  __( 'New Icon Set Label', 'acf-font-awesome' ),
384
+ [ $this, 'acffa_new_icon_set_label_cb' ],
385
  'acffa',
386
  'acffa_section_icon_set_builder',
387
+ [
388
  'label_for' => 'acffa_new_icon_set_label',
389
  'class' => 'acffa_row custom-icon-set'
390
+ ]
391
  );
392
 
393
  add_settings_field(
394
  'acffa_new_icon_set',
395
  __( 'New Icon Set', 'acf-font-awesome' ),
396
+ [ $this, 'acffa_new_icon_set_cb' ],
397
  'acffa',
398
  'acffa_section_icon_set_builder',
399
+ [
400
  'label_for' => 'acffa_new_icon_set',
401
  'class' => 'acffa_row custom-icon-set'
402
+ ]
403
  );
404
 
405
  add_settings_field(
406
  'acffa_existing_icon_sets',
407
  __( 'Existing Icon Sets', 'acf-font-awesome' ),
408
+ [ $this, 'acffa_existing_icon_sets_cb' ],
409
  'acffa',
410
  'acffa_section_icon_set_builder',
411
+ [
412
  'label_for' => 'acffa_existing_icon_sets',
413
  'class' => 'acffa_row custom-icon-set'
414
+ ]
415
  );
416
  }
417
 
441
  return $data;
442
  }
443
 
444
+ public function acffa_section_developers_cb( $args ) {}
 
 
 
 
 
 
 
 
445
 
446
  public function acffa_major_version_cb( $args )
447
  {
448
  $options = get_option( 'acffa_settings' );
449
  $attributes = defined( 'ACFFA_OVERRIDE_MAJOR_VERSION' ) ? 'disabled' : false;
450
  ?>
451
+ <p>
452
+ <?php _e( 'IMPORTANT: This plugin has undergone major changes between FontAwesome versions. Switching to a new version may require you to reselect some/all icons that you have previously selected using this plugin. Switching to v6 has introduced a new "v5 Compatibility Mode" that aims to make this migration easier.', 'acf-font-awesome' ); ?>
453
+ </p>
454
+ <br>
455
  <select <?php echo $attributes; ?> id="<?php echo esc_attr( $args['label_for'] ); ?>" name="acffa_settings[<?php echo esc_attr( $args['label_for'] ); ?>]">
456
  <option value="4" <?php echo isset( $options[ $args[ 'label_for'] ] ) ? ( selected( $options[ $args[ 'label_for'] ], 4, false ) ) : ( '' ); ?>>
457
  <?php _e( '4.x', 'acf-font-awesome' ); ?>
459
  <option value="5" <?php echo isset( $options[ $args[ 'label_for'] ] ) ? ( selected( $options[ $args[ 'label_for'] ], 5, false ) ) : ( '' ); ?>>
460
  <?php _e( '5.x', 'acf-font-awesome' ); ?>
461
  </option>
462
+ <option value="6" <?php echo isset( $options[ $args[ 'label_for'] ] ) ? ( selected( $options[ $args[ 'label_for'] ], 6, false ) ) : ( '' ); ?>>
463
+ <?php _e( '6.x', 'acf-font-awesome' ); ?>
464
+ </option>
465
  </select>
466
  <?php
467
  if ( defined( 'ACFFA_OVERRIDE_MAJOR_VERSION' ) ) :
468
  ?>
469
  <p>
470
+ <em><?php _e( 'The FontAwesome version is manually set with the "ACFFA_override_major_version" filter, and cannot be modified from this screen. Please remove or update the filter to make changes.', 'acf-font-awesome' ); ?></em>
471
  </p>
472
  <?php
473
  endif;
474
  }
475
 
476
+ public function acffa_v5_compatibility_mode_cb( $args )
477
+ {
478
+ $options = get_option( 'acffa_settings' );
479
+ ?>
480
+ <p>
481
+ <?php _e( 'Attempt to automatically migrate any older FontAwesome icon selections made using this plugin to their FontAwesome v6 equivalents.', 'acf-font-awesome' ); ?><br>
482
+ <em><?php _e( 'NOTE: This is only able to automatically migrate FontAwesome free icons. Pro icons will need to be manually reselected.', 'acf-font-awesome' ); ?></em>
483
+ </p>
484
+ <br>
485
+ <p>
486
+ <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'] ] ) ) : ( '' ); ?> />
487
+ <label for="<?php echo esc_attr( $args['label_for'] ); ?>"><?php _e( 'Enable Compatibility Mode <em>(Recommended only for users with existing FontAwesome 4.x/5.x icon selections)</em>', 'acf-font-awesome' ); ?></label>
488
+ </p>
489
+ <?php
490
+ }
491
+
492
  public function acffa_pro_cdn_cb( $args )
493
  {
494
  $options = get_option( 'acffa_settings' );
505
  <?php
506
  }
507
 
508
+ public function acffa_api_key_cb( $args )
509
+ {
510
+ $options = get_option( 'acffa_settings' );
511
+ ?>
512
+ <p>
513
+ <?php _e( 'You can create an API token from your <a target="_blank" href="https://fontawesome.com/account/#api-tokens">FontAwesome Account</a> page', 'acf-font-awesome' ); ?><br>
514
+ </p>
515
+ <br>
516
+ <p>
517
+ <input type="text" class="regular-text code" value="<?php echo isset( $options[ $args[ 'label_for'] ] ) ? ( esc_attr( $options[ $args[ 'label_for'] ] ) ) : ''; ?>" id="<?php echo esc_attr( $args['label_for'] ); ?>" name="acffa_settings[<?php echo esc_attr( $args['label_for'] ); ?>]" />
518
+ <br>
519
+ <span class="validation-label"><?php _e( 'Token Validation:', 'acf-font-awesome' ); ?></span>
520
+ <span class="validation-result">
521
+ <span class="empty"><?php _e( 'Please add your API token above.', 'acf-font-awesome' ); ?></span>
522
+ <span class="save"><?php _e( 'Save settings to validate token.', 'acf-font-awesome' ); ?></span>
523
+ <span class="success"><?php _e( 'Token successfully validated.', 'acf-font-awesome' ); ?></span>
524
+ <span class="error"><?php _e( 'Could not validate token. Please verify the token has been correctly entered.', 'acf-font-awesome' ); ?></span>
525
+ </span>
526
+ </p>
527
+ <?php
528
+ }
529
+
530
+ public function acffa_kit_cb( $args )
531
+ {
532
+ $options = get_option( 'acffa_settings' );
533
+ ?>
534
+ <p>
535
+ <?php _e( 'FontAwesome kits are required for using FontAwesome Pro icons. Enter your API token above to select your kit.', 'acf-font-awesome' ); ?><br>
536
+ </p>
537
+ <br>
538
+
539
+ <table class="widefat" id="available_kits">
540
+ <thead>
541
+ <tr>
542
+ <td><?php _e( 'Select', 'acf-font-awesome' ); ?></td>
543
+ <td><?php _e( 'Kit Name', 'acf-font-awesome' ); ?></td>
544
+ <td><?php _e( 'Token', 'acf-font-awesome' ); ?></td>
545
+ <td><?php _e( 'Status', 'acf-font-awesome' ); ?></td>
546
+ <td><?php _e( 'License', 'acf-font-awesome' ); ?></td>
547
+ <td><?php _e( 'Technology', 'acf-font-awesome' ); ?></td>
548
+ <td><?php _e( 'Custom Icon(s)', 'acf-font-awesome' ); ?></td>
549
+ <td><?php _e( 'Version', 'acf-font-awesome' ); ?></td>
550
+ </tr>
551
+ </thead>
552
+ <tbody>
553
+ <tr class="no_kits_found">
554
+ <td><input type="radio" name="acffa_settings[acffa_kit]" checked value=""></td>
555
+ <td colspan="7">
556
+ <?php _e( 'No Kits Found. <a target="_blank" href="https://fontawesome.com/kits">Create a new kit</a>', 'acf-font-awesome' ); ?>
557
+ </td>
558
+ </tr>
559
+ </tbody>
560
+ </table>
561
+ <p><?php _e( 'Make changes to your kits on <a target="_blank" href="https://fontawesome.com/kits">fontawesome.com/kits</a>', 'acf-font-awesome' ); ?></p>
562
+ <?php
563
+ }
564
+
565
+ public function acffa_kit_has_pro_cb( $args )
566
+ {
567
+ $options = get_option( 'acffa_settings' );
568
+ ?>
569
+ <input type="hidden" value="<?php echo isset( $options[ $args[ 'label_for'] ] ) ? ( esc_attr( $options[ $args[ 'label_for'] ] ) ) : ''; ?>" id="<?php echo esc_attr( $args['label_for'] ); ?>" name="acffa_settings[<?php echo esc_attr( $args['label_for'] ); ?>]" />
570
+ <?php
571
+ }
572
+
573
  public function acffa_plugin_version_cb( $args )
574
  {
575
  ?>
602
 
603
  public function acffa_new_icon_set_cb( $args )
604
  {
605
+ if ( version_compare( ACFFA_MAJOR_VERSION, 6, '=' ) ) {
606
+ ?>
607
+ <div class="selected-icons"></div>
608
+ <select multiple id="<?php echo esc_attr( $args['label_for'] ); ?>" name="acffa_settings[<?php echo esc_attr( $args['label_for'] ); ?>][]"></select>
609
+ <select id="icon_chooser"></select>
610
  <?php
611
+ } else {
612
+ $options = get_option( 'acffa_settings' );
613
+ ?>
614
+ <select multiple="multiple" id="<?php echo esc_attr( $args['label_for'] ); ?>" name="acffa_settings[<?php echo esc_attr( $args['label_for'] ); ?>][]">
615
+ <?php
616
+ $fa_icons = apply_filters( 'ACFFA_get_icons', array() );
617
+ if ( $fa_icons ) {
618
+ if ( version_compare( ACFFA_MAJOR_VERSION, 5, '=' ) ) {
619
+ foreach ( $fa_icons['list'] as $prefix => $icons ) {
620
+ $optgroup_label = apply_filters( 'ACFFA_icon_prefix_label', 'Regular', $prefix );
621
+ echo '<optgroup label="' . $optgroup_label . '">';
622
+
623
+ foreach( $icons as $k => $v ) {
624
+ $value = str_replace( array( 'fas ', 'far ', 'fab ', 'fal ', 'fad ', 'fa-' ), '', $k );
625
+ ?>
626
+ <option value="<?php echo $k; ?>"><?php echo $value; ?></option>
627
+ <?php
628
+ }
629
+
630
+ echo '</optgroup>';
631
+ }
632
+ } else {
633
+ foreach ( $fa_icons['list'] as $k => $v ) {
634
+ $value = str_replace( array( 'fa-' ), '', $k );
635
  ?>
636
  <option value="<?php echo $k; ?>"><?php echo $value; ?></option>
637
  <?php
638
  }
 
 
639
  }
640
  } else {
641
+ ?>
642
+ <option value=""><?php _e( 'No Icons Found', 'acf-font-awesome' ); ?></option>
643
+ <?php
 
 
 
644
  }
645
+ ?>
646
+ </select>
647
+ <?php
648
+ }
 
 
 
 
649
  }
650
 
651
  public function acffa_existing_icon_sets_cb( $args )
667
  <span><strong><?php echo esc_html( $icon_set_label ); ?></strong> <span class="actions">( <a href="#" class="edit-icon-set"><?php _e( 'Load For Editing', 'acf-font-awesome' ); ?></a> | <a href="#" class="view-icon-list"><?php _e( 'Toggle Icon List', 'acf-font-awesome' ); ?></a> | <a href="#" class="delete-icon-set" data-icon-set-name="<?php echo esc_html( $icon_set_name ); ?>" data-nonce="<?php echo wp_create_nonce( 'acffa_delete_set_' . $icon_set_name ); ?>"><?php _e( 'Delete Icon Set', 'acf-font-awesome' ); ?></a> )</span></span>
668
  <ul class="icon-list">
669
  <?php
670
+ if ( version_compare( ACFFA_MAJOR_VERSION, 6, '=' ) ) {
671
+ foreach ( $icon_set as $prefix => $icons ) {
672
+ ?>
673
+ <li>
674
+ <span class="style"><?php echo apply_filters( 'ACFFA_icon_prefix_label', 'Regular', $prefix ); ?></span>
675
+ <ul>
676
+ <?php
677
+ foreach ( $icons as $id => $icon_json ) {
678
+ $icon_info = json_decode( $icon_json );
679
+
680
+ if ( 'fak' == $icon_info->style ) {
681
+ echo '<li class="icon" data-icon-json="' . htmlentities( $icon_json ) . '"><i class="' . $icon_info->style . ' fa-' . $icon_info->id . ' fa-fw"></i>' . $icon_info->label . '</li>';
682
+ } else {
683
+ echo '<li class="icon" data-icon-json="' . htmlentities( $icon_json ) . '"><i class="fa-' . $icon_info->style . ' fa-' . $icon_info->id . ' fa-fw"></i>' . $icon_info->label . '</li>';
684
+ }
685
+ }
686
+ ?>
687
+ </ul>
688
+ </li>
689
+ <?php
690
+ }
691
+ } else if ( version_compare( ACFFA_MAJOR_VERSION, 5, '=' ) ) {
692
  foreach ( $icon_set as $prefix => $icons ) {
693
  ?>
694
  <li>
744
 
745
  public function maybe_refresh_icons( $new_value, $old_value )
746
  {
747
+ if ( version_compare( ACFFA_MAJOR_VERSION, 6, '=' ) ) {
748
+ return $new_value;
749
+ }
750
+
751
  unset( $new_value['acffa_new_icon_set_label'] );
752
  unset( $new_value['acffa_new_icon_set'] );
753
 
772
  return $new_value;
773
  }
774
 
775
+ public function revoke_access_token( $new_value, $old_value )
776
+ {
777
+ $old_api_key = isset( $old_value['acffa_api_key'] ) ? $old_value['acffa_api_key'] : false;
778
+ $new_api_key = isset( $new_value['acffa_api_key'] ) ? $new_value['acffa_api_key'] : false;
779
+
780
+ if ( $old_api_key != $new_api_key ) {
781
+ delete_transient( 'ACFFA_access_token' );
782
+ delete_transient( 'ACFFA_search_config' );
783
+ update_option( 'ACFFA_last_api_call_status', 'na' );
784
+ update_option( 'ACFFA_kits', [] );
785
+ }
786
+
787
+ return $new_value;
788
+ }
789
+
790
+ public function clear_search_config_cache( $new_value, $old_value )
791
+ {
792
+ $old_kit_id = isset( $old_value['acffa_kit'] ) ? $old_value['acffa_kit'] : false;
793
+ $new_kit_id = isset( $new_value['acffa_kit'] ) ? $new_value['acffa_kit'] : false;
794
+
795
+ if ( $old_kit_id != $new_kit_id ) {
796
+ delete_transient( 'ACFFA_search_config' );
797
+ }
798
+
799
+ return $new_value;
800
+ }
801
+
802
+ public function get_fontawesome_kits( $new_value, $old_value )
803
+ {
804
+ if ( version_compare( ACFFA_MAJOR_VERSION, 6, '!=' ) ) {
805
+ return $new_value;
806
+ }
807
+
808
+ if ( ! isset( $new_value['acffa_api_key'] ) || empty( $new_value['acffa_api_key'] ) ) {
809
+ return $new_value;
810
+ }
811
+
812
+ $access_token = apply_filters( 'ACFFA_fontawesome_access_token', false, $new_value['acffa_api_key'] );
813
+
814
+ if ( ! $access_token ) {
815
+ return $new_value;
816
+ }
817
+
818
+ $remote_get = wp_remote_post( 'https://api.fontawesome.com', [
819
+ 'headers' => [
820
+ 'Content-Type' => 'application/json',
821
+ 'Authorization' => 'Bearer ' . $access_token,
822
+ ],
823
+ 'body' => '{
824
+ "query" : "query { me { kits { name token status licenseSelected technologySelected version iconUploads { name } } } }"
825
+ }'
826
+ ] );
827
+
828
+ if ( ! is_wp_error( $remote_get ) ) {
829
+ $response_json = wp_remote_retrieve_body( $remote_get );
830
+
831
+ if ( $response_json ) {
832
+ $response = json_decode( $response_json );
833
+
834
+ if ( isset( $response->data->me->kits ) && ! empty( $response->data->me->kits ) ) {
835
+ update_option( 'ACFFA_kits', $response->data->me->kits );
836
+ }
837
+ }
838
+ }
839
+
840
+ return $new_value;
841
+ }
842
+
843
  private function save_new_icon_set( $label, $icons )
844
  {
845
+ $new_icon_set = [];
846
 
847
+ $fa_icons = apply_filters( 'ACFFA_get_icons', [] );
848
 
849
+ if ( version_compare( ACFFA_MAJOR_VERSION, 6, '=' ) ) {
850
+ foreach( $icons as $icon ) {
851
+ $icon_details = json_decode( $icon );
852
+ if ( ! isset( $new_icon_set[ $icon_details->style ] ) ) {
853
+ $new_icon_set[ $icon_details->style ] = [];
854
+ }
855
+ $new_icon_set[ $icon_details->style ][ $icon_details->id ] = $icon;
856
+ }
857
+ } else if ( version_compare( ACFFA_MAJOR_VERSION, 5, '=' ) ) {
858
  foreach( $icons as $icon ) {
859
  $prefix = substr( $icon, 0, 3 );
860
 
861
  if ( isset( $fa_icons['list'][ $prefix ][ $icon ] ) ) {
862
  if ( ! isset( $new_icon_set[ $prefix ] ) ) {
863
+ $new_icon_set[ $prefix ] = [];
864
  }
865
  $new_icon_set[ $prefix ][ $icon ] = $fa_icons['list'][ $prefix ][ $icon ];
866
  }
885
  $icon_sets_list = get_option( 'ACFFA_custom_icon_sets_list' );
886
 
887
  if ( ! $icon_sets_list ) {
888
+ $icon_sets_list = [];
889
  }
890
 
891
  if ( ! isset( $icon_sets_list[ $this->version ] ) ) {
892
+ $icon_sets_list[ $this->version ] = [];
893
  }
894
 
895
  if ( ! isset( $icon_sets_list[ $this->version ][ 'ACFFA_custom_icon_list_' . $option_name ] ) ) {
931
  wp_die( 'success' );
932
  }
933
 
934
+ public function hide_fontawesome_pro_blurbs( $show_blurbs )
935
+ {
936
+ $acffa_settings = get_option( 'acffa_settings' );
937
+
938
+ if ( isset( $acffa_settings['acffa_kit_has_pro'] ) && $acffa_settings['acffa_kit_has_pro'] ) {
939
+ $show_blurbs = false;
940
+ }
941
+
942
+ return $show_blurbs;
943
+ }
944
+
945
+ public function js_templates()
946
+ {
947
+ include_once ACFFA_DIRECTORY . '/assets/js/templates/tmpl-fa-kit.php';
948
+ }
949
+
950
  }
951
 
952
+ add_action( 'acf/init', [ new ACFFA_Admin, 'init' ], 10 );
assets/css/input.css CHANGED
@@ -4,12 +4,33 @@
4
  font-size: 50px;
5
  }
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  .acf-field-object-font-awesome .acf-field-setting-default_label,
8
  .acf-field-object-font-awesome .acf-field-setting-custom_icon_sets {
9
  display: none;
10
  }
11
 
12
- .acf-input .icon_preview i {
 
13
  margin: 0 0 10px 0;
14
  }
15
 
@@ -18,6 +39,12 @@
18
  margin: 0 0 10px 0;
19
  }
20
 
 
 
 
 
 
 
21
  .fa-select2.fa4,
22
  .fa-select2-drop.fa4 {
23
  font-family: FontAwesome,-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
@@ -31,4 +58,35 @@
31
  .fa-select2.fa5 i.fas,
32
  .fa-select2-drop.fa5 i.fas {
33
  font-weight: 900;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  }
4
  font-size: 50px;
5
  }
6
 
7
+ .acf-field-setting-fa_live_preview.v5-compat-alert .acf-input i,
8
+ .acf-input .icon_preview.v5-compat-alert i,
9
+ .field_option_font-awesome .fa_live_preview.v5-compat-alert i,
10
+ .v5-compat-message {
11
+ color: #cc1818;
12
+ }
13
+
14
+ .v5-compat-message {
15
+ color: #cc1818;
16
+ display: inline-block;
17
+ padding-bottom: 5px;
18
+ }
19
+
20
+ .acf-field-setting-fa_live_preview .acf-input svg,
21
+ .acf-input .icon_preview svg,
22
+ .field_option_font-awesome .fa_live_preview svg {
23
+ width: 50px;
24
+ height: 50px;
25
+ }
26
+
27
  .acf-field-object-font-awesome .acf-field-setting-default_label,
28
  .acf-field-object-font-awesome .acf-field-setting-custom_icon_sets {
29
  display: none;
30
  }
31
 
32
+ .acf-input .icon_preview i,
33
+ .acf-input .icon_preview svg {
34
  margin: 0 0 10px 0;
35
  }
36
 
39
  margin: 0 0 10px 0;
40
  }
41
 
42
+ .field_type-font-awesome .icon_preview svg {
43
+ width: 50px;
44
+ height: 50px;
45
+ margin: 0 0 10px 0;
46
+ }
47
+
48
  .fa-select2.fa4,
49
  .fa-select2-drop.fa4 {
50
  font-family: FontAwesome,-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
58
  .fa-select2.fa5 i.fas,
59
  .fa-select2-drop.fa5 i.fas {
60
  font-weight: 900;
61
+ }
62
+
63
+ .acf-table tr.acf-field.acf-field-setting-get-fontawesome-pro > td.acf-label {
64
+ background: #1864ab !important;
65
+ color: #f8f9fa;
66
+ }
67
+ .acf-table tr.acf-field.acf-field-setting-get-fontawesome-pro > td.acf-input {
68
+ background: #d0ebff;
69
+ }
70
+ .acf-table tr.acf-field.acf-field-setting-get-fontawesome-pro > td.acf-input p {
71
+ margin-top: 0;
72
+ font-size: 14px;
73
+ }
74
+ .acf-table tr.acf-field.acf-field-setting-get-fontawesome-pro > td.acf-input p + p {
75
+ margin-bottom: 0;
76
+ }
77
+ .get-acfpro-btn {
78
+ display: inline-block;
79
+ padding: 10px;
80
+ background: #20c997;
81
+ color: #f8f9fa;
82
+ border-radius: 5px;
83
+ font-size: 14px;
84
+ }
85
+ .get-acfpro-btn:hover {
86
+ background-color: #12b886;
87
+ color: #f8f9fa;
88
+ }
89
+ .get-acfpro-btn i {
90
+ font-size: 20px;
91
+ padding-right: 8px;
92
  }
assets/css/settings.css ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #acffa_api_key {
2
+ margin-bottom: 5px;
3
+ }
4
+ .acffa_row.api_key .validation-label {
5
+ font-weight: bold;
6
+ }
7
+ .acffa_row.api_key .validation-result span:not(.empty) {
8
+ display: none;
9
+ }
10
+ .acffa_row.api_key .validation-result span.success {
11
+ color: #007017;
12
+ }
13
+ .acffa_row.api_key .validation-result span.error {
14
+ color: #d63638;
15
+ }
16
+ .acffa_row.api_key .validation-result span.save,
17
+ .acffa_row.api_key .validation-result span.empty {
18
+ color: #dba617;
19
+ }
20
+ .acffa_row.api_key, .acffa_row.kit {
21
+ display: none;
22
+ }
23
+ #available_kits .no_kits_found {
24
+ display: none;
25
+ }
26
+ select#acffa_new_icon_set {
27
+ display: none;
28
+ }
29
+ .selected-icons {
30
+ margin-bottom: 8px;
31
+ }
32
+ .selected-icons .new-icon {
33
+ cursor: pointer;
34
+ }
35
+ .existing-custom-icon-sets .icon-list {
36
+ display: none;
37
+ background: white;
38
+ padding: 8px;
39
+ margin: 8px 0;
40
+ border: 1px solid #c3c4c7;
41
+ box-shadow: 0 1px 1px rgb(0 0 0 / 4%);
42
+ }
43
+ .existing-custom-icon-sets .icon-list .style {
44
+ font-weight: bold;
45
+ font-style: italic;
46
+ }
47
+ .existing-custom-icon-sets .icon-list ul {
48
+ padding-left: 20px;
49
+ }
50
+ .get-fontawesome-pro {
51
+ padding: 30px 40px;
52
+ border-radius: 10px;
53
+ background: #1864ab;
54
+ font-family: Helvetica,Arial,sans-serif;
55
+ color: #f8f9fa;
56
+ margin: 10px 0;
57
+ }
58
+ @media screen and (max-width: 375px) {
59
+ .get-fontawesome-pro {
60
+ padding: 20px 20px;
61
+ }
62
+ }
63
+
64
+ .get-fontawesome-pro .title-button-wrap {
65
+ display: flex;
66
+ flex-direction: row;
67
+ flex-wrap: wrap;
68
+ }
69
+ .get-fontawesome-pro .title-button-wrap a {
70
+ display: block;
71
+ flex: 0 0 220px;
72
+ margin: auto;
73
+ align-self: center;
74
+ background-color: #20c997;
75
+ color: #f8f9fa;
76
+ transition: all .1s ease-in;
77
+ box-shadow: inset 0 1px 0 rgb(255 255 255 / 1%), 0 1px 1px rgb(0 0 0 / 5%);
78
+ border-top-width: 0.0625rem;
79
+ border-bottom-width: calc(0.2rem + 0.0625rem);
80
+ text-decoration: none;
81
+ font-size: 20px;
82
+ line-height: 50px;
83
+ padding: 10px 20px;
84
+ border-radius: 8px;
85
+ }
86
+ .get-fontawesome-pro .title-button-wrap a i {
87
+ color: #f8f9fa;
88
+ opacity: 0.5;
89
+ font-size: 40px;
90
+ line-height: 1;
91
+ vertical-align: middle;
92
+ padding-right: 10px;
93
+ }
94
+
95
+ .get-fontawesome-pro .title-button-wrap a:hover {
96
+ background-color: #12b886;
97
+ }
98
+ .get-fontawesome-pro i {
99
+ align-self: center;
100
+ color: #63e6be;
101
+ flex: 0 0 85px;
102
+ font-size: 60px;
103
+ }
104
+ @media screen and (max-width: 500px) {
105
+ .get-fontawesome-pro i {
106
+ flex: 0 0 50px;
107
+ font-size: 36px;
108
+ }
109
+ }
110
+ .get-fontawesome-pro h3 {
111
+ flex: 1;
112
+ min-width: 240px;
113
+ padding-right: 20px;
114
+ color: #f8f9fa;
115
+ font-size: 30px;
116
+ font-weight: 300;
117
+ line-height: 1.1;
118
+ }
119
+ @media screen and (max-width: 500px) {
120
+ .get-fontawesome-pro h3 {
121
+ font-size: 28px
122
+ }
123
+ }
124
+ .get-fontawesome-pro p {
125
+ font-size: 16px;
126
+ }
assets/inc/class-ACFFA-Loader-5.php CHANGED
@@ -68,6 +68,7 @@ class ACFFA_Loader_5
68
  add_filter( 'ACFFA_get_fa_url', array( $this, 'get_fa_url' ), 5, 1 );
69
  add_filter( 'ACFFA_icon_prefix', array( $this, 'get_prefix' ), 5, 2 );
70
  add_filter( 'ACFFA_icon_prefix_label', array( $this, 'get_prefix_label' ), 5, 2 );
 
71
  }
72
 
73
  public function select2_ajax_request()
@@ -83,28 +84,31 @@ class ACFFA_Loader_5
83
 
84
  private function get_ajax_query( $options = array() )
85
  {
86
- $options = acf_parse_args($options, array(
87
  'post_id' => 0,
88
  's' => '',
89
  'field_key' => '',
90
  'paged' => 0
91
  ));
92
 
93
- $results = array();
94
- $s = null;
95
 
96
- if ( 'default_value' != $options['field_key'] ) {
97
  $field = acf_get_field( $options['field_key'] );
98
  if ( ! $field ) return false;
99
- }
100
 
101
  if ( $options['s'] !== '' ) {
102
  $s = strval( $options['s'] );
103
  $s = wp_unslash( $s );
104
  }
105
 
106
- if ( isset( $field['icon_sets'] ) // Make sure we have an icon set
107
- && in_array( 'custom', $field['icon_sets'] ) // Make sure that icon set is 'custom'
 
 
 
108
  && isset( $field['custom_icon_set'] ) // Make sure a custom set has been chosen
109
  && stristr( $field['custom_icon_set'], 'ACFFA_custom_icon_list_' . $this->version ) // Make sure that chosen custom set matches this version of FontAwesome
110
  && $custom_icon_set = get_option( $field['custom_icon_set'] ) // Make sure we can retrieve the icon set from the DB/cache
@@ -118,7 +122,7 @@ class ACFFA_Loader_5
118
 
119
  if ( $fa_icons ) {
120
  foreach ( $fa_icons['list'] as $prefix => $icons ) {
121
- if ( ! empty( $field['icon_sets'] ) && ! in_array( 'custom', $field['icon_sets'] ) && ! in_array( $prefix, $field['icon_sets'] ) ) {
122
  continue;
123
  }
124
 
@@ -335,6 +339,41 @@ class ACFFA_Loader_5
335
 
336
  return $label;
337
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
338
  }
339
 
340
  new ACFFA_Loader_5();
68
  add_filter( 'ACFFA_get_fa_url', array( $this, 'get_fa_url' ), 5, 1 );
69
  add_filter( 'ACFFA_icon_prefix', array( $this, 'get_prefix' ), 5, 2 );
70
  add_filter( 'ACFFA_icon_prefix_label', array( $this, 'get_prefix_label' ), 5, 2 );
71
+ add_filter( 'ACFFA_active_icon_sets', array( $this, 'check_active_icon_sets' ), 5, 1 );
72
  }
73
 
74
  public function select2_ajax_request()
84
 
85
  private function get_ajax_query( $options = array() )
86
  {
87
+ $options = acf_parse_args($options, array(
88
  'post_id' => 0,
89
  's' => '',
90
  'field_key' => '',
91
  'paged' => 0
92
  ));
93
 
94
+ $results = array();
95
+ $s = null;
96
 
97
+ if ( 'default_value' != $options['field_key'] ) {
98
  $field = acf_get_field( $options['field_key'] );
99
  if ( ! $field ) return false;
100
+ }
101
 
102
  if ( $options['s'] !== '' ) {
103
  $s = strval( $options['s'] );
104
  $s = wp_unslash( $s );
105
  }
106
 
107
+ $active_icon_sets = isset( $field['icon_sets'] ) ? $field['icon_sets'] : [];
108
+ $active_icon_sets = apply_filters( 'ACFFA_active_icon_sets', $active_icon_sets );
109
+
110
+ if ( isset( $active_icon_sets ) // Make sure we have an icon set
111
+ && in_array( 'custom', $active_icon_sets ) // Make sure that icon set is 'custom'
112
  && isset( $field['custom_icon_set'] ) // Make sure a custom set has been chosen
113
  && stristr( $field['custom_icon_set'], 'ACFFA_custom_icon_list_' . $this->version ) // Make sure that chosen custom set matches this version of FontAwesome
114
  && $custom_icon_set = get_option( $field['custom_icon_set'] ) // Make sure we can retrieve the icon set from the DB/cache
122
 
123
  if ( $fa_icons ) {
124
  foreach ( $fa_icons['list'] as $prefix => $icons ) {
125
+ if ( ! empty( $active_icon_sets ) && ! in_array( 'custom', $active_icon_sets ) && ! in_array( $prefix, $active_icon_sets ) ) {
126
  continue;
127
  }
128
 
339
 
340
  return $label;
341
  }
342
+
343
+ public function check_active_icon_sets( $active_icon_sets )
344
+ {
345
+ foreach ( $active_icon_sets as $key => $icon_set ) {
346
+ switch ( $icon_set ) {
347
+ case 'solid':
348
+ unset( $active_icon_sets[ $key ] );
349
+ $active_icon_sets[] = 'fas';
350
+ break;
351
+
352
+ case 'regular':
353
+ unset( $active_icon_sets[ $key ] );
354
+ $active_icon_sets[] = 'far';
355
+ break;
356
+
357
+ case 'light':
358
+ unset( $active_icon_sets[ $key ] );
359
+ $active_icon_sets[] = 'fal';
360
+ break;
361
+
362
+ case 'duotone':
363
+ unset( $active_icon_sets[ $key ] );
364
+ $active_icon_sets[] = 'fad';
365
+ break;
366
+
367
+ case 'brands':
368
+ unset( $active_icon_sets[ $key ] );
369
+ $active_icon_sets[] = 'fab';
370
+ break;
371
+
372
+ }
373
+ }
374
+
375
+ return $active_icon_sets;
376
+ }
377
  }
378
 
379
  new ACFFA_Loader_5();
assets/inc/class-ACFFA-Loader-6.php ADDED
@@ -0,0 +1,471 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * =======================================
4
+ * Advanced Custom Fields Font Awesome Loader 6
5
+ * Used with FontAwesome 6.x icon set
6
+ * =======================================
7
+ *
8
+ *
9
+ * @author Matt Keys <https://profiles.wordpress.org/mattkeys>
10
+ */
11
+
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+ class ACFFA_Loader_6
17
+ {
18
+ private $kit_token = false;
19
+ private $latest_version_timestamp = false;
20
+ private $options = false;
21
+
22
+ public function __construct()
23
+ {
24
+ $acffa_settings = get_option( 'acffa_settings' );
25
+ $this->kit_token = isset( $acffa_settings['acffa_kit'] ) ? sanitize_text_field( $acffa_settings['acffa_kit'] ) : false;
26
+ $this->latest_version_timestamp = get_option( 'ACFFA_latest_version_timestamp', time() );
27
+ $this->options = get_option( 'acffa_settings', [] );
28
+
29
+ add_action( 'wp_ajax_acf/fields/font-awesome/query', [ $this, 'select2_ajax_request' ] );
30
+ add_filter( 'ACFFA_get_fa_url', [ $this, 'get_fa_url' ], 5, 1 );
31
+ add_filter( 'ACFFA_icon_prefix_label', [ $this, 'get_prefix_label' ], 5, 2 );
32
+ add_filter( 'ACFFA_get_latest_version', [ $this, 'get_latest_version' ], 5, 2 );
33
+ add_filter( 'ACFFA_fontawesome_access_token', [ $this, 'get_access_token' ], 5, 2 );
34
+ add_filter( 'script_loader_tag', [ $this, 'fa_kit_script_attributes' ], 10, 3 );
35
+ add_filter( 'script_loader_tag', [ $this, 'js_api_script_attributes' ], 10, 3 );
36
+ }
37
+
38
+ public function select2_ajax_request()
39
+ {
40
+ if ( ! acf_verify_ajax() ) {
41
+ die();
42
+ }
43
+
44
+ if ( ( ! isset( $this->options['acffa_kit'] ) || empty( $this->options['acffa_kit'] ) ) || ( isset( $this->options['acffa_v5_compatibility_mode'] ) && $this->options['acffa_v5_compatibility_mode'] ) ) {
45
+ $this->maybe_recheck_latest_version();
46
+ }
47
+
48
+ $response = $this->get_ajax_query( $_POST );
49
+
50
+ acf_send_ajax_results( $response );
51
+ }
52
+
53
+ private function get_search_config()
54
+ {
55
+ if ( ! isset( $this->options['acffa_kit'] ) || empty( $this->options['acffa_kit'] ) ) {
56
+ return [];
57
+ }
58
+
59
+ $kit_id = $this->options['acffa_kit'];
60
+
61
+ if ( ! $search_config = get_transient( 'ACFFA_search_config' ) ) {
62
+ $access_token = apply_filters( 'ACFFA_fontawesome_access_token', false );
63
+
64
+ if ( ! $access_token ) {
65
+ return;
66
+ }
67
+
68
+ $remote_get = wp_remote_post( 'https://api.fontawesome.com', [
69
+ 'headers' => [
70
+ 'Content-Type' => 'application/json',
71
+ 'Authorization' => 'Bearer ' . $access_token,
72
+ ],
73
+ 'body' => '{
74
+ "query" : "query { me { kit (token: \"' . $kit_id . '\") { version licenseSelected iconUploads { name width height path unicode } } } }"
75
+ }'
76
+ ] );
77
+
78
+ if ( ! is_wp_error( $remote_get ) ) {
79
+ $response_json = wp_remote_retrieve_body( $remote_get );
80
+
81
+ if ( $response_json ) {
82
+ $response = json_decode( $response_json );
83
+ $search_config = [];
84
+ if ( isset( $response->data->me->kit->version ) ) {
85
+ $search_config['search_version'] = $response->data->me->kit->version;
86
+ }
87
+ if ( isset( $response->data->me->kit->version ) ) {
88
+ $search_config['search_license'] = $response->data->me->kit->licenseSelected;
89
+ }
90
+ if ( isset( $response->data->me->kit->version ) ) {
91
+ $search_config['custom_icons'] = $response->data->me->kit->iconUploads;
92
+ }
93
+ set_transient( 'ACFFA_search_config', $search_config, MINUTE_IN_SECONDS );
94
+ } else {
95
+ $search_config = [];
96
+ }
97
+ } else {
98
+ $search_config = [];
99
+ }
100
+ }
101
+
102
+ return $search_config;
103
+ }
104
+
105
+ public function get_access_token( $access_token, $new_api_key = false )
106
+ {
107
+ $api_key = $new_api_key ? $new_api_key : false;
108
+
109
+ if ( ! $api_key ) {
110
+ $api_key = isset( $this->options['acffa_api_key'] ) && ! empty( $this->options['acffa_api_key'] ) ? $this->options['acffa_api_key'] : false;
111
+ }
112
+
113
+ if ( ! $api_key ) {
114
+ return;
115
+ }
116
+
117
+ if ( ! $access_token = get_transient( 'ACFFA_access_token' ) ) {
118
+ $remote_get = wp_remote_post( 'https://api.fontawesome.com/token', [
119
+ 'headers' => [
120
+ 'Content-Type' => 'application/json',
121
+ 'Authorization' => 'Bearer ' . $api_key,
122
+ ]
123
+ ] );
124
+
125
+ if ( ! is_wp_error( $remote_get ) ) {
126
+ $response_json = wp_remote_retrieve_body( $remote_get );
127
+
128
+ if ( $response_json ) {
129
+ $response = json_decode( $response_json );
130
+ if ( isset( $response->access_token ) ) {
131
+ $access_token = $response->access_token;
132
+ $expire_time = $response->expires_in - 5;
133
+ set_transient( 'ACFFA_access_token', $access_token, $expire_time );
134
+ update_option( 'ACFFA_last_api_call_status', 'success' );
135
+ } else {
136
+ update_option( 'ACFFA_last_api_call_status', 'error' );
137
+ }
138
+ }
139
+ }
140
+ }
141
+
142
+ return $access_token;
143
+ }
144
+
145
+ private function get_ajax_query( $options = [] )
146
+ {
147
+ $search_config = $this->get_search_config();
148
+
149
+ $options = acf_parse_args($options, [
150
+ 'post_id' => 0,
151
+ 's' => '',
152
+ 'field_key' => '',
153
+ 'paged' => 0,
154
+ 'fa_version' => isset( $search_config['search_version'] ) ? $search_config['search_version'] : '6.x',
155
+ 'fa_license' => isset( $search_config['search_license'] ) ? $search_config['search_license'] : 'free',
156
+ 'custom_icons' => isset( $search_config['custom_icons'] ) ? $search_config['custom_icons'] : []
157
+ ] );
158
+
159
+ $results = [];
160
+ $s = null;
161
+
162
+ if ( 'icon_set_builder' == $options['field_key'] ) {
163
+ $field = [];
164
+ $field[ 'icon_sets' ] = [
165
+ 'solid',
166
+ 'regular',
167
+ 'light',
168
+ 'thin',
169
+ 'duotone',
170
+ 'fak',
171
+ 'brands'
172
+ ];
173
+ } else if ( 'default_value' != $options['field_key'] ) {
174
+ $field = acf_get_field( $options['field_key'] );
175
+ if ( ! $field ) return false;
176
+ }
177
+
178
+ $s = strval( $options['s'] );
179
+ $s = wp_unslash( $s );
180
+
181
+ $active_icon_sets = isset( $field['icon_sets'] ) ? $field['icon_sets'] : [];
182
+ $active_icon_sets = apply_filters( 'ACFFA_v5_upgrade_compat_selected_field_sets', $active_icon_sets );
183
+ $active_icon_sets = apply_filters( 'ACFFA_active_icon_sets', $active_icon_sets );
184
+ $search_custom_icon_set = false;
185
+
186
+ if ( isset( $active_icon_sets ) // Make sure we have an icon set
187
+ && in_array( 'custom', $active_icon_sets ) // Make sure that icon set is 'custom'
188
+ && isset( $field['custom_icon_set'] ) // Make sure a custom set has been chosen
189
+ && stristr( $field['custom_icon_set'], 'ACFFA_custom_icon_list_v' . ACFFA_MAJOR_VERSION ) // Make sure that chosen custom set matches this version of FontAwesome
190
+ && $custom_icon_set = get_option( $field['custom_icon_set'] ) // Make sure we can retrieve the icon set from the DB/cache
191
+ ) {
192
+ $search_custom_icon_set = true;
193
+ }
194
+
195
+ $kit_version = apply_filters( 'acffa_kit_version', $options['fa_version'] );
196
+ $kit_license = apply_filters( 'acffa_kit_license', $options['fa_license'] );
197
+ $custom_icons = apply_filters( 'acffa_kit_custom_icons', $options['custom_icons'] );
198
+
199
+ if ( $search_custom_icon_set && '' == $s ) {
200
+ $sorted_icons = [];
201
+
202
+ foreach ( $custom_icon_set as $style => $icons ) {
203
+ if ( ! isset( $sorted_icons[ $style ] ) ) {
204
+ $sorted_icons[ $style ] = [];
205
+ }
206
+
207
+ foreach ( $icons as $icon ) {
208
+ $icon_details = json_decode( $icon );
209
+
210
+ if ( 'fak' == $icon_details->style ) {
211
+ $sorted_icons[ $style ][] = [
212
+ 'id' => $icon,
213
+ 'text' => '<i class="' . $style . ' fa-' . $icon_details->id . ' fa-fw"></i> ' . $icon_details->label
214
+ ];
215
+ } else {
216
+ $sorted_icons[ $style ][] = [
217
+ 'id' => $icon,
218
+ 'text' => '<i class="fa-' . $style . ' fa-' . $icon_details->id . ' fa-fw"></i> ' . $icon_details->label
219
+ ];
220
+ }
221
+ }
222
+ }
223
+
224
+ foreach ( $sorted_icons as $style => $icons ) {
225
+ $results[] = [
226
+ 'id' => $style,
227
+ 'text' => apply_filters( 'ACFFA_icon_prefix_label', $style, $style ),
228
+ 'children' => $icons
229
+ ];
230
+ }
231
+
232
+ $response = [
233
+ 'results' => $results
234
+ ];
235
+
236
+ return $response;
237
+ }
238
+
239
+ $remote_get = wp_remote_post( 'https://api.fontawesome.com', [
240
+ 'headers' => [
241
+ 'Content-Type' => 'application/json'
242
+ ],
243
+ 'body' => '{
244
+ "query" : "query { search(version: \"' . $kit_version . '\", query: \"' . $s . '\", first: 100) { id label styles unicode membership { free } } }"
245
+ }'
246
+ ] );
247
+
248
+ if ( ! is_wp_error( $remote_get ) ) {
249
+ $response_json = wp_remote_retrieve_body( $remote_get );
250
+
251
+ if ( $response_json ) {
252
+ $response = json_decode( $response_json );
253
+
254
+ $sorted_icons = [];
255
+ if ( isset( $response->data->search ) && ! empty( $response->data->search ) ) {
256
+ if ( $search_custom_icon_set ) {
257
+ foreach ( $response->data->search as $icon ) {
258
+ foreach ( $icon->styles as $style ) {
259
+ if ( ! isset( $sorted_icons[ $style ] ) ) {
260
+ $sorted_icons[ $style ] = [];
261
+ }
262
+
263
+ if ( ! isset( $custom_icon_set[ $style ][ $icon->id ] ) ) {
264
+ continue;
265
+ }
266
+
267
+ if ( 'free' == $kit_license && ! in_array( $style, $icon->membership->free ) ) {
268
+ continue;
269
+ }
270
+
271
+ $sorted_icons[ $style ][] = [
272
+ 'id' => '{ "style" : "' . $matched_set . '", "id" : "' . $icon->id . '", "label" : "' . $icon->label . '", "unicode" : "' . $icon->unicode . '" }',
273
+ 'text' => '<i class="fa-' . $matched_set . ' fa-' . $icon->id . ' fa-fw"></i> ' . $icon->label
274
+ ];
275
+ }
276
+ }
277
+ } else {
278
+ if ( ! empty( $active_icon_sets ) ) {
279
+ foreach ( $active_icon_sets as $icon_set ) {
280
+ if ( ! isset( $sorted_icons[ $icon_set ] ) ) {
281
+ $sorted_icons[ $icon_set ] = [];
282
+ }
283
+ }
284
+
285
+ foreach ( $response->data->search as $icon ) {
286
+ $matched_sets = array_intersect( $active_icon_sets, $icon->styles );
287
+ if ( ! $matched_sets ) {
288
+ continue;
289
+ }
290
+
291
+ foreach ( $matched_sets as $matched_set ) {
292
+ if ( 'free' == $kit_license && ! in_array( $matched_set, $icon->membership->free ) ) {
293
+ continue;
294
+ }
295
+
296
+ $sorted_icons[ $matched_set ][] = [
297
+ 'id' => '{ "style" : "' . $matched_set . '", "id" : "' . $icon->id . '", "label" : "' . $icon->label . '", "unicode" : "' . $icon->unicode . '" }',
298
+ 'text' => '<i class="fa-' . $matched_set . ' fa-' . $icon->id . ' fa-fw"></i> ' . $icon->label
299
+ ];
300
+ }
301
+ }
302
+ } else {
303
+ foreach ( $response->data->search as $icon ) {
304
+ foreach ( $icon->styles as $style ) {
305
+ if ( ! isset( $sorted_icons[ $style ] ) ) {
306
+ $sorted_icons[ $style ] = [];
307
+ }
308
+
309
+ if ( 'free' == $kit_license && ! in_array( $style, $icon->membership->free ) ) {
310
+ continue;
311
+ }
312
+
313
+ $sorted_icons[ $style ][] = [
314
+ 'id' => '{ "style" : "' . $style . '", "id" : "' . $icon->id . '", "label" : "' . $icon->label . '", "unicode" : "' . $icon->unicode . '" }',
315
+ 'text' => '<i class="fa-' . $style . ' fa-' . $icon->id . ' fa-fw"></i> ' . $icon->label
316
+ ];
317
+ }
318
+ }
319
+ }
320
+ }
321
+ }
322
+
323
+ if ( ! empty( $custom_icons ) ) {
324
+ if ( ! isset( $sorted_icons['fak'] ) ) {
325
+ $sorted_icons['fak'] = [];
326
+ }
327
+ foreach ( $custom_icons as $custom_icon ) {
328
+ if ( false !== strpos( $custom_icon->name, $s ) ) {
329
+ $sorted_icons['fak'][] = [
330
+ 'id' => '{ "style" : "fak", "id" : "' . $custom_icon->name . '", "label" : "' . $custom_icon->name . '", "unicode" : "' . $custom_icon->unicode . '", "width" : "' . $custom_icon->width . '", "height" : "' . $custom_icon->height . '", "path" : "' . $custom_icon->path . '" }',
331
+ 'text' => '<i class="fak fa-' . $custom_icon->name . ' fa-fw"></i> ' . $custom_icon->name
332
+ ];
333
+ }
334
+ }
335
+ }
336
+
337
+ foreach ( $sorted_icons as $style => $icons ) {
338
+ if ( empty( $icons ) ) {
339
+ continue;
340
+ }
341
+
342
+ $results[] = [
343
+ 'id' => $style,
344
+ 'text' => apply_filters( 'ACFFA_icon_prefix_label', $style, $style ),
345
+ 'children' => $icons
346
+ ];
347
+ }
348
+ }
349
+ }
350
+
351
+ $response = [
352
+ 'results' => $results
353
+ ];
354
+
355
+ return $response;
356
+ }
357
+
358
+ public function get_fa_url()
359
+ {
360
+ if ( $this->kit_token ) {
361
+ return 'https://kit.fontawesome.com/' . $this->kit_token . '.js';
362
+ } else {
363
+ $cdn_baseurl = 'https://use.fontawesome.com/releases/v';
364
+ $latest_version = apply_filters( 'ACFFA_get_latest_version', '6.0.0-beta3' );
365
+ $cdn_filepath = '/css/all.css';
366
+
367
+ return $cdn_baseurl . $latest_version . $cdn_filepath;
368
+ }
369
+ }
370
+
371
+ public function get_prefix_label( $label, $prefix )
372
+ {
373
+ $label = empty( $label ) ? 'regular' : $label;
374
+
375
+ switch ( $prefix ) {
376
+ case 'solid':
377
+ $label = __( 'Solid', 'acf-font-awesome' );
378
+ break;
379
+
380
+ case 'brands':
381
+ $label = __( 'Brands', 'acf-font-awesome' );
382
+ break;
383
+
384
+ case 'light':
385
+ $label = __( 'Light', 'acf-font-awesome' );
386
+ break;
387
+
388
+ case 'thin':
389
+ $label = __( 'Thin', 'acf-font-awesome' );
390
+ break;
391
+
392
+ case 'duotone':
393
+ $label = __( 'Duotone', 'acf-font-awesome' );
394
+ break;
395
+
396
+ case 'fak':
397
+ $label = __( 'Uploaded Icons', 'acf-font-awesome' );
398
+ break;
399
+
400
+ case 'regular':
401
+ default:
402
+ $label = __( 'Regular', 'acf-font-awesome' );
403
+ break;
404
+ }
405
+
406
+ return $label;
407
+ }
408
+
409
+ public function get_latest_version( $version, $recheck = false )
410
+ {
411
+ if ( $recheck || ! $version = get_option( 'ACFFA_latest_version' ) ) {
412
+ $remote_get = wp_remote_post( 'https://api.fontawesome.com', [
413
+ 'headers' => [
414
+ 'Content-Type' => 'application/json'
415
+ ],
416
+ 'body' => '{
417
+ "query" : "query { release(version:\"6.x\") { version } }"
418
+ }'
419
+ ] );
420
+
421
+ if ( ! is_wp_error( $remote_get ) ) {
422
+ $response_json = wp_remote_retrieve_body( $remote_get );
423
+
424
+ if ( $response_json ) {
425
+ $response = json_decode( $response_json );
426
+
427
+ if ( isset( $response->data->release->version ) ) {
428
+ $version = $response->data->release->version;
429
+ update_option( 'ACFFA_latest_version_timestamp', time() );
430
+ update_option( 'ACFFA_latest_version', $version );
431
+ }
432
+ }
433
+ }
434
+ }
435
+
436
+ return $version;
437
+ }
438
+
439
+ public function fa_kit_script_attributes( $tag, $handle, $src )
440
+ {
441
+ if ( 'acffa_font-awesome-kit' !== $handle ) {
442
+ return $tag;
443
+ }
444
+
445
+ if ( stristr( $src, 'https://kit.fontawesome.com/' ) ) {
446
+ $tag = str_replace( '<script', '<script crossorigin="anonymous"' , $tag );
447
+ }
448
+
449
+ return $tag;
450
+ }
451
+
452
+ public function js_api_script_attributes( $tag, $handle, $src )
453
+ {
454
+ if ( 'acffa_fontawesome-js-api' !== $handle ) {
455
+ return $tag;
456
+ }
457
+
458
+ $tag = str_replace( '<script', '<script data-auto-replace-svg="false" data-auto-a11y="false" data-auto-add-css="false" data-observe-mutations="false"' , $tag );
459
+
460
+ return $tag;
461
+ }
462
+
463
+ private function maybe_recheck_latest_version()
464
+ {
465
+ if ( ( time() - $this->latest_version_timestamp ) > HOUR_IN_SECONDS ) {
466
+ $latest_version = apply_filters( 'ACFFA_get_latest_version', '6.0.0-beta3', true );
467
+ }
468
+ }
469
+ }
470
+
471
+ new ACFFA_Loader_6();
assets/inc/microtip/README.md ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <p align="center">
2
+ <img src="https://www.dropbox.com/s/lux7521vqphtrsz/microtip.png?raw=1" width="200px"/>
3
+ </p>
4
+
5
+ <p align="center">
6
+ <a href="#">
7
+ <img src="https://img.shields.io/badge/made%20with-love-E760A4.svg" alt="Made with love">
8
+ </a>
9
+ <a href="https://opensource.org/licenses/MIT" target="_blank">
10
+ <img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License">
11
+ </a>
12
+ <a href="https://travis-ci.org/ghosh/microtip" target="_blank">
13
+ <img src="https://api.travis-ci.org/ghosh/microtip.svg" alt="Build Status">
14
+ </a>
15
+ </p>
16
+
17
+ <p align="center">
18
+ Modern, minimal css tooptip library with accessibility baked in. Just `1kb` minified and gzipped.
19
+ </p>
20
+
21
+ ---
22
+
23
+ ![Microtip](https://www.dropbox.com/s/gracjkb2rca2zj6/microtip.gif?raw=1)
24
+
25
+ &nbsp;
26
+
27
+
28
+ ## Table of Contents
29
+ - [Installation](#installation)
30
+ - [Setup](#setup)
31
+ - [Usage](#usage)
32
+ - [Customization](#customization)
33
+ - [Related](#related)
34
+
35
+ &nbsp;
36
+ ## Installation
37
+
38
+ **via npm**
39
+ ```shell
40
+ npm install microtip
41
+ ```
42
+
43
+ **via yarn**
44
+ ```shell
45
+ yarn add microtip
46
+ ```
47
+
48
+ **via CDN**
49
+ ```
50
+ https://unpkg.com/microtip/microtip.css
51
+ ```
52
+
53
+ **direct download**
54
+ ```shell
55
+ curl -o microtip https://github.com/ghosh/microtip/blob/master/microtip.css
56
+ ```
57
+
58
+ &nbsp;
59
+ ## Setup
60
+
61
+ **in PostCSS**
62
+ ```scss
63
+ @import 'microtip';
64
+ ```
65
+
66
+ **in Webpack**
67
+ ```javascript
68
+ import microtip from 'microtip/microtip.css'
69
+ ```
70
+
71
+ **in SCSS**
72
+ ```scss
73
+ @import 'microtip/microtip';
74
+ ```
75
+ Make sure, `node_modules` is included in the `includePaths` setting. You can then directly import the library into your file.
76
+
77
+ &nbsp;
78
+ ## Usage
79
+
80
+ Using the tooltip is incredibly simple. Simply add a `aria-label` and `role="tooltip"` attribute to the element on which you want the tooltip to appear. The tooltip message is the attribute value `aria-label="your message"`. This along with a position modifier is all you need to get going. Example:-
81
+ ```html
82
+ <button aria-label="Hey tooltip!" data-microtip-position="top" role="tooltip">
83
+ ```
84
+
85
+ ### Position Modifiers
86
+
87
+ You can change the direction of the tooltip by adding a `data-microtip-position` attribute. The accepted values of this attribute are:- `top`, `top-left`, `top-right`, `bottom`, `bottom-left`, `bottom-right`, `left` and `right`. Example:-
88
+ ```html
89
+ <button aria-label="Hey tooltip!" data-microtip-position="top-left" role="tooltip">
90
+ ```
91
+
92
+ ### Size Modifiers
93
+
94
+ By default, the tooltip will takeup only the size it requires to show the text. You can specify sizes by adding a `data-microtip-size` attribute. The accepted values include `small`, `medium`, `large` and `fit`. Example:-
95
+ ```html
96
+ <button aria-label="This is a decently long text!" data-microtip-position="top-left" data-microtip-size="medium" role="tooltip">
97
+ ```
98
+
99
+ **Note** - `fit` sets the width of the tooltip to be the same as the width on the element. It only works along with the `top` and `bottom` position modifiers.
100
+
101
+ &nbsp;
102
+ ## Customization
103
+
104
+ Microtip uses **css variables**, which allows you to customize the behavior of the tooltip as per your needs.
105
+
106
+
107
+ | Variable | Description | Default Value |
108
+ |----------------------------------|----------------------------------------------------|---------------|
109
+ | `--microtip-transition-duration` | Specifies the duration of the tootltip transition | `.18s` |
110
+ | `--microtip-transition-delay` | The delay on hover before showing the tooltip | `0s` |
111
+ | `--microtip-transition-easing` | The easing applied while transitioning the tooltip | `ease-in-out` |
112
+ | `--microtip-font-size` | Sets the font size of the text in tooltip | `13px` |
113
+ | `--microtip-font-weight` | The font weight of the text in tooltip | `normal` |
114
+ | `--microtip-text-transform` | Controls the casing of the text | `none` |
115
+
116
+ &nbsp;
117
+
118
+ Example:-
119
+ ```css
120
+ :root {
121
+ --microtip-transition-duration: 0.5s;
122
+ --microtip-transition-delay: 1s;
123
+ --microtip-transition-easing: ease-out;
124
+ --microtip-font-size: 13px;
125
+ --microtip-font-weight: bold;
126
+ --microtip-text-transform: uppercase;
127
+ }
128
+ ```
129
+
130
+ The above code will cause all the tooltips to transition over `0.5s` while applying an easing of type `ease-out` after a delay of `1s`. The text will be `bold` and `uppercase` and have a font size of `13px`.
131
+
132
+ You could also customize the tooltip for individual instances by using a selector more specific than `:root`. Example:-
133
+
134
+ ```css
135
+ .tooltip {
136
+ --microtip-transition-duration: 0.2s;
137
+ --microtip-transition-delay: 0s;
138
+ --microtip-transition-easing: ease-in-out;
139
+ }
140
+ ```
141
+
142
+ The above code would only affect the tooltips shown on any element with the `tooltip` class.
143
+
144
+ For more on css variables see [here](https://css-tricks.com/now-css-custom-properties-thing-value-parts-can-changed-individually/)
145
+
146
+
147
+ &nbsp;
148
+ ## Related
149
+ - [Micromodal](https://github.com/Ghosh/micromodal) - Tiny javascript library for creating accessible modal dialogs
150
+
151
+
152
+ &nbsp;
153
+ ## Credits
154
+ - [Claudio Holanda](https://twitter.com/kazzkiq) - Whose work inspired this project
155
+
156
+ &nbsp;
157
+
158
+ <p align="center">✌️</p>
159
+ <p align="center">
160
+ <sub><sup>A little project by <a href="https://twitter.com/_ighosh">@i_ghosh</a></sup></sub>
161
+ </p>
assets/inc/microtip/license.md ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Indrashish Ghosh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
assets/inc/microtip/microtip.min.css ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* -------------------------------------------------------------------
2
+ Microtip
3
+
4
+ Modern, lightweight css-only tooltips
5
+ Just 1kb minified and gzipped
6
+
7
+ @author Ghosh
8
+ @package Microtip
9
+
10
+ ----------------------------------------------------------------------
11
+ 1. Base Styles
12
+ 2. Direction Modifiers
13
+ 3. Position Modifiers
14
+ --------------------------------------------------------------------*/
15
+ [aria-label][role~="tooltip"]{position:relative}[aria-label][role~="tooltip"]::before,[aria-label][role~="tooltip"]::after{transform:translate3d(0,0,0);-webkit-backface-visibility:hidden;backface-visibility:hidden;will-change:transform;opacity:0;pointer-events:none;transition:all var(--microtip-transition-duration,.18s) var(--microtip-transition-easing,ease-in-out) var(--microtip-transition-delay,0s);position:absolute;box-sizing:border-box;z-index:10;transform-origin:top}[aria-label][role~="tooltip"]::before{background-size:100% auto!important;content:""}[aria-label][role~="tooltip"]::after{background:rgba(17,17,17,.9);border-radius:4px;color:#fff;content:attr(aria-label);font-size:var(--microtip-font-size,13px);font-weight:var(--microtip-font-weight,normal);text-transform:var(--microtip-text-transform,none);padding:.5em 1em;white-space:nowrap;box-sizing:content-box}[aria-label][role~="tooltip"]:hover::before,[aria-label][role~="tooltip"]:hover::after,[aria-label][role~="tooltip"]:focus::before,[aria-label][role~="tooltip"]:focus::after{opacity:1;pointer-events:auto}[role~="tooltip"][data-microtip-position|="top"]::before{background:url(data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2236px%22%20height%3D%2212px%22%3E%3Cpath%20fill%3D%22rgba%2817,%2017,%2017,%200.9%29%22%20transform%3D%22rotate%280%29%22%20d%3D%22M2.658,0.000%20C-13.615,0.000%2050.938,0.000%2034.662,0.000%20C28.662,0.000%2023.035,12.002%2018.660,12.002%20C14.285,12.002%208.594,0.000%202.658,0.000%20Z%22/%3E%3C/svg%3E) no-repeat;height:6px;width:18px;margin-bottom:5px}[role~="tooltip"][data-microtip-position|="top"]::after{margin-bottom:11px}[role~="tooltip"][data-microtip-position|="top"]::before{transform:translate3d(-50%,0,0);bottom:100%;left:50%}[role~="tooltip"][data-microtip-position|="top"]:hover::before{transform:translate3d(-50%,-5px,0)}[role~="tooltip"][data-microtip-position|="top"]::after{transform:translate3d(-50%,0,0);bottom:100%;left:50%}[role~="tooltip"][data-microtip-position="top"]:hover::after{transform:translate3d(-50%,-5px,0)}[role~="tooltip"][data-microtip-position="top-left"]::after{transform:translate3d(calc(-100% + 16px),0,0);bottom:100%}[role~="tooltip"][data-microtip-position="top-left"]:hover::after{transform:translate3d(calc(-100% + 16px),-5px,0)}[role~="tooltip"][data-microtip-position="top-right"]::after{transform:translate3d(calc(0% + -16px),0,0);bottom:100%}[role~="tooltip"][data-microtip-position="top-right"]:hover::after{transform:translate3d(calc(0% + -16px),-5px,0)}[role~="tooltip"][data-microtip-position|="bottom"]::before{background:url(data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2236px%22%20height%3D%2212px%22%3E%3Cpath%20fill%3D%22rgba%2817,%2017,%2017,%200.9%29%22%20transform%3D%22rotate%28180%2018%206%29%22%20d%3D%22M2.658,0.000%20C-13.615,0.000%2050.938,0.000%2034.662,0.000%20C28.662,0.000%2023.035,12.002%2018.660,12.002%20C14.285,12.002%208.594,0.000%202.658,0.000%20Z%22/%3E%3C/svg%3E) no-repeat;height:6px;width:18px;margin-top:5px;margin-bottom:0}[role~="tooltip"][data-microtip-position|="bottom"]::after{margin-top:11px}[role~="tooltip"][data-microtip-position|="bottom"]::before{transform:translate3d(-50%,-10px,0);bottom:auto;left:50%;top:100%}[role~="tooltip"][data-microtip-position|="bottom"]:hover::before{transform:translate3d(-50%,0,0)}[role~="tooltip"][data-microtip-position|="bottom"]::after{transform:translate3d(-50%,-10px,0);top:100%;left:50%}[role~="tooltip"][data-microtip-position="bottom"]:hover::after{transform:translate3d(-50%,0,0)}[role~="tooltip"][data-microtip-position="bottom-left"]::after{transform:translate3d(calc(-100% + 16px),-10px,0);top:100%}[role~="tooltip"][data-microtip-position="bottom-left"]:hover::after{transform:translate3d(calc(-100% + 16px),0,0)}[role~="tooltip"][data-microtip-position="bottom-right"]::after{transform:translate3d(calc(0% + -16px),-10px,0);top:100%}[role~="tooltip"][data-microtip-position="bottom-right"]:hover::after{transform:translate3d(calc(0% + -16px),0,0)}[role~="tooltip"][data-microtip-position="left"]::before,[role~="tooltip"][data-microtip-position="left"]::after{bottom:auto;left:auto;right:100%;top:50%;transform:translate3d(10px,-50%,0)}[role~="tooltip"][data-microtip-position="left"]::before{background:url(data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2212px%22%20height%3D%2236px%22%3E%3Cpath%20fill%3D%22rgba%2817,%2017,%2017,%200.9%29%22%20transform%3D%22rotate%28-90%2018%2018%29%22%20d%3D%22M2.658,0.000%20C-13.615,0.000%2050.938,0.000%2034.662,0.000%20C28.662,0.000%2023.035,12.002%2018.660,12.002%20C14.285,12.002%208.594,0.000%202.658,0.000%20Z%22/%3E%3C/svg%3E) no-repeat;height:18px;width:6px;margin-right:5px;margin-bottom:0}[role~="tooltip"][data-microtip-position="left"]::after{margin-right:11px}[role~="tooltip"][data-microtip-position="left"]:hover::before,[role~="tooltip"][data-microtip-position="left"]:hover::after{transform:translate3d(0,-50%,0)}[role~="tooltip"][data-microtip-position="right"]::before,[role~="tooltip"][data-microtip-position="right"]::after{bottom:auto;left:100%;top:50%;transform:translate3d(-10px,-50%,0)}[role~="tooltip"][data-microtip-position="right"]::before{background:url(data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2212px%22%20height%3D%2236px%22%3E%3Cpath%20fill%3D%22rgba%2817,%2017,%2017,%200.9%29%22%20transform%3D%22rotate%2890%206%206%29%22%20d%3D%22M2.658,0.000%20C-13.615,0.000%2050.938,0.000%2034.662,0.000%20C28.662,0.000%2023.035,12.002%2018.660,12.002%20C14.285,12.002%208.594,0.000%202.658,0.000%20Z%22/%3E%3C/svg%3E) no-repeat;height:18px;width:6px;margin-bottom:0;margin-left:5px}[role~="tooltip"][data-microtip-position="right"]::after{margin-left:11px}[role~="tooltip"][data-microtip-position="right"]:hover::before,[role~="tooltip"][data-microtip-position="right"]:hover::after{transform:translate3d(0,-50%,0)}[role~="tooltip"][data-microtip-size="small"]::after{white-space:initial;width:80px}[role~="tooltip"][data-microtip-size="medium"]::after{white-space:initial;width:150px}[role~="tooltip"][data-microtip-size="large"]::after{white-space:initial;width:260px}
assets/js/input-v6.js ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function($){
2
+ function update_preview( value, parent ) {
3
+ if ( ! value ) {
4
+ $( '.acf-field-setting-fa_live_preview .acf-input', parent ).empty();
5
+ $( '.icon_preview', parent ).empty();
6
+ } else {
7
+ try {
8
+ var iconJson = $.parseJSON( value );
9
+ if ( 'object' === typeof iconJson ) {
10
+ if ( 'fak' == iconJson.style ) {
11
+ $( '.acf-field-setting-fa_live_preview .acf-input', parent ).html( '<i class="' + iconJson.style + ' fa-' + iconJson.id + ' fa-fw" aria-hidden="true"></i>' );
12
+ $( '.icon_preview', parent ).html( '<i class="' + iconJson.style + ' fa-' + iconJson.id + ' fa-fw" aria-hidden="true"></i>' );
13
+ } else {
14
+ $( '.acf-field-setting-fa_live_preview .acf-input', parent ).html( '<i class="fa-' + iconJson.style + ' fa-' + iconJson.id + ' fa-fw" aria-hidden="true"></i>' );
15
+ $( '.icon_preview', parent ).html( '<i class="fa-' + iconJson.style + ' fa-' + iconJson.id + ' fa-fw" aria-hidden="true"></i>' );
16
+ }
17
+ $( '.icon_preview', parent ).removeClass('v5-compat-alert show-alert');
18
+ }
19
+ } catch( err ) {
20
+ return false;
21
+ }
22
+ }
23
+ }
24
+
25
+ function select2_init_args( element, parent ) {
26
+ return {
27
+ key : $( parent ).data('key'),
28
+ allowNull : $( element ).data('allow_null'),
29
+ ajax : 1,
30
+ ajaxAction : 'acf/fields/font-awesome/query'
31
+ }
32
+ }
33
+
34
+ function prefixLookup( prefix ) {
35
+ switch ( prefix ) {
36
+ case 'fas':
37
+ prefix = 'solid';
38
+ break;
39
+
40
+ case 'far':
41
+ prefix = 'regular';
42
+ break;
43
+
44
+ case 'fal':
45
+ prefix = 'light';
46
+ break;
47
+
48
+ case 'fad':
49
+ prefix = 'duotone';
50
+ break;
51
+
52
+ case 'fab':
53
+ prefix = 'brands';
54
+ break;
55
+ }
56
+
57
+ return prefix;
58
+ }
59
+
60
+ function iconLookup( icon ) {
61
+ if ( 'FontAwesome' in window ) {
62
+
63
+ if ( 0 === icon.indexOf( 'fa-' ) ) {
64
+ var name = icon.split( 'fa-' ).pop();
65
+
66
+ if ( name.indexOf( '-o' ) > -1 ) {
67
+ if ( name.lastIndexOf( '-o' ) === name.length - 2 ) {
68
+ name = name.slice( 0, -2 );
69
+ }
70
+ }
71
+
72
+ var iconDetails = window.FontAwesome.findIconDefinition({iconName: name });
73
+
74
+ if ( undefined === iconDetails ) {
75
+ var iconDetails = window.FontAwesome.findIconDefinition({prefix: 'fab', iconName: name });
76
+ }
77
+
78
+ if ( undefined !== iconDetails ) {
79
+ var prefix = prefixLookup( iconDetails.prefix ),
80
+ label = iconDetails.iconName.replace( '-', ' ' ),
81
+ unicode = iconDetails.icon[3];
82
+
83
+ return {
84
+ value : '{ "style" : "' + prefix + '", "id" : "' + iconDetails.iconName + '", "label" : "' + label + '", "unicode" : "' + unicode + '" }',
85
+ label : label
86
+ };
87
+ }
88
+ } else {
89
+ var prefix = icon.substring( 0, 3 ),
90
+ name = icon.split( 'fa-' ).pop();
91
+
92
+ if ( 'fal' == prefix || 'fad' == prefix ) {
93
+ return;
94
+ }
95
+
96
+ var iconDetails = window.FontAwesome.findIconDefinition({prefix: prefix, iconName: name });
97
+
98
+ if ( undefined !== iconDetails ) {
99
+ var prefix = prefixLookup( iconDetails.prefix ),
100
+ label = iconDetails.iconName.replace( '-', ' ' ),
101
+ unicode = iconDetails.icon[3];
102
+
103
+ return {
104
+ value : '{ "style" : "' + prefix + '", "id" : "' + iconDetails.iconName + '", "label" : "' + label + '", "unicode" : "' + unicode + '" }',
105
+ label : label
106
+ };
107
+ }
108
+ }
109
+ }
110
+ }
111
+
112
+ function select2_init( fa_field ) {
113
+ if ( ACFFA.v5_compat_mode && '[v5-compat-lookup]' == $( 'option:selected', fa_field ).text() ) {
114
+ var iconData = iconLookup( $( fa_field ).val() );
115
+
116
+ if ( iconData ) {
117
+ $( 'option:selected', fa_field ).val( iconData.value );
118
+ $( 'option:selected', fa_field ).text( iconData.label );
119
+ $( fa_field ).val( iconData.value );
120
+ $( fa_field ).siblings('.v5-compat-message').hide();
121
+ $( fa_field ).siblings('.icon_preview').removeClass('v5-compat-alert show-alert');
122
+ } else {
123
+ $( 'option:selected', fa_field ).val( false );
124
+ $( 'option:selected', fa_field ).text( '' );
125
+ }
126
+ }
127
+ var $select = $( fa_field );
128
+ var parent = $( $select ).closest('.acf-field-font-awesome');
129
+
130
+ update_preview( $select.val(), parent );
131
+
132
+ acf.select2.init( $select, select2_init_args( fa_field, parent ), parent );
133
+ }
134
+
135
+ acf.add_action( 'select2_init', function( $input, args, settings, $field ) {
136
+ if ( $field instanceof jQuery && $field.hasClass('fontawesome-edit') ) {
137
+ $field.addClass('select2_initalized');
138
+ }
139
+ });
140
+
141
+ // Add our classes to FontAwesome select2 fields
142
+ acf.add_filter( 'select2_args', function( args, $select, settings, $field ) {
143
+ if ( $select.hasClass('select2-fontawesome') ) {
144
+ args.dropdownCssClass = 'fa-select2-drop fa' + ACFFA.major_version;
145
+ args.containerCssClass = 'fa-select2 fa' + ACFFA.major_version;
146
+ args.escapeMarkup = function( markup ) {
147
+ if (typeof markup !== 'string') {
148
+ return markup;
149
+ }
150
+ return acf.escHtml( markup );
151
+ }
152
+ args.ajax.delay = 400;
153
+
154
+ if ( ! $select.hasClass('custom-icon-set') ) {
155
+ args.minimumInputLength = 1;
156
+ }
157
+ }
158
+
159
+ return args;
160
+ });
161
+
162
+ // Update FontAwesome field previews in field create area
163
+ acf.add_action( 'open_field/type=font-awesome change_field_type/type=font-awesome', function( $el ) {
164
+ var $field_objects = $('.acf-field-object[data-type="font-awesome"]');
165
+
166
+ $field_objects.each( function( index, field_object ) {
167
+ update_preview( $( 'select.fontawesome-create', field_object ).val(), field_object );
168
+
169
+ if ( $( '.acf-field[data-name="icon_sets"] input[type="checkbox"][value="custom"]:checked', field_object ).length ) {
170
+ $( '.acf-field-setting-custom_icon_set', field_object ).show();
171
+ } else {
172
+ $( '.acf-field-setting-custom_icon_set', field_object ).hide();
173
+ }
174
+
175
+ });
176
+ });
177
+
178
+ // Uncheck standard icon set choices if 'custom icon set' is checked, and show the custom icon set select box
179
+ $( document ).on( 'change', '.acf-field[data-name="icon_sets"] input[type="checkbox"]', function() {
180
+ var parent = $( this ).closest('.acf-field-object-font-awesome');
181
+ if ( $( this ).is('[value="custom"]') && $( this ).is(':checked') ) {
182
+ $( 'input[type="checkbox"]:not([value="custom"])', parent ).prop('checked', false);
183
+ $( '.acf-field-setting-custom_icon_set', parent ).show();
184
+ } else {
185
+ $( 'input[type="checkbox"][value="custom"]', parent ).prop('checked', false);
186
+ $( '.acf-field-setting-custom_icon_set', parent ).hide();
187
+ }
188
+ });
189
+
190
+ // Handle new menu items with FontAwesome fields assigned to them
191
+ $( document ).on( 'menu-item-added', function( event, $menuMarkup ) {
192
+ var $fa_fields = $( 'select.fontawesome-edit:not(.select2_initalized)', $menuMarkup );
193
+
194
+ if ( $fa_fields.length ) {
195
+ $fa_fields.each( function( index, fa_field ) {
196
+ select2_init( fa_field );
197
+ });
198
+ }
199
+ });
200
+
201
+ // Update FontAwesome field previews and init select2 in field edit area
202
+ acf.add_action( 'ready_field/type=font-awesome append_field/type=font-awesome show_field/type=font-awesome', function( $el ) {
203
+ var $fa_fields = $( 'select.fontawesome-edit:not(.select2_initalized)', $el );
204
+
205
+ if ( $fa_fields.length ) {
206
+ $fa_fields.each( function( index, fa_field ) {
207
+ select2_init( fa_field );
208
+ });
209
+ }
210
+ });
211
+
212
+ // Update FontAwesome field previews when value changes
213
+ $( document ).on( 'select2:select select2:clear', 'select.select2-fontawesome', function() {
214
+ var $input = $( this );
215
+
216
+ if ( $input.hasClass('fontawesome-create') ) {
217
+ update_preview( $input.val(), $input.closest('.acf-field-object') );
218
+ $('.acf-field-setting-default_label input').val( $( 'option:selected', $input ).html() );
219
+ }
220
+
221
+ if ( $input.hasClass('fontawesome-edit') ) {
222
+ update_preview( $input.val(), $input.closest('.acf-field-font-awesome') );
223
+ }
224
+ });
225
+
226
+ })(jQuery);
assets/js/{settings.js → settings-v5.js} RENAMED
@@ -4,9 +4,22 @@
4
  function evaluate_pro_visibility() {
5
  selected_major_version = $('#acffa_major_version').val();
6
 
7
- if ( 5 == selected_major_version ) {
 
 
 
 
 
 
 
 
 
 
8
  $('.acffa_row.pro_icons').show();
9
  } else {
 
 
 
10
  $('.acffa_row.pro_icons').hide();
11
  $('#pro_icons').prop( 'checked', false );
12
  }
4
  function evaluate_pro_visibility() {
5
  selected_major_version = $('#acffa_major_version').val();
6
 
7
+ if ( selected_major_version == 6 ) {
8
+ $('.acffa_row.api_key').show();
9
+ $('.acffa_row.kit').show();
10
+ $('.acffa_row.v5_compatibility_mode').show();
11
+ $('.acffa_row.pro_icons').hide();
12
+ $('.acffa_row.api_key .validation-result span').hide();
13
+ $('.acffa_row.api_key .validation-result span.save').show();
14
+ } else if ( selected_major_version == 5 ) {
15
+ $('.acffa_row.api_key').hide();
16
+ $('.acffa_row.kit').hide();
17
+ $('.acffa_row.v5_compatibility_mode').hide();
18
  $('.acffa_row.pro_icons').show();
19
  } else {
20
+ $('.acffa_row.api_key').hide();
21
+ $('.acffa_row.kit').hide();
22
+ $('.acffa_row.v5_compatibility_mode').hide();
23
  $('.acffa_row.pro_icons').hide();
24
  $('#pro_icons').prop( 'checked', false );
25
  }
assets/js/settings-v6.js ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function($){
2
+ var old_major_version = false,
3
+ selected_major_version = false;
4
+ function evaluate_field_visibility() {
5
+ selected_major_version = $('#acffa_major_version').val();
6
+
7
+ if ( selected_major_version == 6 ) {
8
+ $('.acffa_row.api_key').show();
9
+ $('.acffa_row.kit').show();
10
+ $('.acffa_row.v5_compatibility_mode').show();
11
+ $('.acffa_row.pro_icons').hide();
12
+ } else if ( selected_major_version == 5 ) {
13
+ $('.acffa_row.api_key').hide();
14
+ $('.acffa_row.kit').hide();
15
+ $('.acffa_row.v5_compatibility_mode').hide();
16
+ $('.acffa_row.pro_icons').show();
17
+ } else {
18
+ $('.acffa_row.api_key').hide();
19
+ $('.acffa_row.kit').hide();
20
+ $('.acffa_row.pro_icons').hide();
21
+ $('#pro_icons').prop( 'checked', false );
22
+ }
23
+ }
24
+
25
+ function build_kits_table() {
26
+ if ( ACFFA.kits.length ) {
27
+ ACFFA.kits.sort((a, b) => (a.name > b.name) ? 1 : -1);
28
+
29
+ var kitTmpl = wp.template( 'fa-kit' ),
30
+ hasPro = false;
31
+
32
+ $.each( ACFFA.kits, function( index, kit ) {
33
+ if ( ! hasPro && 'pro' == kit.licenseSelected ) {
34
+ hasPro = true;
35
+ }
36
+ kit.checked = ACFFA.acffa_kit == kit.token ? 'checked' : '';
37
+ kit.customIconCount = kit.iconUploads.length;
38
+ var newKit = kitTmpl( kit );
39
+ $('#available_kits tbody').append( newKit );
40
+ });
41
+
42
+ if ( hasPro ) {
43
+ $('#acffa_kit_has_pro').val( 1 );
44
+ }
45
+ } else {
46
+ $('.no_kits_found').show();
47
+ }
48
+ }
49
+
50
+ function set_token_status() {
51
+ var value = $('#acffa_api_key').val(),
52
+ validationLabels = $('.acffa_row.api_key .validation-result');
53
+
54
+ $( 'span', validationLabels ).hide();
55
+
56
+ if ( ! value ) {
57
+ $( '.empty', validationLabels ).show();
58
+ } else if ( 'error' == ACFFA.api_key_status ) {
59
+ $( '.error', validationLabels ).show();
60
+ } else if ( 'success' == ACFFA.api_key_status ) {
61
+ $( '.success', validationLabels ).show();
62
+ } else {
63
+ $( '.save', validationLabels ).show();
64
+ }
65
+ }
66
+
67
+ $( document ).ready( function() {
68
+ old_major_version = $('#acffa_major_version').val();
69
+ evaluate_field_visibility();
70
+ set_token_status();
71
+ build_kits_table();
72
+ });
73
+
74
+ $('#acffa_api_key').on( 'keyup', function() {
75
+ $('.acffa_row.api_key .validation-result span').hide();
76
+ if ( $( this ).val() ) {
77
+ $('.acffa_row.api_key .validation-result span.save').show();
78
+ } else {
79
+ $('.acffa_row.api_key .validation-result span.empty').show();
80
+ }
81
+ });
82
+
83
+ $('#acffa_major_version').on( 'change', function() {
84
+ evaluate_field_visibility();
85
+
86
+ var $iconSetBuilder = $('.custom-icon-set');
87
+
88
+ if ( old_major_version !== selected_major_version ) {
89
+ $iconSetBuilder.hide();
90
+ $('.icon-builder-complete-changes-notice').show();
91
+ } else {
92
+ $iconSetBuilder.show();
93
+ $('.icon-builder-complete-changes-notice').hide();
94
+ }
95
+ });
96
+
97
+ function strEscape( string ) {
98
+ var htmlEscapes = {
99
+ '&' : '&amp;',
100
+ '<' : '&lt;',
101
+ '>' : '&gt;',
102
+ '"' : '&quot;',
103
+ "'" : '&#39;'
104
+ };
105
+ return ('' + string).replace(/[&<>"']/g, function (chr) {
106
+ return htmlEscapes[chr];
107
+ });
108
+ }
109
+ function strUnescape( string ) {
110
+ var htmlUnescapes = {
111
+ '&amp;' : '&',
112
+ '&lt;' : '<',
113
+ '&gt;' : '>',
114
+ '&quot;' : '"',
115
+ '&#39;' : "'"
116
+ };
117
+ return ('' + string).replace(/[&<>"']/g, function (chr) {
118
+ return htmlUnescapes[chr];
119
+ });
120
+ }
121
+ function escHtml( string ) {
122
+ return ('' + string).replace(/<script|<\/script/g, function (html) {
123
+ return strEscape(html);
124
+ });
125
+ }
126
+
127
+ $('select#icon_chooser').select2({
128
+ width : '100%',
129
+ ajax : {
130
+ url : ajaxurl,
131
+ dataType : 'json',
132
+ delay : 400,
133
+ type : 'post',
134
+ data : function( params ) {
135
+ return {
136
+ action : 'acf/fields/font-awesome/query',
137
+ s : params.term,
138
+ paged : 1,
139
+ nonce : ACFFA.acf_nonce,
140
+ field_key : 'icon_set_builder',
141
+ fa_version : ACFFA.acffa_search_version,
142
+ fa_license : ACFFA.acffa_search_license,
143
+ custom_icons : ACFFA.acffa_custom_icons
144
+ }
145
+ }
146
+ },
147
+ escapeMarkup : function( markup ) {
148
+ if (typeof markup !== 'string') {
149
+ return markup;
150
+ }
151
+ return escHtml( markup );
152
+ },
153
+ dropdownCssClass : 'fa-select2-drop fa6',
154
+ containerCssClass : 'fa-select2 fa6',
155
+ minimumInputLength : 1,
156
+ placeholder : ACFFA.search_string
157
+ });
158
+
159
+ $('select#icon_chooser').on('select2:select', function (e) {
160
+ var data = e.params.data,
161
+ iconJson = JSON.parse( data.id );
162
+
163
+ $('select#acffa_new_icon_set').append( '<option value="' + strEscape( data.id ) + '" data-label="' + iconJson.label + '" selected>' + iconJson.label + '</option>' );
164
+ $('.acffa_row.custom-icon-set .selected-icons').append( '<div class="new-icon" data-icon-json="' + strEscape( data.id ) + '" data-label="' + iconJson.text + '">' + data.text + '</div>' );
165
+ $( this ).val( null ).trigger('change');
166
+ });
167
+
168
+ $( '.existing-custom-icon-sets .edit-icon-set' ).on( 'click', function( e ) {
169
+ e.preventDefault();
170
+
171
+ $('.acffa_row.custom-icon-set .selected-icons').empty();
172
+ $('select#acffa_new_icon_set').empty();
173
+
174
+ var parent = $( this ).closest('.icon-set'),
175
+ label = $( parent ).data('set-label'),
176
+ $iconList = $( 'li.icon', parent );
177
+
178
+ $iconList.each( function( index, icon ) {
179
+ var iconJson = $( icon ).data('icon-json');
180
+
181
+ $('select#acffa_new_icon_set').append('<option value="' + strEscape( JSON.stringify( iconJson ) ) + '" data-label="' + iconJson.label + '" selected>' + iconJson.label + '</option>');
182
+ if ( 'fak' == iconJson.style ) {
183
+ $('.acffa_row.custom-icon-set .selected-icons').append( '<div class="new-icon" data-icon-json="' + strEscape( JSON.stringify( iconJson ) ) + '" data-label="' + iconJson.label + '"><i class="' + iconJson.style + ' fa-' + iconJson.id + ' fa-fw"></i>' + iconJson.label + '</div>' );
184
+ } else {
185
+ $('.acffa_row.custom-icon-set .selected-icons').append( '<div class="new-icon" data-icon-json="' + strEscape( JSON.stringify( iconJson ) ) + '" data-label="' + iconJson.label + '"><i class="fa-' + iconJson.style + ' fa-' + iconJson.id + ' fa-fw"></i>' + iconJson.label + '</div>' );
186
+ }
187
+ });
188
+
189
+ $('#acffa_new_icon_set_label').val( label );
190
+ });
191
+
192
+ $( '.existing-custom-icon-sets .view-icon-list' ).on( 'click', function( e ) {
193
+ e.preventDefault();
194
+
195
+ var parent = $( this ).closest('.icon-set');
196
+ $( parent ).find('.icon-list').toggle();
197
+ });
198
+
199
+ $( '.existing-custom-icon-sets .delete-icon-set' ).on( 'click', function( e ) {
200
+ e.preventDefault();
201
+
202
+ var result = confirm( ACFFA.confirm_delete );
203
+ if ( result ) {
204
+ var nonce = $( this ).data('nonce'),
205
+ iconSetName = $( this ).data('icon-set-name');
206
+
207
+ $.post(
208
+ ajaxurl,
209
+ {
210
+ 'action' : 'ACFFA_delete_icon_set',
211
+ 'nonce' : nonce,
212
+ 'icon_set_name' : iconSetName
213
+ },
214
+ function( response_msg ) {
215
+ if ( 'success' == response_msg ) {
216
+ $('.icon-set[data-set-name="' + iconSetName + '"]').remove();
217
+ } else {
218
+ alert( ACFFA.delete_fail );
219
+ }
220
+ }
221
+ );
222
+ }
223
+ });
224
+
225
+ $( document ).on( 'click', '.selected-icons .new-icon', function() {
226
+ if ( confirm( ACFFA.remove_icon ) ) {
227
+ var label = $( this ).data('label');
228
+ $('select#acffa_new_icon_set option[data-label="' + label + '"]').remove();
229
+ $( this ).remove();
230
+ }
231
+ } );
232
+ })(jQuery);
assets/js/templates/tmpl-fa-kit.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/html" id="tmpl-fa-kit">
2
+ <tr>
3
+ <td><input type="radio" name="acffa_settings[acffa_kit]" {{data.checked}} value="{{data.token}}"></td>
4
+ <td>{{data.name}}</td>
5
+ <td>{{data.token}}</td>
6
+ <td>{{data.status}}</td>
7
+ <td>{{data.licenseSelected}}</td>
8
+ <td>{{data.technologySelected}}</td>
9
+ <td>{{data.customIconCount}}</td>
10
+ <td>{{data.version}}</td>
11
+ </tr>
12
+ </script>
fields/acf-font-awesome-v5.php CHANGED
@@ -56,28 +56,48 @@ if ( ! class_exists( 'acf_field_font_awesome' ) ) :
56
 
57
  public function render_field_settings( $field )
58
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  $icon_sets_args = array(
60
  'label' => __( 'Icon Sets', 'acf-font-awesome' ),
61
  'instructions' => __( 'Specify which icon set(s) to load', 'acf-font-awesome' ),
62
  'type' => 'checkbox',
63
  'name' => 'icon_sets',
64
- 'value' => ! empty( $field['icon_sets'] ) ? $field['icon_sets'] : 'far'
65
  );
66
 
67
- if ( version_compare( ACFFA_MAJOR_VERSION, 5, '>=' ) ) {
68
- $icon_sets_args['choices'] = array(
69
  'fas' => __( 'Solid', 'acf-font-awesome' ),
70
  'far' => __( 'Regular', 'acf-font-awesome' ),
71
  'fal' => __( 'Light (FontAwesome Pro License Required)', 'acf-font-awesome' ),
72
  'fad' => __( 'Duotone (FontAwesome Pro License Required)', 'acf-font-awesome' ),
73
  'fab' => __( 'Brands', 'acf-font-awesome' ),
74
  'custom' => __( 'Custom Icon Set', 'acf-font-awesome' )
75
- );
 
76
  } else {
77
  $icon_sets_args['choices'] = array(
78
  'all' => __( 'All Icons', 'acf-font-awesome' ),
79
  'custom' => __( 'Custom Icon Set', 'acf-font-awesome' )
80
  );
 
81
  }
82
  acf_render_field_setting( $field, $icon_sets_args );
83
 
@@ -199,7 +219,8 @@ if ( ! class_exists( 'acf_field_font_awesome' ) ) :
199
  $field['class'] = $select2_class . ' select2-fontawesome fontawesome-edit';
200
 
201
  $icons = $this->get_icons('list');
202
- if ( version_compare( ACFFA_MAJOR_VERSION, 5, '<' ) ) :
 
203
  if ( $select_value && isset( $icons[ $select_value ] ) ) :
204
  $field['choices'][ $select_value ] = $icons[ $select_value ];
205
  elseif ( ( ! $select_value || ! isset( $icons[ $select_value ] ) ) && ! $field['allow_null'] ) :
@@ -207,7 +228,7 @@ if ( ! class_exists( 'acf_field_font_awesome' ) ) :
207
  $default_key = key( $icons );
208
  $field['choices'][ $default_key ] = $default_value;
209
  endif;
210
- else :
211
  $prefix = substr( $select_value, 0, 3 );
212
  if ( $select_value && isset( $icons[ $prefix ][ $select_value ] ) ) :
213
  $field['choices'][ $select_value ] = htmlentities( $icons[ $prefix ][ $select_value ] );
@@ -274,6 +295,11 @@ if ( ! class_exists( 'acf_field_font_awesome' ) ) :
274
  return $value;
275
  }
276
 
 
 
 
 
 
277
  if ( ! $this->icons ) {
278
  $this->get_icons();
279
  }
56
 
57
  public function render_field_settings( $field )
58
  {
59
+ if ( apply_filters( 'ACFFA_show_fontawesome_pro_blurbs', true ) ) {
60
+ switch( ACFFA_MAJOR_VERSION ) {
61
+ case '5':
62
+ $carrot_icon = 'fas fa-carrot';
63
+ break;
64
+
65
+ default:
66
+ $carrot_icon = 'fa fa-tree';
67
+ break;
68
+ }
69
+ acf_render_field_setting( $field, [
70
+ 'label' => __( 'Get FontAwesome Pro', 'acf-font-awesome' ),
71
+ 'message' => '<p>' . __( 'Support this plugin and get more icons across more styles plus helpful services, regular updates, a lifetime license, and actual human support.', 'acf-font-awesome' ) . '</p>' . '<a class="get-acfpro-btn" target="_blank" href="https://fontawesome.com/referral?a=0032f3e781"><i class="' . $carrot_icon . '"></i>' . __( 'Upgrade to Font Awesome Pro!', 'acf-font-awesome' ) . '</a>',
72
+ 'type' => 'message',
73
+ 'name' => 'get-fontawesome-pro',
74
+ 'class' => 'get-fontawesome-pro'
75
+ ] );
76
+ }
77
+
78
  $icon_sets_args = array(
79
  'label' => __( 'Icon Sets', 'acf-font-awesome' ),
80
  'instructions' => __( 'Specify which icon set(s) to load', 'acf-font-awesome' ),
81
  'type' => 'checkbox',
82
  'name' => 'icon_sets',
 
83
  );
84
 
85
+ if ( version_compare( ACFFA_MAJOR_VERSION, 5, '=' ) ) {
86
+ $icon_sets_args['choices'] = [
87
  'fas' => __( 'Solid', 'acf-font-awesome' ),
88
  'far' => __( 'Regular', 'acf-font-awesome' ),
89
  'fal' => __( 'Light (FontAwesome Pro License Required)', 'acf-font-awesome' ),
90
  'fad' => __( 'Duotone (FontAwesome Pro License Required)', 'acf-font-awesome' ),
91
  'fab' => __( 'Brands', 'acf-font-awesome' ),
92
  'custom' => __( 'Custom Icon Set', 'acf-font-awesome' )
93
+ ];
94
+ $icon_sets_args['value'] = ! empty( $field['icon_sets'] ) ? $field['icon_sets'] : 'far';
95
  } else {
96
  $icon_sets_args['choices'] = array(
97
  'all' => __( 'All Icons', 'acf-font-awesome' ),
98
  'custom' => __( 'Custom Icon Set', 'acf-font-awesome' )
99
  );
100
+ $icon_sets_args['value'] = ! empty( $field['icon_sets'] ) ? $field['icon_sets'] : 'all';
101
  }
102
  acf_render_field_setting( $field, $icon_sets_args );
103
 
219
  $field['class'] = $select2_class . ' select2-fontawesome fontawesome-edit';
220
 
221
  $icons = $this->get_icons('list');
222
+
223
+ if ( version_compare( ACFFA_MAJOR_VERSION, 4, '=' ) ) :
224
  if ( $select_value && isset( $icons[ $select_value ] ) ) :
225
  $field['choices'][ $select_value ] = $icons[ $select_value ];
226
  elseif ( ( ! $select_value || ! isset( $icons[ $select_value ] ) ) && ! $field['allow_null'] ) :
228
  $default_key = key( $icons );
229
  $field['choices'][ $default_key ] = $default_value;
230
  endif;
231
+ elseif ( version_compare( ACFFA_MAJOR_VERSION, 5, '=' ) ) :
232
  $prefix = substr( $select_value, 0, 3 );
233
  if ( $select_value && isset( $icons[ $prefix ][ $select_value ] ) ) :
234
  $field['choices'][ $select_value ] = htmlentities( $icons[ $prefix ][ $select_value ] );
295
  return $value;
296
  }
297
 
298
+ $icon_json = json_decode( $value );
299
+ if ( is_object( $icon_json ) ) {
300
+ return false;
301
+ }
302
+
303
  if ( ! $this->icons ) {
304
  $this->get_icons();
305
  }
fields/acf-font-awesome-v6.php ADDED
@@ -0,0 +1,515 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // exit if accessed directly
4
+ if ( ! defined( 'ABSPATH' ) ) {
5
+ exit;
6
+ }
7
+
8
+ if ( ! class_exists( 'acf_field_font_awesome' ) ) :
9
+
10
+ class acf_field_font_awesome extends acf_field
11
+ {
12
+ private $icons = false;
13
+ private $version;
14
+
15
+ public function __construct( $settings )
16
+ {
17
+ $this->version = 'v' . ACFFA_MAJOR_VERSION;
18
+ $this->name = 'font-awesome';
19
+ $this->label = __( 'Font Awesome Icon', 'acf-font-awesome');
20
+ $this->category = 'content';
21
+ $this->settings = $settings;
22
+
23
+ $this->defaults = [
24
+ 'enqueue_fa' => 0,
25
+ 'allow_null' => 0,
26
+ 'show_preview' => 1,
27
+ 'save_format' => 'element',
28
+ 'default_value' => '',
29
+ 'default_label' => '',
30
+ 'fa_live_preview' => '',
31
+ 'choices' => []
32
+ ];
33
+
34
+ parent::__construct();
35
+
36
+ if ( apply_filters( 'ACFFA_always_enqueue_fa', false ) ) {
37
+ add_action( 'wp_enqueue_scripts', [ $this, 'frontend_enqueue_scripts' ] );
38
+ } else {
39
+ add_filter( 'acf/load_field', [ $this, 'maybe_enqueue_font_awesome' ] );
40
+ }
41
+
42
+ add_filter( 'ACFFA_v5_upgrade_compat_selected_field_sets', [ $this, 'v5_upgrade_compat_selected_field_sets' ], 5, 1 );
43
+ add_filter( 'ACFFA_v5_upgrade_compat_format_value', [ $this, 'v5_upgrade_compat_format_value' ], 5, 2 );
44
+ }
45
+
46
+ public function render_field_settings( $field )
47
+ {
48
+ if ( apply_filters( 'ACFFA_show_fontawesome_pro_blurbs', true ) ) {
49
+ acf_render_field_setting( $field, [
50
+ 'label' => __( 'Get FontAwesome Pro', 'acf-font-awesome' ),
51
+ 'message' => '<p>' . __( 'Support this plugin and get more icons across more styles plus helpful services, regular updates, a lifetime license, and actual human support.', 'acf-font-awesome' ) . '</p>' . '<a class="get-acfpro-btn" target="_blank" href="https://fontawesome.com/referral?a=0032f3e781"><i class="fa-solid fa-carrot"></i>' . __( 'Upgrade to Font Awesome Pro!', 'acf-font-awesome' ) . '</a>',
52
+ 'type' => 'message',
53
+ 'name' => 'get-fontawesome-pro',
54
+ 'class' => 'get-fontawesome-pro'
55
+ ] );
56
+ }
57
+
58
+ $icon_sets_args = [
59
+ 'label' => __( 'Icon Sets', 'acf-font-awesome' ),
60
+ 'instructions' => __( 'Specify which icon set(s) to load', 'acf-font-awesome' ),
61
+ 'type' => 'checkbox',
62
+ 'name' => 'icon_sets',
63
+ ];
64
+
65
+ $icon_sets_args['choices'] = [
66
+ 'solid' => __( 'Solid', 'acf-font-awesome' ),
67
+ 'regular' => __( 'Regular', 'acf-font-awesome' ),
68
+ 'light' => __( 'Light', 'acf-font-awesome' ) . ' (' . '<a target="_blank" href="https://fontawesome.com/referral?a=0032f3e781">' . __( 'FontAwesome Pro License Required', 'acf-font-awesome' ) . '</a>)',
69
+ 'thin' => __( 'Thin', 'acf-font-awesome' ) . ' (' . '<a target="_blank" href="https://fontawesome.com/referral?a=0032f3e781">' . __( 'FontAwesome Pro License Required', 'acf-font-awesome' ) . '</a>)',
70
+ 'duotone' => __( 'Duotone', 'acf-font-awesome' ) . ' (' . '<a target="_blank" href="https://fontawesome.com/referral?a=0032f3e781">' . __( 'FontAwesome Pro License Required', 'acf-font-awesome' ) . '</a>)',
71
+ 'fak' => __( 'Uploaded Icons', 'acf-font-awesome' ) . ' (' . '<a target="_blank" href="https://fontawesome.com/referral?a=0032f3e781">' . __( 'FontAwesome Pro License Required', 'acf-font-awesome' ) . '</a>)',
72
+ 'brands' => __( 'Brands', 'acf-font-awesome' ),
73
+ 'custom' => __( 'Custom Icon Set', 'acf-font-awesome' )
74
+ ];
75
+
76
+ $selected_field_sets = ! empty( $field['icon_sets'] ) ? $field['icon_sets'] : [ 'solid', 'regular', 'brands' ];
77
+ $selected_field_sets = apply_filters( 'ACFFA_v5_upgrade_compat_selected_field_sets', $selected_field_sets );
78
+
79
+ $icon_sets_args['value'] = $selected_field_sets;
80
+
81
+
82
+ acf_render_field_setting( $field, $icon_sets_args );
83
+
84
+ $custom_icon_set_choices = get_option( 'ACFFA_custom_icon_sets_list' );
85
+ if ( isset( $custom_icon_set_choices[ $this->version ] ) && ! empty( $custom_icon_set_choices[ $this->version ] ) ) {
86
+ $custom_icon_set_choices = $custom_icon_set_choices[ $this->version ];
87
+ } else {
88
+ $custom_icon_set_choices = [ __( 'No custom icon set(s) found', 'acf-font-awesome' ) ];
89
+ }
90
+
91
+ acf_render_field_setting( $field, [
92
+ 'label' => __( 'Custom Icon Set', 'acf-font-awesome' ),
93
+ 'instructions' => sprintf( __( 'Create custom icon sets in the <a href="%s">FontAwesome Settings page</a>.', 'acf-font-awesome' ), admin_url( '/edit.php?post_type=acf-field-group&page=fontawesome-settings' ) ),
94
+ 'type' => 'select',
95
+ 'name' => 'custom_icon_set',
96
+ 'class' => 'custom-icon-set',
97
+ 'choices' => $custom_icon_set_choices,
98
+ 'value' => isset( $field['custom_icon_set'] ) ? $field['custom_icon_set'] : false,
99
+ 'placeholder' => 'Choose an icon set',
100
+ 'allow_null' => 1
101
+ ] );
102
+
103
+ acf_render_field_setting( $field, [
104
+ 'label' => __( 'Icon Preview', 'acf-font-awesome' ),
105
+ 'instructions' => '',
106
+ 'type' => 'message',
107
+ 'name' => 'fa_live_preview',
108
+ 'class' => 'live-preview'
109
+ ] );
110
+
111
+ acf_render_field_setting( $field, [
112
+ 'label' => __( 'Default Label', 'acf-font-awesome' ),
113
+ 'instructions' => 'Used internally to store the select label for the default icon. For performance reasons.',
114
+ 'type' => 'text',
115
+ 'name' => 'default_label',
116
+ 'value' => ! empty ( $field['default_label'] ) ? $field['default_label'] : $field['default_value'],
117
+ 'class' => 'default_value'
118
+ ] );
119
+
120
+ acf_render_field_setting( $field, [
121
+ 'label' => __( 'Default Icon', 'acf-font-awesome' ),
122
+ 'instructions' => '',
123
+ 'type' => 'select',
124
+ 'name' => 'default_value',
125
+ 'class' => 'select2-fontawesome fontawesome-create',
126
+ 'choices' => ! empty( $field['default_label'] ) ? [ $field['default_value'] => html_entity_decode( $field['default_label'] ) ] : [ $field['default_value'] => $field['default_value'] ],
127
+ 'value' => $field['default_value'],
128
+ 'placeholder' => 'Choose a default icon (optional)',
129
+ 'ui' => 1,
130
+ 'allow_null' => 1,
131
+ 'ajax' => 1,
132
+ 'ajax_action' => 'acf/fields/font-awesome/query'
133
+ ] );
134
+
135
+ acf_render_field_setting( $field, [
136
+ 'label' => __( 'Return Value', 'acf-font-awesome' ),
137
+ 'instructions' => __( 'Specify the returned value on front end', 'acf-font-awesome' ),
138
+ 'type' => 'radio',
139
+ 'name' => 'save_format',
140
+ 'choices' => [
141
+ 'element' => __( 'Icon Element', 'acf-font-awesome' ),
142
+ 'class' => __( 'Icon Class', 'acf-font-awesome' ),
143
+ 'unicode' => __( 'Icon Unicode', 'acf-font-awesome' ),
144
+ 'object' => __( 'Icon Object', 'acf-font-awesome' ),
145
+ ]
146
+ ] );
147
+
148
+ acf_render_field_setting( $field, [
149
+ 'label' => __( 'Allow Null?', 'acf-font-awesome' ),
150
+ 'instructions' => '',
151
+ 'type' => 'radio',
152
+ 'name' => 'allow_null',
153
+ 'choices' => [
154
+ 1 => __( 'Yes', 'acf-font-awesome' ),
155
+ 0 => __( 'No', 'acf-font-awesome' )
156
+ ]
157
+ ] );
158
+
159
+ acf_render_field_setting( $field, [
160
+ 'label' => __( 'Show Icon Preview', 'acf-font-awesome' ),
161
+ 'instructions' => __( 'Set to \'Yes\' to include a larger icon preview on any admin pages using this field.', 'acf-font-awesome' ),
162
+ 'type' => 'radio',
163
+ 'name' => 'show_preview',
164
+ 'choices' => [
165
+ 1 => __( 'Yes', 'acf-font-awesome' ),
166
+ 0 => __( 'No', 'acf-font-awesome' )
167
+ ]
168
+ ] );
169
+
170
+ if ( ! apply_filters( 'ACFFA_always_enqueue_fa', false ) ) {
171
+ acf_render_field_setting( $field, [
172
+ 'label' => __( 'Enqueue FontAwesome?', 'acf-font-awesome' ),
173
+ 'instructions' => __( 'Set to \'Yes\' to enqueue FA in the footer on any pages using this field.', 'acf-font-awesome' ),
174
+ 'type' => 'radio',
175
+ 'name' => 'enqueue_fa',
176
+ 'choices' => [
177
+ 1 => __( 'Yes', 'acf-font-awesome' ),
178
+ 0 => __( 'No', 'acf-font-awesome' )
179
+ ]
180
+ ] );
181
+ }
182
+ }
183
+
184
+ public function render_field( $field )
185
+ {
186
+ if ( $field['allow_null'] ) {
187
+ $select_value = $field['value'];
188
+ } else {
189
+ $select_value = ( 'null' != $field['value'] ) ? $field['value'] : $field['default_value'];
190
+ }
191
+
192
+ $v5_icon_preselected = false;
193
+
194
+ $field['type'] = 'select';
195
+ $field['ui'] = 1;
196
+ $field['ajax'] = 1;
197
+ $field['choices'] = [];
198
+ $field['multiple'] = false;
199
+ $field['class'] = $v5_icon_preselected ? 'v5_icon_preselected' : '';
200
+ if ( in_array( 'custom', $field['icon_sets'] ) && ! empty( $field['custom_icon_set'] ) ) {
201
+ $field['class'] .= ' fa6 select2-fontawesome fontawesome-edit custom-icon-set';
202
+ } else {
203
+ $field['class'] .= ' fa6 select2-fontawesome fontawesome-edit';
204
+ }
205
+
206
+ if ( $select_value ) :
207
+ $icon_info = json_decode( $select_value );
208
+ if ( is_object( $icon_info ) ) {
209
+ if ( 'fak' == $icon_info->style ) {
210
+ $field['choices'][ $select_value ] = '<i class="' . $icon_info->style . ' fa-' . $icon_info->id . ' fa-fw"></i> ' . $icon_info->label;
211
+ } else {
212
+ $field['choices'][ $select_value ] = '<i class="fa-' . $icon_info->style . ' fa-' . $icon_info->id . ' fa-fw"></i> ' . $icon_info->label;
213
+ }
214
+ } else {
215
+ $v5_icon_preselected = true;
216
+ $options = get_option( 'acffa_settings' );
217
+ $label = isset( $options['acffa_v5_compatibility_mode'] ) && $options['acffa_v5_compatibility_mode'] ? '[v5-compat-lookup]' : false;
218
+
219
+ $field['choices'][ $select_value ] = $label;
220
+ }
221
+ endif;
222
+
223
+ if ( $field['show_preview'] ) :
224
+ if ( $v5_icon_preselected ) :
225
+ ?>
226
+ <div class="icon_preview v5-compat-alert show-alert">
227
+ <i class="fas fa-exclamation-circle"></i>
228
+ </div>
229
+ <?php
230
+ else :
231
+ ?>
232
+ <div class="icon_preview"></div>
233
+ <?php
234
+ endif;
235
+ endif;
236
+
237
+ if ( $v5_icon_preselected ) :
238
+ $previous_icon_info = $this->get_previous_icon_info( $select_value );
239
+ ?>
240
+ <div class="v5-compat-message" aria-label="<?php _e( 'This FontAwesome v5 Pro icon cannot be automatically translated to its v6 equivalent and will need to be reselected before saving this post/page.', 'acf-font-awesome' ); ?>" data-microtip-size="large" data-microtip-position="top" role="tooltip">
241
+ <?php echo sprintf (__( 'Please reselect your FontAwesome Icon.', 'acf-font-awesome' ), 'SOLID', 'COFFEE' ); ?> <i class="fas fa-question-circle"></i>
242
+ <?php
243
+ if ( isset( $previous_icon_info['style'] ) && ! empty( $previous_icon_info['style'] ) ) :
244
+ ?>
245
+ <em><?php _e( 'Style:', 'acf-font-awesome' ); ?></em> <strong><?php echo $previous_icon_info['style']; ?></strong>
246
+ <?php
247
+ endif;
248
+ if ( isset( $previous_icon_info['name'] ) && ! empty( $previous_icon_info['name'] ) ) :
249
+ ?>
250
+ <em><?php _e( 'Name:', 'acf-font-awesome' ); ?></em> <strong><?php echo $previous_icon_info['name']; ?></strong>
251
+ <?php
252
+ endif;
253
+ ?>
254
+ </div>
255
+ <?php
256
+ endif;
257
+
258
+ acf_render_field( $field );
259
+ }
260
+
261
+ public function input_admin_enqueue_scripts()
262
+ {
263
+ $url = $this->settings['url'];
264
+ $version = $this->settings['version'];
265
+ $options = get_option( 'acffa_settings' );
266
+ $latest_version = apply_filters( 'ACFFA_get_latest_version', '6.0.0-beta3' );
267
+
268
+ if ( isset( $options['acffa_v5_compatibility_mode'] ) && $options['acffa_v5_compatibility_mode'] ) {
269
+ wp_enqueue_script( 'acffa_fontawesome-js-api', "https://use.fontawesome.com/releases/v$latest_version/js/all.js", [], $latest_version );
270
+ }
271
+ wp_enqueue_script( 'acf-input-font-awesome', "{$url}assets/js/input-v6.js", [ 'acf-input' ], $version );
272
+ wp_localize_script( 'acf-input-font-awesome', 'ACFFA', [
273
+ 'major_version' => ACFFA_MAJOR_VERSION,
274
+ 'v5_compat_mode' => isset( $options['acffa_v5_compatibility_mode'] ) && $options['acffa_v5_compatibility_mode'] ? true : false
275
+ ] );
276
+
277
+ wp_enqueue_style( 'acf-input-microtip', "{$url}assets/inc/microtip/microtip.min.css", [], '1.0.0' );
278
+ wp_enqueue_style( 'acf-input-font-awesome', "{$url}assets/css/input.css", [ 'acf-input' ], $version );
279
+
280
+ if ( apply_filters( 'ACFFA_admin_enqueue_fa', true ) ) {
281
+ $fa_url = apply_filters( 'ACFFA_get_fa_url', '' );
282
+ if ( stristr( $fa_url, 'https://kit.fontawesome.com/' ) ) {
283
+ wp_enqueue_script( 'acffa_font-awesome-kit', $fa_url );
284
+ } else {
285
+ wp_enqueue_style( 'acffa_font-awesome', $fa_url, [ 'acf-input' ], $latest_version );
286
+ }
287
+ }
288
+ }
289
+
290
+ public function maybe_enqueue_font_awesome( $field )
291
+ {
292
+ if ( 'font-awesome' == $field['type'] && $field['enqueue_fa'] ) {
293
+ add_action( 'wp_footer', [ $this, 'frontend_enqueue_scripts' ] );
294
+ }
295
+
296
+ return $field;
297
+ }
298
+
299
+ public function frontend_enqueue_scripts()
300
+ {
301
+ $fa_url = apply_filters( 'ACFFA_get_fa_url', '' );
302
+ if ( stristr( $fa_url, 'https://kit.fontawesome.com/' ) ) {
303
+ wp_enqueue_script( 'acffa_font-awesome-kit', $fa_url );
304
+ } else {
305
+ $latest_version = apply_filters( 'ACFFA_get_latest_version', '6.0.0-beta3' );
306
+ wp_enqueue_style( 'acffa_font-awesome', $fa_url, [], $latest_version );
307
+ }
308
+ }
309
+
310
+ public function format_value( $value, $post_id, $field )
311
+ {
312
+ if ( 'null' == $value ) {
313
+ return false;
314
+ }
315
+
316
+ if ( empty( $value ) ) {
317
+ return $value;
318
+ }
319
+
320
+ $icon_json = json_decode( $value );
321
+
322
+ if ( is_object( $icon_json ) ) {
323
+ if ( 'fak' == $icon_json->style ) {
324
+ $class = $icon_json->style . ' fa-' . $icon_json->id;
325
+ $prefix = $icon_json->style;
326
+ } else {
327
+ $class = 'fa-' . $icon_json->style . ' fa-' . $icon_json->id;
328
+ $prefix = 'fa-' . $icon_json->style;
329
+ }
330
+
331
+ switch ( $field['save_format'] ) {
332
+ case 'element':
333
+ $value = '<i class="' . $class . '" aria-hidden="true"></i>';
334
+ break;
335
+
336
+ case 'unicode':
337
+ $value = '&#x' . $icon_json->unicode . ';';
338
+ break;
339
+
340
+ case 'class':
341
+ $value = $class;
342
+ break;
343
+
344
+ case 'object':
345
+ $object_data = [
346
+ 'element' => '<i class="' . $class . '" aria-hidden="true"></i>',
347
+ 'class' => $class,
348
+ 'id' => $icon_json->id,
349
+ 'prefix' => $prefix,
350
+ 'style' => $icon_json->style,
351
+ 'hex' => '\\' . $icon_json->unicode,
352
+ 'unicode' => '&#x' . $icon_json->unicode . ';'
353
+ ];
354
+
355
+ if ( 'fak' == $icon_json->style ) {
356
+ $svg_data = [
357
+ 'element' => '<svg class="svg-inline--fa" viewBox="0 0 ' . $icon_json->width . ' ' . $icon_json->height . '"><path d="' . $icon_json->path . '" /></svg>',
358
+ 'path' => $icon_json->path,
359
+ 'height' => $icon_json->height,
360
+ 'width' => $icon_json->width
361
+ ];
362
+ $object_data['svg'] = ( object ) $svg_data;
363
+ }
364
+
365
+ $value = ( object ) $object_data;
366
+ break;
367
+ }
368
+ } else {
369
+ $value = apply_filters( 'ACFFA_v5_upgrade_compat_format_value', $value, $field['save_format'] );
370
+ }
371
+
372
+ return $value;
373
+ }
374
+
375
+ public function v5_upgrade_compat_format_value( $value, $save_format )
376
+ {
377
+ if ( 'false' == $value ) {
378
+ return;
379
+ }
380
+
381
+ $icons = get_option( 'ACFFA_icon_data' );
382
+ $version = get_option( 'ACFFA_current_version', '5.15.4' );
383
+
384
+ if ( ! $icons || ! isset( $icons[ $version ] ) ) {
385
+ return $value;
386
+ }
387
+
388
+ $icons = $icons[ $version ];
389
+
390
+ if ( version_compare( $version, 5, '<' ) ) {
391
+ $icon = isset( $icons['details'][ $value ] ) ? $icons['details'][ $value ] : false;
392
+ } else {
393
+ $prefix = substr( $value, 0, 3 );
394
+ $icon = isset( $icons['details'][ $prefix ][ $value ] ) ? $icons['details'][ $prefix ][ $value ] : false;
395
+ }
396
+
397
+ if ( $icon ) {
398
+ switch ( $save_format ) {
399
+ case 'element':
400
+ if ( version_compare( $version, 5, '<' ) ) {
401
+ $value = '<i class="fa ' . $value . '" aria-hidden="true"></i>';
402
+ } else {
403
+ $value = '<i class="' . $value . '" aria-hidden="true"></i>';
404
+ }
405
+ break;
406
+
407
+ case 'unicode':
408
+ $value = $icon['unicode'];
409
+ break;
410
+
411
+ case 'object':
412
+ $object_data = array(
413
+ 'element' => '<i class="' . $value . '" aria-hidden="true"></i>',
414
+ 'class' => $value,
415
+ 'hex' => $icon['hex'],
416
+ 'unicode' => $icon['unicode']
417
+ );
418
+
419
+ if ( version_compare( $version, 5, '>=' ) ) {
420
+ $object_data['prefix'] = $prefix;
421
+ }
422
+
423
+ $value = ( object ) $object_data;
424
+ break;
425
+ }
426
+ }
427
+
428
+ return $value;
429
+ }
430
+
431
+ public function v5_upgrade_compat_selected_field_sets( $selected_field_sets )
432
+ {
433
+ if ( is_array( $selected_field_sets ) && ! empty( $selected_field_sets ) ) {
434
+ foreach ( $selected_field_sets as $key => $field_set ) {
435
+ switch ( $field_set ) {
436
+ case 'fas':
437
+ unset( $selected_field_sets[ $key ] );
438
+ $selected_field_sets[] = 'solid';
439
+ break;
440
+
441
+ case 'far':
442
+ unset( $selected_field_sets[ $key ] );
443
+ $selected_field_sets[] = 'regular';
444
+ break;
445
+
446
+ case 'fal':
447
+ unset( $selected_field_sets[ $key ] );
448
+ $selected_field_sets[] = 'light';
449
+ break;
450
+
451
+ case 'fad':
452
+ unset( $selected_field_sets[ $key ] );
453
+ $selected_field_sets[] = 'duotone';
454
+ break;
455
+
456
+ case 'fab':
457
+ unset( $selected_field_sets[ $key ] );
458
+ $selected_field_sets[] = 'brands';
459
+ break;
460
+ }
461
+ }
462
+ }
463
+
464
+ return $selected_field_sets;
465
+ }
466
+
467
+ private function get_previous_icon_info( $previous_icon )
468
+ {
469
+ if ( ! $previous_icon || 'false' == $previous_icon ) {
470
+ return;
471
+ }
472
+
473
+ if ( 0 === strpos( $previous_icon, 'fa-' ) ) {
474
+ $icon_info = [
475
+ 'name' => preg_replace('/-o$/', '', substr( $previous_icon, 3 ) )
476
+ ];
477
+ } else {
478
+ $icon_info = [
479
+ 'style' => '',
480
+ 'name' => substr( $previous_icon, 7 )
481
+ ];
482
+
483
+ $prefix = substr( $previous_icon, 0, 3 );
484
+
485
+ switch ( $prefix ) {
486
+ case 'fas':
487
+ $icon_info['style'] = 'solid';
488
+ break;
489
+
490
+ case 'far':
491
+ $icon_info['style'] = 'regular';
492
+ break;
493
+
494
+ case 'fal':
495
+ $icon_info['style'] = 'light';
496
+ break;
497
+
498
+ case 'fad':
499
+ $icon_info['style'] = 'duotone';
500
+ break;
501
+
502
+ case 'fab':
503
+ $icon_info['style'] = 'brands';
504
+ break;
505
+ }
506
+ }
507
+
508
+ return $icon_info;
509
+ }
510
+
511
+ }
512
+
513
+ new acf_field_font_awesome( $this->settings );
514
+
515
+ endif;
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: mattkeys
3
  Tags: Advanced Custom Fields, ACF, Font Awesome, FontAwesome
4
  Requires at least: 3.5
5
- Tested up to: 5.8
6
  Stable tag: trunk
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -13,20 +13,19 @@ Adds a new 'Font Awesome Icon' field to the popular Advanced Custom Fields plugi
13
 
14
  Add a [Font Awesome](http://fontawesome.io/) icon field type to Advanced Custom Fields.
15
 
16
- * Optionally set a default icon
17
- * Specify which FontAwesome icon sets to use (Solid, Regular, Light, Brands) (Applies to FontAwesome v5)
18
  * Create your own custom filtered list of FontAwesome icons to use with your fields. Use different custom icon sets with different fields
19
- * Returns Icon Element, Icon Class, Icon Unicode, or an Object including the element, class, and unicode value
20
- * Optionally enqueues Font Awesome in footer where needed (when a FontAwesome field is being used on the page)
21
- * Integrates with [jsDelivr](https://www.jsdelivr.com/) to automatically load the latest version of [Font Awesome](http://fontawesome.io/)
22
 
23
- Note: It is recommended to let this plugin enqueue the latest version of Font Awesome on your front-end; or include the latest version by some other means; so that available icons in the admin area will be displayed properly on your sites front-end.
24
 
25
  = Compatibility =
26
 
27
  This ACF field type is compatible with:
28
  * ACF 5.7+
29
- * FontAwesome 4.x and 5.x fonts
30
 
31
  == Installation ==
32
 
@@ -40,9 +39,9 @@ This ACF field type is compatible with:
40
 
41
  * **ACFFA_always_enqueue_fa**: Return true to always enqueue FontAwesome on the frontend, even if no ACF FontAwesome fields are in use on the page. This will enqueue FontAwesome in the header instead of the footer.
42
  * **ACFFA_admin_enqueue_fa**: Return false to stop enqueueing FontAwesome in the admin area. Useful if you already have FontAwesome enqueued by some other means.
43
- * **ACFFA_get_icons**: Filter the array of icons and icon details loaded from the database
44
  * **ACFFA_get_fa_url**: Filter the URL used for enqueuing FontAwesome in the frontend and admin areas of the site.
45
- * **ACFFA_override_major_version**: Filter to manually set the 'major' version of FontAwesome to load (accepts either 4, or 5). NOTE: This filter must be registered before any calls to ACF get_field() function are made.
46
 
47
  == Screenshots ==
48
 
@@ -51,6 +50,12 @@ This ACF field type is compatible with:
51
 
52
  == Changelog ==
53
 
 
 
 
 
 
 
54
  = 3.1.2 =
55
  * Fixed compatibility issue with ACF 5.10+
56
  * Fixed deprecated warnings in PHP 8, thanks to Levi Cole for the pull request
@@ -186,6 +191,12 @@ This ACF field type is compatible with:
186
 
187
  == Upgrade Notice ==
188
 
 
 
 
 
 
 
189
  = 3.1.2 =
190
  * Fixed compatibility issue with ACF 5.10+
191
  * Fixed deprecated warnings in PHP 8, thanks to Levi Cole for the pull request
2
  Contributors: mattkeys
3
  Tags: Advanced Custom Fields, ACF, Font Awesome, FontAwesome
4
  Requires at least: 3.5
5
+ Tested up to: 5.9
6
  Stable tag: trunk
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
 
14
  Add a [Font Awesome](http://fontawesome.io/) icon field type to Advanced Custom Fields.
15
 
16
+ * Specify which FontAwesome icon sets to use (Solid, Regular, Light, Thin, Duotone, Brands, and Custom Upload Icons) (Some features only available with FontAwesome 5.x or 6.x icons)
 
17
  * Create your own custom filtered list of FontAwesome icons to use with your fields. Use different custom icon sets with different fields
18
+ * Returns Icon Element, Icon Class, Icon Unicode, or an Object including the element, class, unicode value, and SVG data (if applicable)
19
+ * Optionally enqueues Font Awesome in footer where needed (when a FontAwesome field is being used on the page))
20
+ * Integrates with the [FontAwesome GraphQL](https://fontawesome.com/v6.0/docs/apis/graphql/get-started) for loading your [FontAwesome Kits](https://fontawesome.com/v6.0/docs/web/setup/use-kit), searching for icons, and loading the latest version of FontAwesome
21
 
22
+ Note: It is recommended to let this plugin enqueue the latest version of Font Awesome on your front-end; or include the latest version yourself using your [FontAwesome Kit](https://fontawesome.com/v6.0/docs/web/setup/use-kit); so that available icons in the admin area will be displayed properly on your sites front-end.
23
 
24
  = Compatibility =
25
 
26
  This ACF field type is compatible with:
27
  * ACF 5.7+
28
+ * FontAwesome 4.x and 5.x and 6.x fonts
29
 
30
  == Installation ==
31
 
39
 
40
  * **ACFFA_always_enqueue_fa**: Return true to always enqueue FontAwesome on the frontend, even if no ACF FontAwesome fields are in use on the page. This will enqueue FontAwesome in the header instead of the footer.
41
  * **ACFFA_admin_enqueue_fa**: Return false to stop enqueueing FontAwesome in the admin area. Useful if you already have FontAwesome enqueued by some other means.
42
+ * **ACFFA_get_icons**: (Applies to FontAwesome 4.x and 5.x icons only) Filter the array of icons and icon details loaded from the database
43
  * **ACFFA_get_fa_url**: Filter the URL used for enqueuing FontAwesome in the frontend and admin areas of the site.
44
+ * **ACFFA_override_major_version**: Filter to manually set the 'major' version of FontAwesome to load (accepts either 4, 5, or 6). NOTE: This filter must be registered before any calls to ACF get_field() function are made.
45
 
46
  == Screenshots ==
47
 
50
 
51
  == Changelog ==
52
 
53
+ = 4.0.0 =
54
+ * Added support for FontAwesome 6 icons
55
+ * Added support for FontAwesome Kits including Custom Uploaded Icons
56
+ * Now utilizes the FontAwesome GraphQL API for quicker searching, fuzzy matching
57
+ * Added new compatibility mode to make updating from v4 and v5 icons easier
58
+
59
  = 3.1.2 =
60
  * Fixed compatibility issue with ACF 5.10+
61
  * Fixed deprecated warnings in PHP 8, thanks to Levi Cole for the pull request
191
 
192
  == Upgrade Notice ==
193
 
194
+ = 4.0.0 =
195
+ * Added support for FontAwesome 6 icons
196
+ * Added support for FontAwesome Kits including Custom Uploaded Icons
197
+ * Now utilizes the FontAwesome GraphQL API for quicker searching, fuzzy matching
198
+ * Added new compatibility mode to make updating from v4 and v5 icons easier
199
+
200
  = 3.1.2 =
201
  * Fixed compatibility issue with ACF 5.10+
202
  * Fixed deprecated warnings in PHP 8, thanks to Levi Cole for the pull request
uninstall.php CHANGED
@@ -9,6 +9,12 @@ delete_option( 'ACFFA_cdn_error' );
9
  delete_option( 'ACFFA_icon_data' );
10
  delete_option( 'ACFFA_current_version' );
11
  delete_option( 'ACFFA_active_icon_set' );
 
 
 
 
 
 
12
 
13
  $ACFFA_custom_icon_sets_list = get_option( 'ACFFA_custom_icon_sets_list' );
14
  if ( $ACFFA_custom_icon_sets_list ) {
9
  delete_option( 'ACFFA_icon_data' );
10
  delete_option( 'ACFFA_current_version' );
11
  delete_option( 'ACFFA_active_icon_set' );
12
+ delete_option( 'ACFFA_latest_version' );
13
+ delete_option( 'ACFFA_latest_version_timestamp' );
14
+ delete_option( 'ACFFA_last_api_call_status' );
15
+ delete_option( 'ACFFA_kits' );
16
+ delete_transient( 'ACFFA_search_config' );
17
+ delete_transient( 'ACFFA_access_token' );
18
 
19
  $ACFFA_custom_icon_sets_list = get_option( 'ACFFA_custom_icon_sets_list' );
20
  if ( $ACFFA_custom_icon_sets_list ) {