| Total Complexity | 75 |
| Total Lines | 630 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like WP_Font_Awesome_Settings often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use WP_Font_Awesome_Settings, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 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() { |
||
| 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 ) { |
||
| 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 ) { |
||
| 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 | <style> |
||
| 364 | .wpfas-kit-show { |
||
| 365 | display: none; |
||
| 366 | } |
||
| 367 | |||
| 368 | .wpfas-kit-set .wpfas-kit-hide { |
||
| 369 | display: none; |
||
| 370 | } |
||
| 371 | |||
| 372 | .wpfas-kit-set .wpfas-kit-show { |
||
| 373 | display: table-row; |
||
| 374 | } |
||
| 375 | </style> |
||
| 376 | <div class="wrap"> |
||
| 377 | <h1><?php echo $this->name; ?></h1> |
||
| 378 | <form method="post" action="options.php" class="fas-settings-form"> |
||
| 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 | ?> |
||
| 384 | <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
||
| 385 | <tr valign="top"> |
||
| 386 | <th scope="row"><label |
||
| 387 | for="wpfas-type"><?php _e( 'Type', 'font-awesome-settings' ); ?></label></th> |
||
| 388 | <td> |
||
| 389 | <select name="wp-font-awesome-settings[type]" id="wpfas-type" |
||
| 390 | onchange="if(this.value=='KIT'){jQuery('.wpfas-table-settings').addClass('wpfas-kit-set');}else{jQuery('.wpfas-table-settings').removeClass('wpfas-kit-set');}"> |
||
| 391 | <option |
||
| 392 | value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e( 'CSS (default)', 'font-awesome-settings' ); ?></option> |
||
| 393 | <option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option> |
||
| 394 | <option |
||
| 395 | value="KIT" <?php selected( $this->settings['type'], 'KIT' ); ?>><?php _e( 'Kits (settings managed on fontawesome.com)', 'font-awesome-settings' ); ?></option> |
||
| 396 | </select> |
||
| 397 | </td> |
||
| 398 | </tr> |
||
| 399 | |||
| 400 | <tr valign="top" class="wpfas-kit-show"> |
||
| 401 | <th scope="row"><label |
||
| 402 | for="wpfas-kit-url"><?php _e( 'Kit URL', 'font-awesome-settings' ); ?></label></th> |
||
| 403 | <td> |
||
| 404 | <input class="regular-text" id="wpfas-kit-url" type="url" |
||
| 405 | name="wp-font-awesome-settings[kit-url]" |
||
| 406 | value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" |
||
| 407 | placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
||
| 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> |
||
| 415 | </td> |
||
| 416 | </tr> |
||
| 417 | |||
| 418 | <tr valign="top" class="wpfas-kit-hide"> |
||
| 419 | <th scope="row"><label |
||
| 420 | for="wpfas-version"><?php _e( 'Version', 'font-awesome-settings' ); ?></label></th> |
||
| 421 | <td> |
||
| 422 | <select name="wp-font-awesome-settings[version]" id="wpfas-version"> |
||
| 423 | <option |
||
| 424 | value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo sprintf( __( 'Latest - %s (default)', 'font-awesome-settings' ), $this->get_latest_version() ); ?> |
||
| 425 | </option> |
||
| 426 | <option value="6.1.0" <?php selected( $this->settings['version'], '6.1.0' ); ?>> |
||
| 427 | 6.1.0 |
||
| 428 | </option> |
||
| 429 | <option value="6.0.0" <?php selected( $this->settings['version'], '6.0.0' ); ?>> |
||
| 430 | 6.0.0 |
||
| 431 | </option> |
||
| 432 | <option value="5.15.4" <?php selected( $this->settings['version'], '5.15.4' ); ?>> |
||
| 433 | 5.15.4 |
||
| 434 | </option> |
||
| 435 | <option value="5.6.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>> |
||
| 436 | 5.6.0 |
||
| 437 | </option> |
||
| 438 | <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>> |
||
| 439 | 5.5.0 |
||
| 440 | </option> |
||
| 441 | <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>> |
||
| 442 | 5.4.0 |
||
| 443 | </option> |
||
| 444 | <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>> |
||
| 445 | 5.3.0 |
||
| 446 | </option> |
||
| 447 | <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>> |
||
| 448 | 5.2.0 |
||
| 449 | </option> |
||
| 450 | <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>> |
||
| 451 | 5.1.0 |
||
| 452 | </option> |
||
| 453 | <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>> |
||
| 454 | 4.7.1 (CSS only) |
||
| 455 | </option> |
||
| 456 | </select> |
||
| 457 | </td> |
||
| 458 | </tr> |
||
| 459 | |||
| 460 | <tr valign="top"> |
||
| 461 | <th scope="row"><label |
||
| 462 | for="wpfas-enqueue"><?php _e( 'Enqueue', 'font-awesome-settings' ); ?></label></th> |
||
| 463 | <td> |
||
| 464 | <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue"> |
||
| 465 | <option |
||
| 466 | value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)', 'font-awesome-settings' ); ?></option> |
||
| 467 | <option |
||
| 468 | value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend', 'font-awesome-settings' ); ?></option> |
||
| 469 | <option |
||
| 470 | value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend', 'font-awesome-settings' ); ?></option> |
||
| 471 | </select> |
||
| 472 | </td> |
||
| 473 | </tr> |
||
| 474 | |||
| 475 | <tr valign="top" class="wpfas-kit-hide"> |
||
| 476 | <th scope="row"><label |
||
| 477 | for="wpfas-pro"><?php _e( 'Enable pro', 'font-awesome-settings' ); ?></label></th> |
||
| 478 | <td> |
||
| 479 | <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/> |
||
| 480 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
||
| 481 | value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
||
| 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> |
||
| 491 | </td> |
||
| 492 | </tr> |
||
| 493 | |||
| 494 | <tr valign="top" class="wpfas-kit-hide"> |
||
| 495 | <th scope="row"><label |
||
| 496 | for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility', 'font-awesome-settings' ); ?></label> |
||
| 497 | </th> |
||
| 498 | <td> |
||
| 499 | <input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/> |
||
| 500 | <input type="checkbox" name="wp-font-awesome-settings[shims]" |
||
| 501 | value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims"/> |
||
| 502 | <span><?php _e( 'This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings' ); ?></span> |
||
| 503 | </td> |
||
| 504 | </tr> |
||
| 505 | |||
| 506 | <tr valign="top" class="wpfas-kit-hide"> |
||
| 507 | <th scope="row"><label |
||
| 508 | for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)', 'font-awesome-settings' ); ?></label> |
||
| 509 | </th> |
||
| 510 | <td> |
||
| 511 | <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/> |
||
| 512 | <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]" |
||
| 513 | value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?> |
||
| 514 | id="wpfas-js-pseudo"/> |
||
| 515 | <span><?php _e( 'Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings' ); ?></span> |
||
| 516 | </td> |
||
| 517 | </tr> |
||
| 518 | |||
| 519 | <tr valign="top"> |
||
| 520 | <th scope="row"><label |
||
| 521 | for="wpfas-dequeue"><?php _e( 'Dequeue', 'font-awesome-settings' ); ?></label></th> |
||
| 522 | <td> |
||
| 523 | <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/> |
||
| 524 | <input type="checkbox" name="wp-font-awesome-settings[dequeue]" |
||
| 525 | value="1" <?php checked( $this->settings['dequeue'], '1' ); ?> |
||
| 526 | id="wpfas-dequeue"/> |
||
| 527 | <span><?php _e( 'This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings' ); ?></span> |
||
| 528 | </td> |
||
| 529 | </tr> |
||
| 530 | |||
| 531 | </table> |
||
| 532 | <div class="fas-buttons"> |
||
| 533 | <?php |
||
| 534 | submit_button(); |
||
| 535 | ?> |
||
| 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 | |||
| 538 | </div> |
||
| 539 | </form> |
||
| 540 | |||
| 541 | <div id="wpfas-version"><?php echo sprintf(__( 'Version: %s (affiliate links provided)', 'font-awesome-settings' ), $this->version ); ?></div> |
||
| 542 | </div> |
||
| 543 | |||
| 544 | <style> |
||
| 545 | .fas-settings-form .submit{ |
||
| 546 | display: inline; |
||
| 547 | padding-right: 5px; |
||
| 548 | } |
||
| 549 | |||
| 550 | .fas-settings-form .fas-buttons{ |
||
| 551 | margin: 15px 0; |
||
| 552 | } |
||
| 553 | #wpfas-version{ |
||
| 554 | margin-top: 30px; |
||
| 555 | color: #646970; |
||
| 556 | } |
||
| 557 | </style> |
||
| 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() { |
||
| 640 | } |
||
| 641 | |||
| 642 | /** |
||
| 643 | * Show any warnings as an admin notice. |
||
| 644 | * |
||
| 645 | * @return void |
||
| 646 | */ |
||
| 647 | public function admin_notices(){ |
||
| 667 | </div> |
||
| 668 | <?php |
||
| 669 | } |
||
| 670 | } |
||
| 671 | } |
||
| 672 | |||
| 673 | } |
||
| 674 | |||
| 675 | } |
||
| 676 | |||
| 677 | /** |
||
| 682 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.