@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | * Bail if we are not in WP. |
| 14 | 14 | */ |
| 15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | - exit; |
|
| 16 | + exit; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -21,345 +21,345 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * A Class to be able to change settings for Font Awesome. |
|
| 26 | - * |
|
| 27 | - * Class WP_Font_Awesome_Settings |
|
| 28 | - * @since 1.0.10 Now able to pass wp.org theme check. |
|
| 29 | - * @since 1.0.11 Font Awesome Pro now supported. |
|
| 30 | - * @since 1.0.11 Font Awesome Kits now supported. |
|
| 31 | - * @since 1.0.13 RTL language support added. |
|
| 32 | - * @since 1.0.14 Warning added for v6 pro requires kit and will now not work if official FA plugin installed. |
|
| 33 | - * @since 1.0.15 Font Awesome will now load in the FSE if enable din teh backend. |
|
| 34 | - * @ver 1.0.15 |
|
| 35 | - * @todo decide how to implement textdomain |
|
| 36 | - */ |
|
| 37 | - class WP_Font_Awesome_Settings { |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Class version version. |
|
| 41 | - * |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 44 | - public $version = '1.0.15'; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Class textdomain. |
|
| 48 | - * |
|
| 49 | - * @var string |
|
| 50 | - */ |
|
| 51 | - public $textdomain = 'font-awesome-settings'; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Latest version of Font Awesome at time of publish published. |
|
| 55 | - * |
|
| 56 | - * @var string |
|
| 57 | - */ |
|
| 58 | - public $latest = "5.8.2"; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * The title. |
|
| 62 | - * |
|
| 63 | - * @var string |
|
| 64 | - */ |
|
| 65 | - public $name = 'Font Awesome'; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Holds the settings values. |
|
| 69 | - * |
|
| 70 | - * @var array |
|
| 71 | - */ |
|
| 72 | - private $settings; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * WP_Font_Awesome_Settings instance. |
|
| 76 | - * |
|
| 77 | - * @access private |
|
| 78 | - * @since 1.0.0 |
|
| 79 | - * @var WP_Font_Awesome_Settings There can be only one! |
|
| 80 | - */ |
|
| 81 | - private static $instance = null; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Main WP_Font_Awesome_Settings Instance. |
|
| 85 | - * |
|
| 86 | - * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
| 87 | - * |
|
| 88 | - * @since 1.0.0 |
|
| 89 | - * @static |
|
| 90 | - * @return WP_Font_Awesome_Settings - Main instance. |
|
| 91 | - */ |
|
| 92 | - public static function instance() { |
|
| 93 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
| 94 | - self::$instance = new WP_Font_Awesome_Settings; |
|
| 95 | - |
|
| 96 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
| 97 | - |
|
| 98 | - if ( is_admin() ) { |
|
| 99 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
| 100 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
| 101 | - add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return self::$instance; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Initiate the settings and add the required action hooks. |
|
| 112 | - * |
|
| 113 | - * @since 1.0.8 Settings name wrong - FIXED |
|
| 114 | - */ |
|
| 115 | - public function init() { |
|
| 116 | - $this->settings = $this->get_settings(); |
|
| 117 | - |
|
| 118 | - // check if the official plugin is active and use that instead if so. |
|
| 119 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
| 120 | - |
|
| 121 | - if ( $this->settings['type'] == 'CSS' ) { |
|
| 122 | - |
|
| 123 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
| 124 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
| 128 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
| 129 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 ); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - } else { |
|
| 133 | - |
|
| 134 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
| 135 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
| 139 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
| 140 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 ); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - // remove font awesome if set to do so |
|
| 145 | - if ( $this->settings['dequeue'] == '1' ) { |
|
| 146 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Add FA to the FSE. |
|
| 154 | - * |
|
| 155 | - * @param $editor_settings |
|
| 156 | - * @param $block_editor_context |
|
| 157 | - * |
|
| 158 | - * @return array |
|
| 159 | - */ |
|
| 160 | - public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
|
| 161 | - |
|
| 162 | - if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
|
| 163 | - $url = $this->get_url(); |
|
| 164 | - $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - return $editor_settings; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Add FA to the FSE. |
|
| 172 | - * |
|
| 173 | - * @param $editor_settings |
|
| 174 | - * @param $block_editor_context |
|
| 175 | - * |
|
| 176 | - * @return array |
|
| 177 | - */ |
|
| 178 | - public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){ |
|
| 179 | - |
|
| 180 | - $url = $this->get_url(); |
|
| 181 | - $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>"; |
|
| 182 | - |
|
| 183 | - return $editor_settings; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Adds the Font Awesome styles. |
|
| 188 | - */ |
|
| 189 | - public function enqueue_style() { |
|
| 190 | - // build url |
|
| 191 | - $url = $this->get_url(); |
|
| 192 | - |
|
| 193 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
| 194 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
| 195 | - wp_enqueue_style( 'font-awesome' ); |
|
| 196 | - |
|
| 197 | - // RTL language support CSS. |
|
| 198 | - if ( is_rtl() ) { |
|
| 199 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - if ( $this->settings['shims'] ) { |
|
| 203 | - $url = $this->get_url( true ); |
|
| 204 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
| 205 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
| 206 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Adds the Font Awesome JS. |
|
| 212 | - */ |
|
| 213 | - public function enqueue_scripts() { |
|
| 214 | - // build url |
|
| 215 | - $url = $this->get_url(); |
|
| 216 | - |
|
| 217 | - $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
| 218 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
| 219 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
| 220 | - wp_enqueue_script( 'font-awesome' ); |
|
| 221 | - |
|
| 222 | - if ( $this->settings['shims'] ) { |
|
| 223 | - $url = $this->get_url( true ); |
|
| 224 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
| 225 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
| 226 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Get the url of the Font Awesome files. |
|
| 232 | - * |
|
| 233 | - * @param bool $shims If this is a shim file or not. |
|
| 234 | - * |
|
| 235 | - * @return string The url to the file. |
|
| 236 | - */ |
|
| 237 | - public function get_url( $shims = false ) { |
|
| 238 | - $script = $shims ? 'v4-shims' : 'all'; |
|
| 239 | - $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
| 240 | - $type = $this->settings['type']; |
|
| 241 | - $version = $this->settings['version']; |
|
| 242 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
| 243 | - $url = ''; |
|
| 244 | - |
|
| 245 | - if ( $type == 'KIT' && $kit_url ) { |
|
| 246 | - if ( $shims ) { |
|
| 247 | - // if its a kit then we don't add shims here |
|
| 248 | - return ''; |
|
| 249 | - } |
|
| 250 | - $url .= $kit_url; // CDN |
|
| 251 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
| 252 | - } else { |
|
| 253 | - $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
| 254 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
| 255 | - $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
| 256 | - $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
| 257 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - return $url; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
| 265 | - * |
|
| 266 | - * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
| 267 | - * |
|
| 268 | - * @param $url |
|
| 269 | - * @param $original_url |
|
| 270 | - * @param $_context |
|
| 271 | - * |
|
| 272 | - * @return string The filtered url. |
|
| 273 | - */ |
|
| 274 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
| 275 | - |
|
| 276 | - if ( $_context == 'display' |
|
| 277 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
| 278 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
| 279 | - ) {// it's a font-awesome-url (probably) |
|
| 280 | - |
|
| 281 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
| 282 | - if ( $this->settings['type'] == 'JS' ) { |
|
| 283 | - if ( $this->settings['js-pseudo'] ) { |
|
| 284 | - $url .= "' data-search-pseudo-elements defer='defer"; |
|
| 285 | - } else { |
|
| 286 | - $url .= "' defer='defer"; |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - } else { |
|
| 290 | - $url = ''; // removing the url removes the file |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - return $url; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * Register the database settings with WordPress. |
|
| 300 | - */ |
|
| 301 | - public function register_settings() { |
|
| 302 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Add the WordPress settings menu item. |
|
| 307 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
| 308 | - */ |
|
| 309 | - public function menu_item() { |
|
| 310 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
| 311 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
| 312 | - $this, |
|
| 313 | - 'settings_page' |
|
| 314 | - ) ); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * Get the current Font Awesome output settings. |
|
| 319 | - * |
|
| 320 | - * @return array The array of settings. |
|
| 321 | - */ |
|
| 322 | - public function get_settings() { |
|
| 323 | - |
|
| 324 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
| 325 | - |
|
| 326 | - $defaults = array( |
|
| 327 | - 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
| 328 | - 'version' => '', // latest |
|
| 329 | - 'enqueue' => '', // front and backend |
|
| 330 | - 'shims' => '0', // default OFF now in 2020 |
|
| 331 | - 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
| 332 | - 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
| 333 | - 'pro' => '0', // if pro CDN url should be used |
|
| 334 | - 'kit-url' => '', // the kit url |
|
| 335 | - ); |
|
| 336 | - |
|
| 337 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Filter the Font Awesome settings. |
|
| 341 | - * |
|
| 342 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
| 343 | - */ |
|
| 344 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * The settings page html output. |
|
| 350 | - */ |
|
| 351 | - public function settings_page() { |
|
| 352 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 353 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
| 357 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
| 358 | - $this->get_latest_version( $force_api = true ); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
| 362 | - ?> |
|
| 24 | + /** |
|
| 25 | + * A Class to be able to change settings for Font Awesome. |
|
| 26 | + * |
|
| 27 | + * Class WP_Font_Awesome_Settings |
|
| 28 | + * @since 1.0.10 Now able to pass wp.org theme check. |
|
| 29 | + * @since 1.0.11 Font Awesome Pro now supported. |
|
| 30 | + * @since 1.0.11 Font Awesome Kits now supported. |
|
| 31 | + * @since 1.0.13 RTL language support added. |
|
| 32 | + * @since 1.0.14 Warning added for v6 pro requires kit and will now not work if official FA plugin installed. |
|
| 33 | + * @since 1.0.15 Font Awesome will now load in the FSE if enable din teh backend. |
|
| 34 | + * @ver 1.0.15 |
|
| 35 | + * @todo decide how to implement textdomain |
|
| 36 | + */ |
|
| 37 | + class WP_Font_Awesome_Settings { |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Class version version. |
|
| 41 | + * |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | + public $version = '1.0.15'; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Class textdomain. |
|
| 48 | + * |
|
| 49 | + * @var string |
|
| 50 | + */ |
|
| 51 | + public $textdomain = 'font-awesome-settings'; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Latest version of Font Awesome at time of publish published. |
|
| 55 | + * |
|
| 56 | + * @var string |
|
| 57 | + */ |
|
| 58 | + public $latest = "5.8.2"; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * The title. |
|
| 62 | + * |
|
| 63 | + * @var string |
|
| 64 | + */ |
|
| 65 | + public $name = 'Font Awesome'; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Holds the settings values. |
|
| 69 | + * |
|
| 70 | + * @var array |
|
| 71 | + */ |
|
| 72 | + private $settings; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * WP_Font_Awesome_Settings instance. |
|
| 76 | + * |
|
| 77 | + * @access private |
|
| 78 | + * @since 1.0.0 |
|
| 79 | + * @var WP_Font_Awesome_Settings There can be only one! |
|
| 80 | + */ |
|
| 81 | + private static $instance = null; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Main WP_Font_Awesome_Settings Instance. |
|
| 85 | + * |
|
| 86 | + * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
| 87 | + * |
|
| 88 | + * @since 1.0.0 |
|
| 89 | + * @static |
|
| 90 | + * @return WP_Font_Awesome_Settings - Main instance. |
|
| 91 | + */ |
|
| 92 | + public static function instance() { |
|
| 93 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
| 94 | + self::$instance = new WP_Font_Awesome_Settings; |
|
| 95 | + |
|
| 96 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
| 97 | + |
|
| 98 | + if ( is_admin() ) { |
|
| 99 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
| 100 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
| 101 | + add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + do_action( 'wp_font_awesome_settings_loaded' ); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return self::$instance; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Initiate the settings and add the required action hooks. |
|
| 112 | + * |
|
| 113 | + * @since 1.0.8 Settings name wrong - FIXED |
|
| 114 | + */ |
|
| 115 | + public function init() { |
|
| 116 | + $this->settings = $this->get_settings(); |
|
| 117 | + |
|
| 118 | + // check if the official plugin is active and use that instead if so. |
|
| 119 | + if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
| 120 | + |
|
| 121 | + if ( $this->settings['type'] == 'CSS' ) { |
|
| 122 | + |
|
| 123 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
| 124 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
| 128 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
| 129 | + add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 ); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + } else { |
|
| 133 | + |
|
| 134 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
| 135 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
| 139 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
| 140 | + add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 ); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + // remove font awesome if set to do so |
|
| 145 | + if ( $this->settings['dequeue'] == '1' ) { |
|
| 146 | + add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Add FA to the FSE. |
|
| 154 | + * |
|
| 155 | + * @param $editor_settings |
|
| 156 | + * @param $block_editor_context |
|
| 157 | + * |
|
| 158 | + * @return array |
|
| 159 | + */ |
|
| 160 | + public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
|
| 161 | + |
|
| 162 | + if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
|
| 163 | + $url = $this->get_url(); |
|
| 164 | + $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + return $editor_settings; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Add FA to the FSE. |
|
| 172 | + * |
|
| 173 | + * @param $editor_settings |
|
| 174 | + * @param $block_editor_context |
|
| 175 | + * |
|
| 176 | + * @return array |
|
| 177 | + */ |
|
| 178 | + public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){ |
|
| 179 | + |
|
| 180 | + $url = $this->get_url(); |
|
| 181 | + $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>"; |
|
| 182 | + |
|
| 183 | + return $editor_settings; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Adds the Font Awesome styles. |
|
| 188 | + */ |
|
| 189 | + public function enqueue_style() { |
|
| 190 | + // build url |
|
| 191 | + $url = $this->get_url(); |
|
| 192 | + |
|
| 193 | + wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
| 194 | + wp_register_style( 'font-awesome', $url, array(), null ); |
|
| 195 | + wp_enqueue_style( 'font-awesome' ); |
|
| 196 | + |
|
| 197 | + // RTL language support CSS. |
|
| 198 | + if ( is_rtl() ) { |
|
| 199 | + wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + if ( $this->settings['shims'] ) { |
|
| 203 | + $url = $this->get_url( true ); |
|
| 204 | + wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
| 205 | + wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
| 206 | + wp_enqueue_style( 'font-awesome-shims' ); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Adds the Font Awesome JS. |
|
| 212 | + */ |
|
| 213 | + public function enqueue_scripts() { |
|
| 214 | + // build url |
|
| 215 | + $url = $this->get_url(); |
|
| 216 | + |
|
| 217 | + $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
| 218 | + call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
| 219 | + wp_register_script( 'font-awesome', $url, array(), null ); |
|
| 220 | + wp_enqueue_script( 'font-awesome' ); |
|
| 221 | + |
|
| 222 | + if ( $this->settings['shims'] ) { |
|
| 223 | + $url = $this->get_url( true ); |
|
| 224 | + call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
| 225 | + wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
| 226 | + wp_enqueue_script( 'font-awesome-shims' ); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Get the url of the Font Awesome files. |
|
| 232 | + * |
|
| 233 | + * @param bool $shims If this is a shim file or not. |
|
| 234 | + * |
|
| 235 | + * @return string The url to the file. |
|
| 236 | + */ |
|
| 237 | + public function get_url( $shims = false ) { |
|
| 238 | + $script = $shims ? 'v4-shims' : 'all'; |
|
| 239 | + $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
| 240 | + $type = $this->settings['type']; |
|
| 241 | + $version = $this->settings['version']; |
|
| 242 | + $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
| 243 | + $url = ''; |
|
| 244 | + |
|
| 245 | + if ( $type == 'KIT' && $kit_url ) { |
|
| 246 | + if ( $shims ) { |
|
| 247 | + // if its a kit then we don't add shims here |
|
| 248 | + return ''; |
|
| 249 | + } |
|
| 250 | + $url .= $kit_url; // CDN |
|
| 251 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
| 252 | + } else { |
|
| 253 | + $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
| 254 | + $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
| 255 | + $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
| 256 | + $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
| 257 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + return $url; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
| 265 | + * |
|
| 266 | + * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
| 267 | + * |
|
| 268 | + * @param $url |
|
| 269 | + * @param $original_url |
|
| 270 | + * @param $_context |
|
| 271 | + * |
|
| 272 | + * @return string The filtered url. |
|
| 273 | + */ |
|
| 274 | + public function remove_font_awesome( $url, $original_url, $_context ) { |
|
| 275 | + |
|
| 276 | + if ( $_context == 'display' |
|
| 277 | + && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
| 278 | + && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
| 279 | + ) {// it's a font-awesome-url (probably) |
|
| 280 | + |
|
| 281 | + if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
| 282 | + if ( $this->settings['type'] == 'JS' ) { |
|
| 283 | + if ( $this->settings['js-pseudo'] ) { |
|
| 284 | + $url .= "' data-search-pseudo-elements defer='defer"; |
|
| 285 | + } else { |
|
| 286 | + $url .= "' defer='defer"; |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + } else { |
|
| 290 | + $url = ''; // removing the url removes the file |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + return $url; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * Register the database settings with WordPress. |
|
| 300 | + */ |
|
| 301 | + public function register_settings() { |
|
| 302 | + register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Add the WordPress settings menu item. |
|
| 307 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
| 308 | + */ |
|
| 309 | + public function menu_item() { |
|
| 310 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
| 311 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
| 312 | + $this, |
|
| 313 | + 'settings_page' |
|
| 314 | + ) ); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * Get the current Font Awesome output settings. |
|
| 319 | + * |
|
| 320 | + * @return array The array of settings. |
|
| 321 | + */ |
|
| 322 | + public function get_settings() { |
|
| 323 | + |
|
| 324 | + $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
| 325 | + |
|
| 326 | + $defaults = array( |
|
| 327 | + 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
| 328 | + 'version' => '', // latest |
|
| 329 | + 'enqueue' => '', // front and backend |
|
| 330 | + 'shims' => '0', // default OFF now in 2020 |
|
| 331 | + 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
| 332 | + 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
| 333 | + 'pro' => '0', // if pro CDN url should be used |
|
| 334 | + 'kit-url' => '', // the kit url |
|
| 335 | + ); |
|
| 336 | + |
|
| 337 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Filter the Font Awesome settings. |
|
| 341 | + * |
|
| 342 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
| 343 | + */ |
|
| 344 | + return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * The settings page html output. |
|
| 350 | + */ |
|
| 351 | + public function settings_page() { |
|
| 352 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
| 353 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
| 357 | + if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
| 358 | + $this->get_latest_version( $force_api = true ); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
| 362 | + ?> |
|
| 363 | 363 | <style> |
| 364 | 364 | .wpfas-kit-show { |
| 365 | 365 | display: none; |
@@ -377,10 +377,10 @@ discard block |
||
| 377 | 377 | <h1><?php echo $this->name; ?></h1> |
| 378 | 378 | <form method="post" action="options.php" class="fas-settings-form"> |
| 379 | 379 | <?php |
| 380 | - settings_fields( 'wp-font-awesome-settings' ); |
|
| 381 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
| 382 | - $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
|
| 383 | - ?> |
|
| 380 | + settings_fields( 'wp-font-awesome-settings' ); |
|
| 381 | + do_settings_sections( 'wp-font-awesome-settings' ); |
|
| 382 | + $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
|
| 383 | + ?> |
|
| 384 | 384 | <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
| 385 | 385 | <tr valign="top"> |
| 386 | 386 | <th scope="row"><label |
@@ -406,12 +406,12 @@ discard block |
||
| 406 | 406 | value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" |
| 407 | 407 | placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
| 408 | 408 | <span><?php |
| 409 | - echo sprintf( |
|
| 410 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
| 411 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
| 412 | - '</a>' |
|
| 413 | - ); |
|
| 414 | - ?></span> |
|
| 409 | + echo sprintf( |
|
| 410 | + __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
| 411 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
| 412 | + '</a>' |
|
| 413 | + ); |
|
| 414 | + ?></span> |
|
| 415 | 415 | </td> |
| 416 | 416 | </tr> |
| 417 | 417 | |
@@ -480,14 +480,14 @@ discard block |
||
| 480 | 480 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
| 481 | 481 | value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
| 482 | 482 | <span><?php |
| 483 | - echo sprintf( |
|
| 484 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
| 485 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
|
| 486 | - ' <i class="fas fa-external-link-alt"></i></a>', |
|
| 487 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
|
| 488 | - ' <i class="fas fa-external-link-alt"></i></a>' |
|
| 489 | - ); |
|
| 490 | - ?></span> |
|
| 483 | + echo sprintf( |
|
| 484 | + __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
| 485 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
|
| 486 | + ' <i class="fas fa-external-link-alt"></i></a>', |
|
| 487 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
|
| 488 | + ' <i class="fas fa-external-link-alt"></i></a>' |
|
| 489 | + ); |
|
| 490 | + ?></span> |
|
| 491 | 491 | </td> |
| 492 | 492 | </tr> |
| 493 | 493 | |
@@ -531,8 +531,8 @@ discard block |
||
| 531 | 531 | </table> |
| 532 | 532 | <div class="fas-buttons"> |
| 533 | 533 | <?php |
| 534 | - submit_button(); |
|
| 535 | - ?> |
|
| 534 | + submit_button(); |
|
| 535 | + ?> |
|
| 536 | 536 | <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 14,000+ more icons with Font Awesome Pro','font-awesome-settings'); ?> <i class="fas fa-external-link-alt"></i></a></p> |
| 537 | 537 | |
| 538 | 538 | </div> |
@@ -556,126 +556,126 @@ discard block |
||
| 556 | 556 | } |
| 557 | 557 | </style> |
| 558 | 558 | <?php |
| 559 | - } |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * Check a version number is valid and if so return it or else return an empty string. |
|
| 564 | - * |
|
| 565 | - * @param $version string The version number to check. |
|
| 566 | - * |
|
| 567 | - * @since 1.0.6 |
|
| 568 | - * |
|
| 569 | - * @return string Either a valid version number or an empty string. |
|
| 570 | - */ |
|
| 571 | - public function validate_version_number( $version ) { |
|
| 572 | - |
|
| 573 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
| 574 | - // valid |
|
| 575 | - } else { |
|
| 576 | - $version = '';// not validated |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - return $version; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Get the latest version of Font Awesome. |
|
| 585 | - * |
|
| 586 | - * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
| 587 | - * |
|
| 588 | - * @since 1.0.7 |
|
| 589 | - * @return mixed|string The latest version number found. |
|
| 590 | - */ |
|
| 591 | - public function get_latest_version( $force_api = false ) { |
|
| 592 | - $latest_version = $this->latest; |
|
| 593 | - |
|
| 594 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
| 595 | - |
|
| 596 | - if ( $cache === false || $force_api ) { // its not set |
|
| 597 | - $api_ver = $this->get_latest_version_from_api(); |
|
| 598 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
| 599 | - $latest_version = $api_ver; |
|
| 600 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
| 601 | - } |
|
| 602 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
| 603 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
| 604 | - $latest_version = $cache; |
|
| 605 | - } |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - return $latest_version; |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * Get the latest Font Awesome version from the github API. |
|
| 613 | - * |
|
| 614 | - * @since 1.0.7 |
|
| 615 | - * @return string The latest version number or `0` on API fail. |
|
| 616 | - */ |
|
| 617 | - public function get_latest_version_from_api() { |
|
| 618 | - $version = "0"; |
|
| 619 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
| 620 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
| 621 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 622 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
| 623 | - $version = $api_response['tag_name']; |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - return $version; |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * Inline CSS for RTL language support. |
|
| 632 | - * |
|
| 633 | - * @since 1.0.13 |
|
| 634 | - * @return string Inline CSS. |
|
| 635 | - */ |
|
| 636 | - public function rtl_inline_css() { |
|
| 637 | - $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
| 638 | - |
|
| 639 | - return $inline_css; |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - /** |
|
| 643 | - * Show any warnings as an admin notice. |
|
| 644 | - * |
|
| 645 | - * @return void |
|
| 646 | - */ |
|
| 647 | - public function admin_notices(){ |
|
| 648 | - $settings = $this->settings; |
|
| 649 | - |
|
| 650 | - if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
| 651 | - |
|
| 652 | - if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
| 653 | - ?> |
|
| 559 | + } |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * Check a version number is valid and if so return it or else return an empty string. |
|
| 564 | + * |
|
| 565 | + * @param $version string The version number to check. |
|
| 566 | + * |
|
| 567 | + * @since 1.0.6 |
|
| 568 | + * |
|
| 569 | + * @return string Either a valid version number or an empty string. |
|
| 570 | + */ |
|
| 571 | + public function validate_version_number( $version ) { |
|
| 572 | + |
|
| 573 | + if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
| 574 | + // valid |
|
| 575 | + } else { |
|
| 576 | + $version = '';// not validated |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + return $version; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Get the latest version of Font Awesome. |
|
| 585 | + * |
|
| 586 | + * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
| 587 | + * |
|
| 588 | + * @since 1.0.7 |
|
| 589 | + * @return mixed|string The latest version number found. |
|
| 590 | + */ |
|
| 591 | + public function get_latest_version( $force_api = false ) { |
|
| 592 | + $latest_version = $this->latest; |
|
| 593 | + |
|
| 594 | + $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
| 595 | + |
|
| 596 | + if ( $cache === false || $force_api ) { // its not set |
|
| 597 | + $api_ver = $this->get_latest_version_from_api(); |
|
| 598 | + if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
| 599 | + $latest_version = $api_ver; |
|
| 600 | + set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
| 601 | + } |
|
| 602 | + } elseif ( $this->validate_version_number( $cache ) ) { |
|
| 603 | + if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
| 604 | + $latest_version = $cache; |
|
| 605 | + } |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + return $latest_version; |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + /** |
|
| 612 | + * Get the latest Font Awesome version from the github API. |
|
| 613 | + * |
|
| 614 | + * @since 1.0.7 |
|
| 615 | + * @return string The latest version number or `0` on API fail. |
|
| 616 | + */ |
|
| 617 | + public function get_latest_version_from_api() { |
|
| 618 | + $version = "0"; |
|
| 619 | + $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
| 620 | + if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
| 621 | + $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 622 | + if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
| 623 | + $version = $api_response['tag_name']; |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + return $version; |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * Inline CSS for RTL language support. |
|
| 632 | + * |
|
| 633 | + * @since 1.0.13 |
|
| 634 | + * @return string Inline CSS. |
|
| 635 | + */ |
|
| 636 | + public function rtl_inline_css() { |
|
| 637 | + $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
| 638 | + |
|
| 639 | + return $inline_css; |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + /** |
|
| 643 | + * Show any warnings as an admin notice. |
|
| 644 | + * |
|
| 645 | + * @return void |
|
| 646 | + */ |
|
| 647 | + public function admin_notices(){ |
|
| 648 | + $settings = $this->settings; |
|
| 649 | + |
|
| 650 | + if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
| 651 | + |
|
| 652 | + if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
| 653 | + ?> |
|
| 654 | 654 | <div class="notice notice-error is-dismissible"> |
| 655 | 655 | <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'font-awesome-settings' ); ?></p> |
| 656 | 656 | </div> |
| 657 | 657 | <?php |
| 658 | - } |
|
| 658 | + } |
|
| 659 | 659 | |
| 660 | - }else{ |
|
| 661 | - if ( ! empty( $settings ) ) { |
|
| 662 | - if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
| 663 | - $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
|
| 664 | - ?> |
|
| 660 | + }else{ |
|
| 661 | + if ( ! empty( $settings ) ) { |
|
| 662 | + if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
| 663 | + $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
|
| 664 | + ?> |
|
| 665 | 665 | <div class="notice notice-error is-dismissible"> |
| 666 | 666 | <p><?php echo sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'font-awesome-settings' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p> |
| 667 | 667 | </div> |
| 668 | 668 | <?php |
| 669 | - } |
|
| 670 | - } |
|
| 671 | - } |
|
| 669 | + } |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | 672 | |
| 673 | - } |
|
| 673 | + } |
|
| 674 | 674 | |
| 675 | - } |
|
| 675 | + } |
|
| 676 | 676 | |
| 677 | - /** |
|
| 678 | - * Run the class if found. |
|
| 679 | - */ |
|
| 680 | - WP_Font_Awesome_Settings::instance(); |
|
| 677 | + /** |
|
| 678 | + * Run the class if found. |
|
| 679 | + */ |
|
| 680 | + WP_Font_Awesome_Settings::instance(); |
|
| 681 | 681 | } |