--- a/advanced-custom-fields-font-awesome/acf-font-awesome.php
+++ b/advanced-custom-fields-font-awesome/acf-font-awesome.php
@@ -1,256 +1,256 @@
-<?php
-
-/*
-Plugin Name: Advanced Custom Fields: Font Awesome
-Plugin URI: https://wordpress.org/plugins/advanced-custom-fields-font-awesome/
-Description: Adds a new 'Font Awesome Icon' field to the popular Advanced Custom Fields plugin.
-Version: 5.0.1
-Author: Justin Kruit, Matt Keys
-Author URI: http://justinkruit.com/
-Text Domain: acf-font-awesome
-License: GPLv2 or later
-License URI: http://www.gnu.org/licenses/gpl-2.0.html
-*/
-
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
-}
-
-if ( ! defined( 'ACFFA_VERSION' ) ) {
- define( 'ACFFA_VERSION', '5.0.0' );
-}
-
-if ( ! defined( 'ACFFA_PUBLIC_PATH' ) ) {
- $stylesheet_dir = trim( get_stylesheet_directory(), '/' );
- $stylesheet_dir = wp_normalize_path($stylesheet_dir);
-
- $file = wp_normalize_path( __FILE__ );
-
- if ( stristr( $file, $stylesheet_dir ) ) {
- define( 'ACFFA_THEME_INSTALLATION', true );
-
- if ( defined( 'MY_ACFFA_URL' ) ) {
- $public_path = MY_ACFFA_URL;
- } else {
- $basename_dir = trim( plugin_basename( __DIR__ ), '/' );
- $theme_path = str_replace( $stylesheet_dir, '', $basename_dir );
- $public_path = get_stylesheet_directory_uri() . trailingslashit( $theme_path );
- }
- } else {
- define( 'ACFFA_THEME_INSTALLATION', false );
- $public_path = plugin_dir_url( __FILE__ );
- }
-
- define( 'ACFFA_PUBLIC_PATH', $public_path );
-}
-
-if ( ! defined( 'ACFFA_DIRECTORY' ) ) {
- if ( defined( 'MY_ACFFA_PATH' ) ) {
- define( 'ACFFA_DIRECTORY', MY_ACFFA_PATH );
- } else {
- define( 'ACFFA_DIRECTORY', dirname( __FILE__ ) );
- }
-}
-
-if ( ! defined( 'ACFFA_BASENAME' ) ) {
- define( 'ACFFA_BASENAME', plugin_basename( __FILE__ ) );
-}
-
-function ACFFA_load_textdomain() {
- load_plugin_textdomain( 'acf-font-awesome', false, plugin_basename( dirname( __FILE__ ) ) . '/lang' );
-}
-add_action( 'init', 'ACFFA_load_textdomain', 10 );
-
-if ( ! class_exists('acf_plugin_font_awesome') ) :
-
- class acf_plugin_font_awesome {
-
- public function init()
- {
- $acffa_major_version = $this->get_major_version();
-
- if ( is_admin() ) {
- require 'admin/class-ACFFA-Admin.php';
- }
-
- $this->check_for_updates( $acffa_major_version );
-
- if ( $acffa_major_version == 4 ) {
- require 'assets/inc/class-ACFFA-Loader-4.php';
- } elseif ( $acffa_major_version == 5 ) {
- require 'assets/inc/class-ACFFA-Loader-5.php';
- } elseif ( $acffa_major_version == 6 ) {
- require 'assets/inc/class-ACFFA-Loader-6.php';
- } else {
- require 'assets/inc/class-ACFFA-Loader-7.php';
- }
-
- if ( version_compare( $acffa_major_version, 6, '<' ) ) {
- include_once('fields/acf-font-awesome-v5.php');
- } elseif (version_compare( $acffa_major_version, 7, '<' ) ) {
- include_once('fields/acf-font-awesome-v6.php');
- } else {
- include_once('fields/acf-font-awesome-v7.php');
- }
-
- if ( ! defined( 'DISABLE_NAG_NOTICES' ) || ! DISABLE_NAG_NOTICES ) {
- add_action( 'admin_notices', [ $this, 'theme_install_update_needed' ] );
- }
- add_action( 'ACFFA_theme_install_update_check', [ $this, 'theme_install_update_check' ] );
-
- if ( ACFFA_THEME_INSTALLATION ) {
- if ( ! wp_next_scheduled ( 'ACFFA_theme_install_update_check' ) ) {
- wp_schedule_event( time(), 'daily', 'ACFFA_theme_install_update_check' );
- }
- }
-
- }
-
- private function get_major_version()
- {
- $current_version = get_option( 'ACFFA_current_version' );
- $acffa_settings = get_option( 'acffa_settings', [] );
- $default_version = ( $current_version && empty( $acffa_settings ) ) ? 4 : 7;
-
- $acffa_major_version = isset( $acffa_settings['acffa_major_version'] ) ? intval( $acffa_settings['acffa_major_version'] ) : $default_version;
- $override_major_version = (int) apply_filters( 'ACFFA_override_major_version', false );
- if ( $override_major_version ) {
- $override_major_version = floor( $override_major_version );
-
- if ( 4 == $override_major_version || 5 == $override_major_version || 6 == $override_major_version || 7 == $override_major_version ) {
- if ( $acffa_major_version !== $override_major_version ) {
- $acffa_settings['acffa_major_version'] = $override_major_version;
- update_option( 'acffa_settings', $acffa_settings, false );
-
- do_action( 'ACFFA_refresh_latest_icons' );
-
- $acffa_major_version = $override_major_version;
- }
-
- if ( ! defined( 'ACFFA_OVERRIDE_MAJOR_VERSION' ) ) {
- define( 'ACFFA_OVERRIDE_MAJOR_VERSION', true );
- }
- }
- }
-
- if ( ! defined( 'ACFFA_MAJOR_VERSION' ) ) {
- define( 'ACFFA_MAJOR_VERSION', $acffa_major_version );
- }
-
- if ( ! isset( $acffa_settings['acffa_major_version'] ) ) {
- $acffa_settings['acffa_major_version'] = $acffa_major_version;
- $acffa_settings['acffa_plugin_version'] = ACFFA_VERSION;
- $acffa_settings['show_upgrade_notice'] = true;
- update_option( 'acffa_settings', $acffa_settings, false );
- }
-
- return $acffa_major_version;
- }
-
- private function check_for_updates( $acffa_major_version )
- {
- $acffa_settings = get_option( 'acffa_settings', [] );
- $acffa_internal_version = isset( $acffa_settings['acffa_plugin_version'] ) ? $acffa_settings['acffa_plugin_version'] : false;
-
- if ( ! $acffa_internal_version ) {
- return;
- }
-
- switch ( $acffa_major_version ) {
- case 4:
- if ( version_compare( $acffa_internal_version, '4.0.0', '<' ) ) {
- $acffa_settings['acffa_v5_compatibility_mode'] = 1;
- }
- case 5:
- if ( version_compare( $acffa_internal_version, '3.1.1', '<' ) ) {
- define( 'ACFFA_FORCE_REFRESH', true );
- do_action( 'ACFFA_refresh_latest_icons' );
- }
- if ( version_compare( $acffa_internal_version, '4.0.1', '<' ) ) {
- $acffa_settings['acffa_v5_compatibility_mode'] = 1;
- }
- break;
- }
-
- if ( version_compare( $acffa_internal_version, '4.0.3', '<' ) ) {
- define( 'ACFFA_FORCE_REFRESH', true );
- do_action( 'ACFFA_refresh_latest_icons' );
- }
-
- if ( $acffa_internal_version !== ACFFA_VERSION ) {
- $acffa_settings['acffa_plugin_version'] = ACFFA_VERSION;
- update_option( 'acffa_settings', $acffa_settings, false );
- delete_option( 'ACFFA_theme_install_update_needed' );
- }
- }
-
- public function theme_install_update_check()
- {
- $acf_font_awesome_plugindata = wp_remote_get( 'https://api.wordpress.org/plugins/info/1.0/advanced-custom-fields-font-awesome.json' );
-
- if ( is_wp_error( $acf_font_awesome_plugindata ) ) {
- return;
- }
-
- $response = wp_remote_retrieve_body( $acf_font_awesome_plugindata );
- $plugindata = json_decode( $response );
-
- if ( ! isset( $plugindata->version ) || empty( $plugindata->version ) ) {
- return;
- }
-
- if ( version_compare( ACFFA_VERSION, $plugindata->version, '<' ) ) {
- update_option( 'ACFFA_theme_install_update_needed', $plugindata->version );
- } else {
- delete_option( 'ACFFA_theme_install_update_needed' );
- }
- }
-
- public function theme_install_update_needed()
- {
- if ( ! ACFFA_THEME_INSTALLATION ) {
- return;
- }
-
- global $pagenow;
-
- $show_notice = false;
- if ( 'update-core.php' == $pagenow || 'plugins.php' == $pagenow ) {
- $show_notice = true;
- }
-
- if ( ( isset( $_GET['post_type'] ) && 'acf-field-group' == $_GET['post_type'] ) && ( isset( $_GET['page'] ) && 'fontawesome-settings' == $_GET['page'] ) ) {
- $show_notice = true;
- }
-
- if ( ! $show_notice ) {
- return;
- }
-
- if ( ! $latest_version = get_option( 'ACFFA_theme_install_update_needed' ) ) {
- return;
- }
-
- $active_theme = wp_get_theme();
- $theme_name = $active_theme->get('Name') ? '<strong>(' . $active_theme->get('Name') . ')</strong>' : false;
- $theme_author = $active_theme->get('AuthorURI') ? '<a href="' . $active_theme->get('AuthorURI') . '" target="_blank">' . __( 'theme author', 'acf-font-awesome' ) . '</a>' : __( 'theme author', 'acf-font-awesome' );
-
- $out_of_date_message = '<p>' . sprintf( __( 'There is a new version of <a href="%s" target="_blank">Advanced Custom Fields: Font Awesome</a> available. Installed Version: <strong>%s</strong>, Latest Version: <strong>%s</strong>', 'acf-font-awesome' ), 'https://wordpress.org/plugins/advanced-custom-fields-font-awesome/', ACFFA_VERSION, $latest_version ) . '<br>';
- $out_of_date_message .= "<br>n";
- $out_of_date_message .= sprintf( __( 'It looks like this plugin is bundled with your theme: %s and is not able to receive updates. It is recommended that you contact your %s for updates. Alternatively you can install this plugin through the <a href="%s" target="_blank">WordPress Plugin Repository</a> to get the latest version.', 'acf-font-awesome' ), $theme_name, $theme_author, admin_url( 'plugin-install.php?tab=plugin-information&plugin=advanced-custom-fields-font-awesome' ) ) . '</p>';
-
- $out_of_date_message = apply_filters( 'ACFFA_theme_install_update_message', $out_of_date_message, ACFFA_VERSION, $latest_version );
-
- if ( $out_of_date_message ) {
- ?>
- <div class="update-message notice notice-warning notice-alt is-dismissible">
- <?php echo $out_of_date_message; ?>
- </div>
- <?php
- }
- }
- }
-
- add_action( 'acf/include_field_types', [ new acf_plugin_font_awesome, 'init' ], 10 );
-
-endif;
+<?php
+
+/*
+Plugin Name: Advanced Custom Fields: Font Awesome
+Plugin URI: https://wordpress.org/plugins/advanced-custom-fields-font-awesome/
+Description: Adds a new 'Font Awesome Icon' field to the popular Advanced Custom Fields plugin.
+Version: 5.0.2
+Author: Justin Kruit, Matt Keys
+Author URI: http://justinkruit.com/
+Text Domain: acf-font-awesome
+License: GPLv2 or later
+License URI: http://www.gnu.org/licenses/gpl-2.0.html
+*/
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+
+if ( ! defined( 'ACFFA_VERSION' ) ) {
+ define( 'ACFFA_VERSION', '5.0.2' );
+}
+
+if ( ! defined( 'ACFFA_PUBLIC_PATH' ) ) {
+ $stylesheet_dir = trim( get_stylesheet_directory(), '/' );
+ $stylesheet_dir = wp_normalize_path($stylesheet_dir);
+
+ $file = wp_normalize_path( __FILE__ );
+
+ if ( stristr( $file, $stylesheet_dir ) ) {
+ define( 'ACFFA_THEME_INSTALLATION', true );
+
+ if ( defined( 'MY_ACFFA_URL' ) ) {
+ $public_path = MY_ACFFA_URL;
+ } else {
+ $basename_dir = trim( plugin_basename( __DIR__ ), '/' );
+ $theme_path = str_replace( $stylesheet_dir, '', $basename_dir );
+ $public_path = get_stylesheet_directory_uri() . trailingslashit( $theme_path );
+ }
+ } else {
+ define( 'ACFFA_THEME_INSTALLATION', false );
+ $public_path = plugin_dir_url( __FILE__ );
+ }
+
+ define( 'ACFFA_PUBLIC_PATH', $public_path );
+}
+
+if ( ! defined( 'ACFFA_DIRECTORY' ) ) {
+ if ( defined( 'MY_ACFFA_PATH' ) ) {
+ define( 'ACFFA_DIRECTORY', MY_ACFFA_PATH );
+ } else {
+ define( 'ACFFA_DIRECTORY', dirname( __FILE__ ) );
+ }
+}
+
+if ( ! defined( 'ACFFA_BASENAME' ) ) {
+ define( 'ACFFA_BASENAME', plugin_basename( __FILE__ ) );
+}
+
+function ACFFA_load_textdomain() {
+ load_plugin_textdomain( 'acf-font-awesome', false, plugin_basename( dirname( __FILE__ ) ) . '/lang' );
+}
+add_action( 'init', 'ACFFA_load_textdomain', 10 );
+
+if ( ! class_exists('acf_plugin_font_awesome') ) :
+
+ class acf_plugin_font_awesome {
+
+ public function init()
+ {
+ $acffa_major_version = $this->get_major_version();
+
+ if ( is_admin() ) {
+ require 'admin/class-ACFFA-Admin.php';
+ }
+
+ $this->check_for_updates( $acffa_major_version );
+
+ if ( $acffa_major_version == 4 ) {
+ require 'assets/inc/class-ACFFA-Loader-4.php';
+ } elseif ( $acffa_major_version == 5 ) {
+ require 'assets/inc/class-ACFFA-Loader-5.php';
+ } elseif ( $acffa_major_version == 6 ) {
+ require 'assets/inc/class-ACFFA-Loader-6.php';
+ } else {
+ require 'assets/inc/class-ACFFA-Loader-7.php';
+ }
+
+ if ( version_compare( $acffa_major_version, 6, '<' ) ) {
+ include_once('fields/acf-font-awesome-v5.php');
+ } elseif (version_compare( $acffa_major_version, 7, '<' ) ) {
+ include_once('fields/acf-font-awesome-v6.php');
+ } else {
+ include_once('fields/acf-font-awesome-v7.php');
+ }
+
+ if ( ! defined( 'DISABLE_NAG_NOTICES' ) || ! DISABLE_NAG_NOTICES ) {
+ add_action( 'admin_notices', [ $this, 'theme_install_update_needed' ] );
+ }
+ add_action( 'ACFFA_theme_install_update_check', [ $this, 'theme_install_update_check' ] );
+
+ if ( ACFFA_THEME_INSTALLATION ) {
+ if ( ! wp_next_scheduled ( 'ACFFA_theme_install_update_check' ) ) {
+ wp_schedule_event( time(), 'daily', 'ACFFA_theme_install_update_check' );
+ }
+ }
+
+ }
+
+ private function get_major_version()
+ {
+ $current_version = get_option( 'ACFFA_current_version' );
+ $acffa_settings = get_option( 'acffa_settings', [] );
+ $default_version = ( $current_version && empty( $acffa_settings ) ) ? 4 : 7;
+
+ $acffa_major_version = isset( $acffa_settings['acffa_major_version'] ) ? intval( $acffa_settings['acffa_major_version'] ) : $default_version;
+ $override_major_version = (int) apply_filters( 'ACFFA_override_major_version', false );
+ if ( $override_major_version ) {
+ $override_major_version = floor( $override_major_version );
+
+ if ( 4 == $override_major_version || 5 == $override_major_version || 6 == $override_major_version || 7 == $override_major_version ) {
+ if ( $acffa_major_version !== $override_major_version ) {
+ $acffa_settings['acffa_major_version'] = $override_major_version;
+ update_option( 'acffa_settings', $acffa_settings, false );
+
+ do_action( 'ACFFA_refresh_latest_icons' );
+
+ $acffa_major_version = $override_major_version;
+ }
+
+ if ( ! defined( 'ACFFA_OVERRIDE_MAJOR_VERSION' ) ) {
+ define( 'ACFFA_OVERRIDE_MAJOR_VERSION', true );
+ }
+ }
+ }
+
+ if ( ! defined( 'ACFFA_MAJOR_VERSION' ) ) {
+ define( 'ACFFA_MAJOR_VERSION', $acffa_major_version );
+ }
+
+ if ( ! isset( $acffa_settings['acffa_major_version'] ) ) {
+ $acffa_settings['acffa_major_version'] = $acffa_major_version;
+ $acffa_settings['acffa_plugin_version'] = ACFFA_VERSION;
+ $acffa_settings['show_upgrade_notice'] = true;
+ update_option( 'acffa_settings', $acffa_settings, false );
+ }
+
+ return $acffa_major_version;
+ }
+
+ private function check_for_updates( $acffa_major_version )
+ {
+ $acffa_settings = get_option( 'acffa_settings', [] );
+ $acffa_internal_version = isset( $acffa_settings['acffa_plugin_version'] ) ? $acffa_settings['acffa_plugin_version'] : false;
+
+ if ( ! $acffa_internal_version ) {
+ return;
+ }
+
+ switch ( $acffa_major_version ) {
+ case 4:
+ if ( version_compare( $acffa_internal_version, '4.0.0', '<' ) ) {
+ $acffa_settings['acffa_v5_compatibility_mode'] = 1;
+ }
+ case 5:
+ if ( version_compare( $acffa_internal_version, '3.1.1', '<' ) ) {
+ define( 'ACFFA_FORCE_REFRESH', true );
+ do_action( 'ACFFA_refresh_latest_icons' );
+ }
+ if ( version_compare( $acffa_internal_version, '4.0.1', '<' ) ) {
+ $acffa_settings['acffa_v5_compatibility_mode'] = 1;
+ }
+ break;
+ }
+
+ if ( version_compare( $acffa_internal_version, '4.0.3', '<' ) ) {
+ define( 'ACFFA_FORCE_REFRESH', true );
+ do_action( 'ACFFA_refresh_latest_icons' );
+ }
+
+ if ( $acffa_internal_version !== ACFFA_VERSION ) {
+ $acffa_settings['acffa_plugin_version'] = ACFFA_VERSION;
+ update_option( 'acffa_settings', $acffa_settings, false );
+ delete_option( 'ACFFA_theme_install_update_needed' );
+ }
+ }
+
+ public function theme_install_update_check()
+ {
+ $acf_font_awesome_plugindata = wp_remote_get( 'https://api.wordpress.org/plugins/info/1.0/advanced-custom-fields-font-awesome.json' );
+
+ if ( is_wp_error( $acf_font_awesome_plugindata ) ) {
+ return;
+ }
+
+ $response = wp_remote_retrieve_body( $acf_font_awesome_plugindata );
+ $plugindata = json_decode( $response );
+
+ if ( ! isset( $plugindata->version ) || empty( $plugindata->version ) ) {
+ return;
+ }
+
+ if ( version_compare( ACFFA_VERSION, $plugindata->version, '<' ) ) {
+ update_option( 'ACFFA_theme_install_update_needed', $plugindata->version );
+ } else {
+ delete_option( 'ACFFA_theme_install_update_needed' );
+ }
+ }
+
+ public function theme_install_update_needed()
+ {
+ if ( ! ACFFA_THEME_INSTALLATION ) {
+ return;
+ }
+
+ global $pagenow;
+
+ $show_notice = false;
+ if ( 'update-core.php' == $pagenow || 'plugins.php' == $pagenow ) {
+ $show_notice = true;
+ }
+
+ if ( ( isset( $_GET['post_type'] ) && 'acf-field-group' == $_GET['post_type'] ) && ( isset( $_GET['page'] ) && 'fontawesome-settings' == $_GET['page'] ) ) {
+ $show_notice = true;
+ }
+
+ if ( ! $show_notice ) {
+ return;
+ }
+
+ if ( ! $latest_version = get_option( 'ACFFA_theme_install_update_needed' ) ) {
+ return;
+ }
+
+ $active_theme = wp_get_theme();
+ $theme_name = $active_theme->get('Name') ? '<strong>(' . $active_theme->get('Name') . ')</strong>' : false;
+ $theme_author = $active_theme->get('AuthorURI') ? '<a href="' . $active_theme->get('AuthorURI') . '" target="_blank">' . __( 'theme author', 'acf-font-awesome' ) . '</a>' : __( 'theme author', 'acf-font-awesome' );
+
+ $out_of_date_message = '<p>' . sprintf( __( 'There is a new version of <a href="%s" target="_blank">Advanced Custom Fields: Font Awesome</a> available. Installed Version: <strong>%s</strong>, Latest Version: <strong>%s</strong>', 'acf-font-awesome' ), 'https://wordpress.org/plugins/advanced-custom-fields-font-awesome/', ACFFA_VERSION, $latest_version ) . '<br>';
+ $out_of_date_message .= "<br>n";
+ $out_of_date_message .= sprintf( __( 'It looks like this plugin is bundled with your theme: %s and is not able to receive updates. It is recommended that you contact your %s for updates. Alternatively you can install this plugin through the <a href="%s" target="_blank">WordPress Plugin Repository</a> to get the latest version.', 'acf-font-awesome' ), $theme_name, $theme_author, admin_url( 'plugin-install.php?tab=plugin-information&plugin=advanced-custom-fields-font-awesome' ) ) . '</p>';
+
+ $out_of_date_message = apply_filters( 'ACFFA_theme_install_update_message', $out_of_date_message, ACFFA_VERSION, $latest_version );
+
+ if ( $out_of_date_message ) {
+ ?>
+ <div class="update-message notice notice-warning notice-alt is-dismissible">
+ <?php echo wp_kses_post( $out_of_date_message ); ?>
+ </div>
+ <?php
+ }
+ }
+ }
+
+ add_action( 'acf/include_field_types', [ new acf_plugin_font_awesome, 'init' ], 10 );
+
+endif;
--- a/advanced-custom-fields-font-awesome/admin/class-ACFFA-Admin.php
+++ b/advanced-custom-fields-font-awesome/admin/class-ACFFA-Admin.php
@@ -1,1028 +1,1032 @@
-<?php
-/**
- * =======================================
- * Advanced Custom Fields Font Awesome Admin
- * =======================================
- *
- *
- * @author Matt Keys <https://profiles.wordpress.org/mattkeys>
- */
-
-class ACFFA_Admin
-{
- private $version;
-
- public function init()
- {
- $this->version = 'v' . ACFFA_MAJOR_VERSION;
-
- add_action( 'admin_notices', [ $this, 'show_upgrade_notice' ] );
- add_action( 'admin_notices', [ $this, 'maybe_notify_cdn_error' ] );
- add_filter( 'plugin_action_links', [ $this, 'add_settings_link' ], 10, 2 );
- add_action( 'admin_menu', [ $this, 'add_settings_page' ], 100 );
- add_action( 'admin_init', [ $this, 'register_settings' ] );
- add_filter( 'pre_update_option_acffa_settings', [ $this, 'intercept_icon_set_save' ], 10, 2 );
- add_filter( 'pre_update_option_acffa_settings', [ $this, 'maybe_refresh_icons' ], 20, 2 );
- add_filter( 'pre_update_option_acffa_settings', [ $this, 'revoke_access_token' ], 20, 2 );
- add_filter( 'pre_update_option_acffa_settings', [ $this, 'clear_search_config_cache' ], 20, 2 );
- add_filter( 'pre_update_option_acffa_settings', [ $this, 'check_kits_settings' ], 25, 2 );
- add_action( 'update_option_acffa_settings', [ $this, 'get_latest_version' ], 10, 3 );
- add_action( 'admin_init', [ $this, 'check_kits_api_key_filter'], 10 );
- add_action( 'wp_ajax_ACFFA_delete_icon_set', [ $this, 'ajax_remove_icon_set' ] );
- add_filter( 'ACFFA_show_fontawesome_pro_blurbs', [ $this, 'hide_fontawesome_pro_blurbs' ], 5, 1 );
-
- if ( version_compare( ACFFA_MAJOR_VERSION, 6, '>=' ) ) {
- add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_acf_select2' ] );
- add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts_v6' ] );
- } else {
- add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts_v5' ] );
- }
- }
-
- public function show_upgrade_notice()
- {
- $acffa_settings = get_option( 'acffa_settings' );
- if ( ! isset( $acffa_settings['show_upgrade_notice'] ) ) {
- return;
- }
- ?>
- <div class="notice notice-info is-dismissible">
- <p><?php echo sprintf( __( 'Visit the new ACF <a href="%s">FontAwesome Settings</a> page to change FontAwesome icon version, or to create custom icon sets.', 'acf-font-awesome' ), admin_url( '/edit.php?post_type=acf-field-group&page=fontawesome-settings' ) ); ?></p>
- </div>
- <?php
- unset( $acffa_settings['show_upgrade_notice'] );
- update_option( 'acffa_settings', $acffa_settings, false );
- }
-
- public function maybe_notify_cdn_error()
- {
- if ( ! get_option( 'ACFFA_cdn_error' ) ) {
- return;
- }
-
- delete_option( 'ACFFA_cdn_error' );
- $curl_info = curl_version();
- ?>
- <div class="notice notice-error is-dismissible">
- <p><?php _e( 'The plugin "Advanced Custom Fields: Font Awesome" has detected an error while retrieving the latest FontAwesome icons. This may be due to temporary CDN downtime. However if problems persist, please contact your hosting provider to ensure cURL is installed and up to date. Detected cURL version: ', 'acf-font-awesome' ) . $curl_info['version']; ?></p>
- </div>
- <?php
- }
-
- public function enqueue_acf_select2( $hook )
- {
- $acf = sanitize_title( __( 'ACF', 'acf' ) );
- $custom_fields = sanitize_title( __( 'Custom Fields', 'acf' ) );
- if ( $custom_fields . '_page_fontawesome-settings' != $hook &&
- $acf . '_page_fontawesome-settings' != $hook ) {
- return;
- }
-
- // globals
- global $wp_scripts, $wp_styles;
-
- // vars
- $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
- $major = acf_get_setting( 'select2_version' );
- $version = '';
- $script = '';
- $style = '';
-
- // attempt to find 3rd party Select2 version
- // - avoid including v3 CSS when v4 JS is already enququed
- if ( isset( $wp_scripts->registered['select2'] ) ) {
-
- $major = (int) $wp_scripts->registered['select2']->ver;
-
- }
-
- // v4
- if ( $major == 4 ) {
-
- $version = '4.0.13';
- $script = acf_get_url( "assets/inc/select2/4/select2.full{$min}.js" );
- $style = acf_get_url( "assets/inc/select2/4/select2{$min}.css" );
-
- // v3
- } else {
-
- $version = '3.5.2';
- $script = acf_get_url( "assets/inc/select2/3/select2{$min}.js" );
- $style = acf_get_url( 'assets/inc/select2/3/select2.css' );
-
- }
-
- // enqueue
- wp_enqueue_script( 'select2', $script, [ 'jquery' ], $version );
- wp_enqueue_style( 'select2', $style, '', $version );
-
- // localize
- acf_localize_data(
- [
- 'select2L10n' => [
- 'matches_1' => _x( 'One result is available, press enter to select it.', 'Select2 JS matches_1', 'acf' ),
- 'matches_n' => _x( '%d results are available, use up and down arrow keys to navigate.', 'Select2 JS matches_n', 'acf' ),
- 'matches_0' => _x( 'No matches found', 'Select2 JS matches_0', 'acf' ),
- 'input_too_short_1' => _x( 'Please enter 1 or more characters', 'Select2 JS input_too_short_1', 'acf' ),
- 'input_too_short_n' => _x( 'Please enter %d or more characters', 'Select2 JS input_too_short_n', 'acf' ),
- 'input_too_long_1' => _x( 'Please delete 1 character', 'Select2 JS input_too_long_1', 'acf' ),
- 'input_too_long_n' => _x( 'Please delete %d characters', 'Select2 JS input_too_long_n', 'acf' ),
- 'selection_too_long_1' => _x( 'You can only select 1 item', 'Select2 JS selection_too_long_1', 'acf' ),
- 'selection_too_long_n' => _x( 'You can only select %d items', 'Select2 JS selection_too_long_n', 'acf' ),
- 'load_more' => _x( 'Loading more results…', 'Select2 JS load_more', 'acf' ),
- 'searching' => _x( 'Searching…', 'Select2 JS searching', 'acf' ),
- 'load_fail' => _x( 'Loading failed', 'Select2 JS load_fail', 'acf' ),
- ],
- ]
- );
- }
-
- public function enqueue_scripts_v6( $hook )
- {
- $acf = sanitize_title( __( 'ACF', 'acf' ) );
- $custom_fields = sanitize_title( __( 'Custom Fields', 'acf' ) );
- if ( $custom_fields . '_page_fontawesome-settings' != $hook &&
- $acf . '_page_fontawesome-settings' != $hook ) {
- return;
- }
-
- $options = get_option( 'acffa_settings' );
-
- $fa_url = apply_filters( 'ACFFA_get_fa_url', '' );
- if ( stristr( $fa_url, 'https://kit.fontawesome.com/' ) ) {
- wp_enqueue_script( 'acffa_font-awesome-kit', $fa_url );
- } else {
- wp_enqueue_style( 'acffa_font-awesome', $fa_url );
- }
-
- wp_enqueue_style( 'acffa-settings', ACFFA_PUBLIC_PATH . 'assets/css/settings.css', [], ACFFA_VERSION );
- wp_enqueue_script( 'acffa-settings', ACFFA_PUBLIC_PATH . 'assets/js/settings-v6.js', [ 'select2', 'wp-util' ], ACFFA_VERSION, true );
- wp_localize_script( 'acffa-settings', 'ACFFA', [
- 'save_settings' => __( 'Save Settings', 'acf-font-awesome' ),
- 'save_refresh_settings' => __( 'Save Settings & Refresh Icon Cache', 'acf-font-awesome' ),
- 'search_string' => __( 'Add New Icon', 'acf-font-awesome' ),
- 'confirm_delete' => __( 'Are you sure you want to delete this icon set?', 'acf-font-awesome' ),
- 'remove_icon' => __( 'Remove this icon from this set?', 'acf-font-awesome' ),
- 'delete_fail' => __( 'There was an error while trying to delete the icon set, please refresh the page and try again.', 'acf-font-awesome' ),
- 'acffa_major_version' => isset( $options['acffa_major_version'] ) ? $options['acffa_major_version'] : '',
- 'acffa_kit' => isset( $options['acffa_kit'] ) ? $options['acffa_kit'] : '',
- 'acf_nonce' => wp_create_nonce( 'acf_nonce' ),
- 'kits' => get_option( 'ACFFA_kits', [] ),
- 'api_key_status' => get_option( 'ACFFA_last_api_call_status', 'na' )
- ] );
-
- add_action( 'admin_footer', [ $this, 'js_templates' ] );
- }
-
- public function enqueue_scripts_v5( $hook )
- {
- $acf = sanitize_title( __( 'ACF', 'acf' ) );
- $custom_fields = sanitize_title( __( 'Custom Fields', 'acf' ) );
- if ( $custom_fields . '_page_fontawesome-settings' != $hook &&
- $acf . '_page_fontawesome-settings' != $hook ) {
- return;
- }
-
- wp_enqueue_style( 'acffa-settings', ACFFA_PUBLIC_PATH . 'assets/css/settings.css', [], ACFFA_VERSION );
-
- wp_register_style( 'font-awesome', apply_filters( 'ACFFA_get_fa_url', '' ) );
- wp_enqueue_style( 'multi-select-css', ACFFA_PUBLIC_PATH . 'assets/inc/multi-select/multi-select.css', [ 'font-awesome' ] );
-
- wp_register_script( 'quicksearch-js', ACFFA_PUBLIC_PATH . 'assets/inc/quicksearch/jquery.quicksearch.js', [ 'jquery' ], '1.0.0', true );
- wp_register_script( 'multi-select-js', ACFFA_PUBLIC_PATH . 'assets/inc/multi-select/jquery.multi-select.js', [ 'jquery' ], '0.9.12', true );
- wp_enqueue_script( 'acffa-settings', ACFFA_PUBLIC_PATH . 'assets/js/settings-v5.js', [ 'multi-select-js', 'quicksearch-js' ], '1.0.0', true );
- wp_localize_script( 'acffa-settings', 'ACFFA', [
- 'save_settings' => __( 'Save Settings', 'acf-font-awesome' ),
- 'save_refresh_settings' => __( 'Save Settings & Refresh Icon Cache', 'acf-font-awesome' ),
- 'search_string' => __( 'Search List', 'acf-font-awesome' ),
- 'confirm_delete' => __( 'Are you sure you want to delete this icon set?', 'acf-font-awesome' ),
- 'delete_fail' => __( 'There was an error while trying to delete the icon set, please refresh the page and try again.', 'acf-font-awesome' )
- ] );
- }
-
- public function add_settings_link( $links, $file )
- {
- if ( $file != ACFFA_BASENAME ) {
- return $links;
- }
-
- 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>' );
-
- if ( apply_filters( 'ACFFA_show_fontawesome_pro_blurbs', true ) ) {
- $links[] = '<a target="_blank" style="color:#20c997;" href="https://fontawesome.com/referral?a=f4be3e1256">' . __( 'Get Font Awesome Pro!', 'acf-font-awesome' ) . '</a>';
- }
-
- return $links;
- }
-
- public function add_settings_page()
- {
- $capability = apply_filters( 'acf/settings/capability', 'manage_options' );
-
- add_submenu_page(
- 'edit.php?post_type=acf-field-group',
- 'FontAwesome for Advanced Custom Fields',
- 'FontAwesome Settings',
- $capability,
- 'fontawesome-settings',
- [ $this, 'fontawesome_settings' ]
- );
- }
-
- public function fontawesome_settings()
- {
- $errors = get_settings_errors( 'acffa_messages' );
- if ( isset( $_GET['settings-updated'] ) && ! $errors ) {
- add_settings_error( 'acffa_messages', 'acffa_message', __( 'Settings Saved', 'acf-font-awesome' ), 'updated' );
- }
-
- settings_errors( 'acffa_messages' );
- ?>
- <div class="wrap">
- <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
- <?php
- if ( apply_filters( 'ACFFA_show_fontawesome_pro_blurbs', true ) ) :
- switch( ACFFA_MAJOR_VERSION ) {
- case '6':
- case '7':
- $fortawesome = 'fa-solid fa-font-awesome';
- $carrot_icon = 'fa-solid fa-carrot';
- break;
-
- case '5':
- $fortawesome = 'fab fa-font-awesome-flag';
- $carrot_icon = 'fas fa-carrot';
- break;
-
- default:
- $fortawesome = 'fa fa-font-awesome';
- $carrot_icon = 'fa fa-tree';
- break;
- }
- ?>
- <div class="get-fontawesome-pro">
- <div class="title-button-wrap">
- <i class="<?php echo $fortawesome; ?>"></i>
- <h3><?php _e( 'Get more icons, styles, tools, & tech support. Upgrade to Font Awesome Pro!', 'acf-font-awesome' ); ?></h3>
- <a target="_blank" href="https://fontawesome.com/referral?a=f4be3e1256"><i class="<?php echo $carrot_icon; ?>"></i><?php _e( 'Get More with Pro', 'acf-font-awesome' ); ?></a>
- </div>
- <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>
- </div>
- <?php
- endif;
- ?>
- <form action="options.php" method="post">
- <?php
- settings_fields( 'acffa' );
-
- do_settings_sections( 'acffa' );
-
- if ( version_compare( ACFFA_MAJOR_VERSION, 6, '<' ) ) {
- submit_button( __( 'Save Settings & Refresh Icon Cache', 'acf-font-awesome' ) );
- } else {
- submit_button( __( 'Save Settings', 'acf-font-awesome' ) );
- }
- ?>
- </form>
- </div>
- <?php
- }
-
- public function register_settings()
- {
- register_setting(
- 'acffa',
- 'acffa_settings',
- [
- 'sanitize_callback' => [ $this, 'sanitize_new_icon_set' ]
- ]
- );
-
- add_settings_section(
- 'acffa_section_developers',
- __( 'Settings', 'acf-font-awesome' ),
- [ $this, 'acffa_section_developers_cb' ],
- 'acffa'
- );
-
- add_settings_field(
- 'acffa_major_version',
- __( 'FontAwesome Version', 'acf-font-awesome' ),
- [ $this, 'acffa_major_version_cb' ],
- 'acffa',
- 'acffa_section_developers',
- [
- 'label_for' => 'acffa_major_version',
- 'class' => 'acffa_row'
- ]
- );
-
- add_settings_field(
- 'acffa_pro_cdn',
- __( 'Enable Pro Icons?', 'acf-font-awesome' ),
- [ $this, 'acffa_pro_cdn_cb' ],
- 'acffa',
- 'acffa_section_developers',
- [
- 'label_for' => 'acffa_pro_cdn',
- 'class' => 'acffa_row pro_icons'
- ]
- );
-
- add_settings_field(
- 'acffa_v5_compatibility_mode',
- __( 'Compatibility Mode', 'acf-font-awesome' ),
- [ $this, 'acffa_v5_compatibility_mode_cb' ],
- 'acffa',
- 'acffa_section_developers',
- [
- 'label_for' => 'acffa_v5_compatibility_mode',
- 'class' => 'acffa_row v5_compatibility_mode'
- ]
- );
-
- add_settings_field(
- 'acffa_api_key',
- __( 'FontAwesome API Token', 'acf-font-awesome' ),
- [ $this, 'acffa_api_key_cb' ],
- 'acffa',
- 'acffa_section_developers',
- [
- 'label_for' => 'acffa_api_key',
- 'class' => 'acffa_row api_key'
- ]
- );
-
- add_settings_field(
- 'acffa_kit',
- __( 'FontAwesome Kit', 'acf-font-awesome' ),
- [ $this, 'acffa_kit_cb' ],
- 'acffa',
- 'acffa_section_developers',
- [
- 'label_for' => 'acffa_kit',
- 'class' => 'acffa_row kit'
- ]
- );
-
- add_settings_field(
- 'acffa_kit_has_pro',
- 'Has Pro Kit',
- [ $this, 'acffa_kit_has_pro_cb' ],
- 'acffa',
- 'acffa_section_developers',
- [
- 'label_for' => 'acffa_kit_has_pro',
- 'class' => 'acffa_row hidden'
- ]
- );
-
- add_settings_field(
- 'acffa_plugin_version',
- 'Plugin Version',
- [ $this, 'acffa_plugin_version_cb' ],
- 'acffa',
- 'acffa_section_developers',
- [
- 'label_for' => 'acffa_plugin_version',
- 'class' => 'acffa_row hidden'
- ]
- );
-
- add_settings_section(
- 'acffa_section_icon_set_builder',
- __( 'Icon Set Builder', 'acf-font-awesome' ),
- [ $this, 'acffa_section_icon_set_builder_cb' ],
- 'acffa'
- );
-
- add_settings_field(
- 'acffa_new_icon_set_label',
- __( 'New Icon Set Label', 'acf-font-awesome' ),
- [ $this, 'acffa_new_icon_set_label_cb' ],
- 'acffa',
- 'acffa_section_icon_set_builder',
- [
- 'label_for' => 'acffa_new_icon_set_label',
- 'class' => 'acffa_row custom-icon-set'
- ]
- );
-
- add_settings_field(
- 'acffa_new_icon_set',
- __( 'New Icon Set', 'acf-font-awesome' ),
- [ $this, 'acffa_new_icon_set_cb' ],
- 'acffa',
- 'acffa_section_icon_set_builder',
- [
- 'label_for' => 'acffa_new_icon_set',
- 'class' => 'acffa_row custom-icon-set'
- ]
- );
-
- add_settings_field(
- 'acffa_existing_icon_sets',
- __( 'Existing Icon Sets', 'acf-font-awesome' ),
- [ $this, 'acffa_existing_icon_sets_cb' ],
- 'acffa',
- 'acffa_section_icon_set_builder',
- [
- 'label_for' => 'acffa_existing_icon_sets',
- 'class' => 'acffa_row custom-icon-set'
- ]
- );
- }
-
- public function sanitize_new_icon_set( $data )
- {
- if ( isset( $data['acffa_new_icon_set_label'] ) || ! empty( $data['acffa_new_icon_set_label'] ) ) {
- $data['acffa_new_icon_set_label'] = sanitize_text_field( $data['acffa_new_icon_set_label'] );
- } else {
- $data['acffa_new_icon_set_label'] = false;
- }
-
- if ( isset( $data['acffa_new_icon_set'] ) || ! empty( $data['acffa_new_icon_set'] ) ) {
- $data['acffa_new_icon_set'] = array_map(
- 'sanitize_text_field',
- wp_unslash( $data['acffa_new_icon_set'] )
- );
- } else {
- $data['acffa_new_icon_set'] = false;
- }
-
- if ( $data['acffa_new_icon_set_label'] && ! $data['acffa_new_icon_set'] ) {
- add_settings_error( 'acffa_messages', 'missing_label', __( 'Please select at least one icon when adding a new custom icon set.', 'acf-font-awesome' ), 'error' );
- } else if ( $data['acffa_new_icon_set'] && ! $data['acffa_new_icon_set_label'] ) {
- add_settings_error( 'acffa_messages', 'missing_icons', __( 'Label is required when adding a new custom icon set.', 'acf-font-awesome' ), 'error' );
- }
-
- return $data;
- }
-
- public function acffa_section_developers_cb( $args ) {}
-
- public function acffa_major_version_cb( $args )
- {
- $options = get_option( 'acffa_settings' );
- $attributes = defined( 'ACFFA_OVERRIDE_MAJOR_VERSION' ) ? 'disabled' : false;
- ?>
- <p>
- <?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 "Compatibility Mode" that aims to make this migration easier.', 'acf-font-awesome' ); ?>
- </p>
- <br>
- <select <?php echo $attributes; ?> id="<?php echo esc_attr( $args['label_for'] ); ?>" name="acffa_settings[<?php echo esc_attr( $args['label_for'] ); ?>]">
- <option value="4" <?php echo isset( $options[ $args[ 'label_for'] ] ) ? ( selected( $options[ $args[ 'label_for'] ], 4, false ) ) : ( '' ); ?>>
- <?php _e( '4.x', 'acf-font-awesome' ); ?>
- </option>
- <option value="5" <?php echo isset( $options[ $args[ 'label_for'] ] ) ? ( selected( $options[ $args[ 'label_for'] ], 5, false ) ) : ( '' ); ?>>
- <?php _e( '5.x', 'acf-font-awesome' ); ?>
- </option>
- <option value="6" <?php echo isset( $options[ $args[ 'label_for'] ] ) ? ( selected( $options[ $args[ 'label_for'] ], 6, false ) ) : ( '' ); ?>>
- <?php _e( '6.x', 'acf-font-awesome' ); ?>
- </option>
- <option value="7" <?php echo isset( $options[ $args[ 'label_for'] ] ) ? ( selected( $options[ $args[ 'label_for'] ], 7, false ) ) : ( '' ); ?>>
- <?php _e( '7.x', 'acf-font-awesome' ); ?>
- </option>
- </select>
- <?php
- if ( defined( 'ACFFA_OVERRIDE_MAJOR_VERSION' ) ) :
- ?>
- <p>
- <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>
- </p>
- <?php
- endif;
- }
-
- public function acffa_v5_compatibility_mode_cb( $args )
- {
- $options = get_option( 'acffa_settings' );
- ?>
- <p>
- <?php _e( 'Attempt to automatically migrate any older FontAwesome icon selections made using this plugin to their FontAwesome v6 equivalents.', 'acf-font-awesome' ); ?><br>
- <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>
- </p>
- <br>
- <p>
- <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'] ] ) ) : ( '' ); ?> />
- <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>
- </p>
- <?php
- }
-
- public function acffa_pro_cdn_cb( $args )
- {
- $options = get_option( 'acffa_settings' );
- ?>
- <p>
- <?php _e( 'If you have a FontAwesome Pro license, check the box below to enable the pro icons.', 'acf-font-awesome' ); ?><br>
- <em><?php _e( 'NOTE: You MUST add this domain in your FontAwesome "Pro CDN Domains" in order for this to work!', 'acf-font-awesome' ); ?></em>
- </p>
- <br>
- <p>
- <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'] ] ) ) : ( '' ); ?> />
- <label for="<?php echo esc_attr( $args['label_for'] ); ?>"><?php _e( 'I have enabled this domain for CDN use. Turn on the pro icons!', 'acf-font-awesome' ); ?></label>
- </p>
- <?php
- }
-
- public function acffa_api_key_cb( $args )
- {
- if ( $api_key = apply_filters( 'ACFFA_fa_api_key', false ) ) {
- ?>
- <p>
- <?php _e( 'The API key has been set programatically using the "ACFFA_fa_api_key" filter.', 'acf-font-awesome' ); ?><br>
- </p>
- <?php
- } else {
- $options = get_option( 'acffa_settings' );
- ?>
- <p>
- <?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>
- </p>
- <br>
- <p>
- <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'] ); ?>]" />
- <br>
- <span class="validation-label"><?php _e( 'Token Validation:', 'acf-font-awesome' ); ?></span>
- <span class="validation-result">
- <span class="empty"><?php _e( 'Please add your API token above.', 'acf-font-awesome' ); ?></span>
- <span class="save"><?php _e( 'Save settings to validate token.', 'acf-font-awesome' ); ?></span>
- <span class="success"><?php _e( 'Token successfully validated.', 'acf-font-awesome' ); ?></span>
- <span class="error"><?php _e( 'Could not validate token. Please verify the token has been correctly entered.', 'acf-font-awesome' ); ?></span>
- </span>
- </p>
- <?php
- }
- }
-
- public function acffa_kit_cb( $args )
- {
- if ( $api_key = apply_filters( 'ACFFA_fa_kit_token', false ) ) {
- ?>
- <p>
- <?php _e( 'The kit token has been set programatically using the "ACFFA_fa_kit_token" filter.', 'acf-font-awesome' ); ?><br>
- </p>
- <?php
- } else {
- $options = get_option( 'acffa_settings' );
- ?>
- <p>
- <?php _e( 'FontAwesome kits are required for using FontAwesome Pro icons. Enter your API token above to select your kit.', 'acf-font-awesome' ); ?><br>
- </p>
- <br>
-
- <table class="widefat" id="available_kits">
- <thead>
- <tr>
- <td><?php _e( 'Select', 'acf-font-awesome' ); ?></td>
- <td><?php _e( 'Kit Name', 'acf-font-awesome' ); ?></td>
- <td><?php _e( 'Token', 'acf-font-awesome' ); ?></td>
- <td><?php _e( 'Status', 'acf-font-awesome' ); ?></td>
- <td><?php _e( 'License', 'acf-font-awesome' ); ?></td>
- <td><?php _e( 'Technology', 'acf-font-awesome' ); ?></td>
- <td><?php _e( 'Custom Icon(s)', 'acf-font-awesome' ); ?></td>
- <td><?php _e( 'Version', 'acf-font-awesome' ); ?></td>
- </tr>
- </thead>
- <tbody>
- <tr class="no_kits_found">
- <td><input type="radio" name="acffa_settings[acffa_kit]" checked value=""></td>
- <td colspan="7">
- <?php _e( 'No Kits Found. <a target="_blank" href="https://fontawesome.com/kits">Create a new kit</a>', 'acf-font-awesome' ); ?>
- </td>
- </tr>
- </tbody>
- </table>
- <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>
- <?php
- }
- }
-
- public function acffa_kit_has_pro_cb( $args )
- {
- $options = get_option( 'acffa_settings' );
- ?>
- <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'] ); ?>]" />
- <?php
- }
-
- public function acffa_plugin_version_cb( $args )
- {
- ?>
- <input type="hidden" value="<?php echo ACFFA_VERSION; ?>" id="<?php echo esc_attr( $args['label_for'] ); ?>" name="acffa_settings[<?php echo esc_attr( $args['label_for'] ); ?>]" />
- <?php
- }
-
- public function acffa_section_icon_set_builder_cb( $args )
- {
- ?>
- <p id="<?php echo esc_attr( $args['id'] ); ?>">
- <?php _e( 'Use the icon set builder to create custom collections of FontAwesome icons to be used in your ACF FontAwesome fields', 'acf-font-awesome' ); ?><br>
- <em><?php _e( 'If you've made changes the the FontAwesome version you are loading above, please refresh this page to see those changes reflected in the list below.', 'acf-font-awesome' ); ?></em>
- </p>
- <p class="icon-builder-complete-changes-notice">
- <strong><?php _e( 'You must save your changes to the major version before using the icon set builder.', 'acf-font-awesome' ); ?></strong>
- </p>
- <?php
- }
-
- public function acffa_new_icon_set_label_cb( $args )
- {
- ?>
- <input type="text" id="<?php echo esc_attr( $args['label_for'] ); ?>" name="acffa_settings[<?php echo esc_attr( $args['label_for'] ); ?>]" placeholder="<?php _e( 'Custom Icon Set Name', 'acf-font-awesome' ); ?>">
- <p>
- <em><?php _e( 'NOTE: Providing a label that is already in use will overwrite the existing custom icon set.', 'acf-font-awesome' ); ?></em>
- </p>
- <?php
- }
-
- public function acffa_new_icon_set_cb( $args )
- {
- if ( version_compare( ACFFA_MAJOR_VERSION, 6, '>=' ) ) {
- ?>
- <div class="selected-icons"></div>
- <select multiple id="<?php echo esc_attr( $args['label_for'] ); ?>" name="acffa_settings[<?php echo esc_attr( $args['label_for'] ); ?>][]"></select>
- <select id="icon_chooser"></select>
- <?php
- } else {
- $options = get_option( 'acffa_settings' );
- ?>
- <select multiple="multiple" id="<?php echo esc_attr( $args['label_for'] ); ?>" name="acffa_settings[<?php echo esc_attr( $args['label_for'] ); ?>][]">
- <?php
- $fa_icons = apply_filters( 'ACFFA_get_icons', array() );
- if ( $fa_icons ) {
- if ( version_compare( ACFFA_MAJOR_VERSION, 5, '=' ) ) {
- foreach ( $fa_icons['list'] as $prefix => $icons ) {
- $optgroup_label = apply_filters( 'ACFFA_icon_prefix_label', 'Regular', $prefix );
- echo '<optgroup label="' . $optgroup_label . '">';
-
- foreach( $icons as $k => $v ) {
- $value = str_replace( array( 'fas ', 'far ', 'fab ', 'fal ', 'fad ', 'fa-' ), '', $k );
- ?>
- <option value="<?php echo $k; ?>"><?php echo $value; ?></option>
- <?php
- }
-
- echo '</optgroup>';
- }
- } else {
- foreach ( $fa_icons['list'] as $k => $v ) {
- $value = str_replace( array( 'fa-' ), '', $k );
- ?>
- <option value="<?php echo $k; ?>"><?php echo $value; ?></option>
- <?php
- }
- }
- } else {
- ?>
- <option value=""><?php _e( 'No Icons Found', 'acf-font-awesome' ); ?></option>
- <?php
- }
- ?>
- </select>
- <?php
- }
- }
-
- public function acffa_existing_icon_sets_cb( $args )
- {
- $custom_icon_sets_list = get_option( 'ACFFA_custom_icon_sets_list' );
-
- if ( isset( $custom_icon_sets_list[ $this->version ] ) && ! empty( $custom_icon_sets_list[ $this->version ] ) ) {
- ?>
- <ul class="existing-custom-icon-sets">
- <?php
- foreach ( $custom_icon_sets_list[ $this->version ] as $icon_set_name => $icon_set_label ) {
- $icon_set = get_option( $icon_set_name );
- $icon_set = apply_filters( 'ACFFA_standardize_custom_icon_set_family_style', $icon_set );
-
- if ( ! $icon_set ) {
- $this->remove_icon_set( $custom_icon_sets_list, $icon_set_name, true );
- }
- ?>
- <li class="icon-set" data-set-label="<?php echo esc_html( $icon_set_label ); ?>" data-set-name="<?php echo esc_html( $icon_set_name ); ?>">
- <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>
- <ul class="icon-list">
- <?php
- if ( version_compare( ACFFA_MAJOR_VERSION, 6, '>=' ) ) {
- foreach ( $icon_set as $family_style => $icons ) {
- ?>
- <li>
- <span class="style"><?php echo apply_filters( 'ACFFA_icon_prefix_label', 'Regular', $family_style ); ?></span>
- <ul>
- <?php
- foreach ( $icons as $id => $icon_json ) {
- $icon_info = json_decode( $icon_json );
- $family = isset( $icon_info->family ) ? $icon_info->family : apply_filters( 'ACFFA_default_family_by_style', 'classic', $icon_info->style );
- echo '<li class="icon" data-icon-json="' . htmlentities( $icon_json ) . '"><i class="fa-' . $family . ' fa-' . $icon_info->style . ' fa-' . $icon_info->id . ' fa-fw"></i>' . $icon_info->label . '</li>';
- }
- ?>
- </ul>
- </li>
- <?php
- }
- } else if ( version_compare( ACFFA_MAJOR_VERSION, 5, '=' ) ) {
- foreach ( $icon_set as $prefix => $icons ) {
- ?>
- <li>
- <?php echo apply_filters( 'ACFFA_icon_prefix_label', 'Regular', $prefix ); ?>
- <ul>
- <?php
- foreach ( $icons as $class => $label ) {
- echo '<li class="icon" data-icon="' . $class . '">' . $label . '</li>';
- }
- ?>
- </ul>
- </li>
- <?php
- }
- } else {
- foreach ( $icon_set as $class => $label ) {
- ?>
- <li>
- <?php
- echo '<li class="icon" data-icon="' . $class . '">' . $label . '</li>';
- ?>
- </li>
- <?php
- }
- }
- ?>
- </ul>
- </li>
- <?php
- }
- ?>
- </ul>
- <?php
- } else {
- _e( 'No existing custom icon set(s) found.', 'acf-font-awesome' );
- }
- }
-
- public function intercept_icon_set_save( $new_value, $old_value )
- {
- $label = $new_value['acffa_new_icon_set_label'];
- $icons = $new_value['acffa_new_icon_set'];
-
- unset( $new_value['acffa_new_icon_set_label'] );
- unset( $new_value['acffa_new_icon_set'] );
-
- if ( $label && $icons ) {
- $this->save_new_icon_set( $label, $icons );
- }
-
- return $new_value;
- }
-
- public function maybe_refresh_icons( $new_value, $old_value )
- {
- if ( version_compare( ACFFA_MAJOR_VERSION, 6, '>=' ) ) {
- return $new_value;
- }
-
- unset( $new_value['acffa_new_icon_set_label'] );
- unset( $new_value['acffa_new_icon_set'] );
-
- do_action( 'ACFFA_refresh_latest_icons' );
-
- return $new_value;
- }
-
- public function revoke_access_token( $new_value, $old_value )
- {
- $old_api_key = isset( $old_value['acffa_api_key'] ) ? $old_value['acffa_api_key'] : false;
- $new_api_key = isset( $new_value['acffa_api_key'] ) ? $new_value['acffa_api_key'] : false;
-
- if ( $old_api_key != $new_api_key ) {
- delete_transient( 'ACFFA_access_token' );
- delete_transient( 'ACFFA_search_config' );
- update_option( 'ACFFA_last_api_call_status', 'na' );
- update_option( 'ACFFA_kits', [] );
- }
-
- return $new_value;
- }
-
- public function clear_search_config_cache( $new_value, $old_value )
- {
- $old_kit_id = isset( $old_value['acffa_kit'] ) ? $old_value['acffa_kit'] : false;
- $new_kit_id = isset( $new_value['acffa_kit'] ) ? $new_value['acffa_kit'] : false;
-
- if ( $old_kit_id != $new_kit_id ) {
- delete_transient( 'ACFFA_search_config' );
- }
-
- return $new_value;
- }
-
- public function check_kits_settings( $new_value, $old_value )
- {
- if ( version_compare( ACFFA_MAJOR_VERSION, 6, '<' ) ) {
- return $new_value;
- }
-
- if ( $ACFFA_fa_api_key = apply_filters( 'ACFFA_fa_api_key', false ) ) {
- return $new_value;
- }
-
- if ( ! isset( $new_value['acffa_api_key'] ) || empty( $new_value['acffa_api_key'] ) ) {
- return $new_value;
- }
-
- $this->get_fontawesome_kits( $new_value['acffa_api_key'] );
-
- return $new_value;
- }
-
- public function get_latest_version($old_value, $new_value, $option)
- {
- if ( version_compare( ACFFA_MAJOR_VERSION, 6, '<' ) ) {
- return $new_value;
- }
-
-
- $old_version = isset( $old_value['acffa_major_version'] ) ? $old_value['acffa_major_version'] : false;
- $new_version = isset( $new_value['acffa_major_version'] ) ? $new_value['acffa_major_version'] : false;
-
- if ( $old_version != $new_version ) {
- delete_option( 'ACFFA_latest_version' );
- }
-
- return $new_value;
- }
-
- public function check_kits_api_key_filter()
- {
- $ACFFA_fa_api_key = apply_filters( 'ACFFA_fa_api_key', false );
- $ACFFA_fa_api_key_db = get_option( 'ACFFA_fa_api_key' );
-
- if ( ! $ACFFA_fa_api_key && ! $ACFFA_fa_api_key_db ) {
- return;
- }
-
- if ( $ACFFA_fa_api_key != $ACFFA_fa_api_key_db ) {
- delete_transient( 'ACFFA_access_token' );
- delete_transient( 'ACFFA_search_config' );
- update_option( 'ACFFA_last_api_call_status', 'na' );
- update_option( 'ACFFA_kits', [] );
-
- if ( $ACFFA_fa_api_key ) {
- update_option( 'ACFFA_fa_api_key', $ACFFA_fa_api_key, false );
- } else {
- delete_option( 'ACFFA_fa_api_key' );
- }
-
- $this->get_fontawesome_kits( $ACFFA_fa_api_key );
- }
- }
-
- private function get_fontawesome_kits( $fa_api_key )
- {
- $access_token = apply_filters( 'ACFFA_fontawesome_access_token', false, $fa_api_key );
-
- if ( ! $access_token ) {
- return;
- }
-
- $remote_get = wp_remote_post( 'https://api.fontawesome.com', [
- 'headers' => [
- 'Content-Type' => 'application/json',
- 'Authorization' => 'Bearer ' . $access_token,
- ],
- 'timeout' => 30,
- 'body' => '{
- "query" : "query { me { kits { name token status licenseSelected technologySelected version iconUploads { name } } } }"
- }'
- ] );
-
- if ( ! is_wp_error( $remote_get ) ) {
- $response_json = wp_remote_retrieve_body( $remote_get );
-
- if ( $response_json ) {
- $response = json_decode( $response_json );
-
- if ( isset( $response->data->me->kits ) && ! empty( $response->data->me->kits ) ) {
- update_option( 'ACFFA_kits', $response->data->me->kits );
- }
- }
- }
- }
-
- private function save_new_icon_set( $label, $icons )
- {
- $new_icon_set = [];
-
- $fa_icons = apply_filters( 'ACFFA_get_icons', [] );
-
- if ( version_compare( ACFFA_MAJOR_VERSION, 6, '>=' ) ) {
- foreach( $icons as $icon ) {
- $icon_details = json_decode( $icon );
- $family = isset( $icon_details->family ) ? $icon_details->family : apply_filters( 'ACFFA_default_family_by_style', 'classic', $icon_details->style );
- $family_style = $family . '_' . $icon_details->style;
- if ( ! isset( $new_icon_set[ $family_style ] ) ) {
- $new_icon_set[ $family_style ] = [];
- }
- $new_icon_set[ $family_style ][ $icon_details->id ] = $icon;
- }
- } else if ( version_compare( ACFFA_MAJOR_VERSION, 5, '=' ) ) {
- foreach( $icons as $icon ) {
- $prefix = substr( $icon, 0, 3 );
-
- if ( isset( $fa_icons['list'][ $prefix ][ $icon ] ) ) {
- if ( ! isset( $new_icon_set[ $prefix ] ) ) {
- $new_icon_set[ $prefix ] = [];
- }
- $new_icon_set[ $prefix ][ $icon ] = $fa_icons['list'][ $prefix ][ $icon ];
- }
- }
- } else {
- foreach( $icons as $icon ) {
- if ( isset( $fa_icons['list'][ $icon ] ) ) {
- $new_icon_set[ $icon ] = $fa_icons['list'][ $icon ];
- }
- }
- }
-
- if ( ! empty( $new_icon_set ) ) {
- $option_name = 'ACFFA_custom_icon_list_' . $this->version . '_' . sanitize_html_class( $label );
- update_option( $option_name, $new_icon_set, false );
- $this->update_custom_icon_sets_list( $option_name, $label );
- }
- }
-
- private function update_custom_icon_sets_list( $option_name, $label )
- {
- $icon_sets_list = get_option( 'ACFFA_custom_icon_sets_list' );
-
- if ( ! $icon_sets_list ) {
- $icon_sets_list = [];
- }
-
- if ( ! isset( $icon_sets_list[ $this->version ] ) ) {
- $icon_sets_list[ $this->version ] = [];
- }
-
- if ( ! isset( $icon_sets_list[ $this->version ][ 'ACFFA_custom_icon_list_' . $option_name ] ) ) {
- $icon_sets_list[ $this->version ][ $option_name ] = $label;
- }
-
- update_option( 'ACFFA_custom_icon_sets_list', $icon_sets_list, false );
- }
-
- private function remove_icon_set( $custom_icon_sets_list, $icon_set_name, $list_only = false )
- {
- if ( ! $custom_icon_sets_list ) {
- $custom_icon_sets_list = get_option( 'ACFFA_custom_icon_sets_list' );
- }
-
- if ( ! isset( $custom_icon_sets_list[ $this->version ][ $icon_set_name ] ) ) {
- return;
- }
-
- unset( $custom_icon_sets_list[ $this->version ][ $icon_set_name ] );
-
- update_option( 'ACFFA_custom_icon_sets_list', $custom_icon_sets_list );
-
- if ( ! $list_only ) {
- delete_option( $icon_set_name );
- }
- }
-
- public function ajax_remove_icon_set()
- {
- $valid_nonce = check_ajax_referer( 'acffa_delete_set_' . $_POST['icon_set_name'], 'nonce', false );
-
- if ( ! $valid_nonce ) {
- wp_die( 'fail' );
- }
-
- $this->remove_icon_set( false, $_POST['icon_set_name'] );
-
- wp_die( 'success' );
- }
-
- public function hide_fontawesome_pro_blurbs( $show_blurbs )
- {
- $acffa_settings = get_option( 'acffa_settings' );
-
- if ( isset( $acffa_settings['acffa_kit_has_pro'] ) && $acffa_settings['acffa_kit_has_pro'] ) {
- $show_blurbs = false;
- }
-
- if ( version_compare( ACFFA_MAJOR_VERSION, 5, '=' ) && isset( $acffa_settings['acffa_pro_cdn'] ) && $acffa_settings['acffa_pro_cdn'] ) {
- $show_blurbs = false;
- }
-
- return $show_blurbs;
- }
-
- public function js_templates()
- {
- include_once ACFFA_DIRECTORY . '/assets/js/templates/tmpl-fa-kit.php';
- }
-
-}
-
-add_action( 'acf/init', [ new ACFFA_Admin, 'init' ], 10 );
+<?php
+/**
+ * =======================================
+ * Advanced Custom Fields Font Awesome Admin
+ * =======================================
+ *
+ *
+ * @author Matt Keys <https://profiles.wordpress.org/mattkeys>
+ */
+
+class ACFFA_Admin
+{
+ private $version;
+
+ public function init()
+ {
+ $this->version = 'v' . ACFFA_MAJOR_VERSION;
+
+ add_action( 'admin_notices', [ $this, 'show_upgrade_notice' ] );
+ add_action( 'admin_notices', [ $this, 'maybe_notify_cdn_error' ] );
+ add_filter( 'plugin_action_links', [ $this, 'add_settings_link' ], 10, 2 );
+ add_action( 'admin_menu', [ $this, 'add_settings_page' ], 100 );
+ add_action( 'admin_init', [ $this, 'register_settings' ] );
+ add_filter( 'pre_update_option_acffa_settings', [ $this, 'intercept_icon_set_save' ], 10, 2 );
+ add_filter( 'pre_update_option_acffa_settings', [ $this, 'maybe_refresh_icons' ], 20, 2 );
+ add_filter( 'pre_update_option_acffa_settings', [ $this, 'revoke_access_token' ], 20, 2 );
+ add_filter( 'pre_update_option_acffa_settings', [ $this, 'clear_search_config_cache' ], 20, 2 );
+ add_filter( 'pre_update_option_acffa_settings', [ $this, 'check_kits_settings' ], 25, 2 );
+ add_action( 'update_option_acffa_settings', [ $this, 'get_latest_version' ], 10, 3 );
+ add_action( 'admin_init', [ $this, 'check_kits_api_key_filter'], 10 );
+ add_action( 'wp_ajax_ACFFA_delete_icon_set', [ $this, 'ajax_remove_icon_set' ] );
+ add_filter( 'ACFFA_show_fontawesome_pro_blurbs', [ $this, 'hide_fontawesome_pro_blurbs' ], 5, 1 );
+
+ if ( version_compare( ACFFA_MAJOR_VERSION, 6, '>=' ) ) {
+ add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_acf_select2' ] );
+ add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts_v6' ] );
+ } else {
+ add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts_v5' ] );
+ }
+ }
+
+ public function show_upgrade_notice()
+ {
+ $acffa_settings = get_option( 'acffa_settings' );
+ if ( ! isset( $acffa_settings['show_upgrade_notice'] ) ) {
+ return;
+ }
+ ?>
+ <div class="notice notice-info is-dismissible">
+ <p><?php echo wp_kses(sprintf( __( 'Visit the new ACF <a href="%s">FontAwesome Settings</a> page to change FontAwesome icon version, or to create custom icon sets.', 'acf-font-awesome' ), admin_url( '/edit.php?post_type=acf-field-group&page=fontawesome-settings' ) ), array( 'a' =>