Total Complexity | 181 |
Total Lines | 1021 |
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 |
||
29 | class WP_Font_Awesome_Settings { |
||
30 | |||
31 | /** |
||
32 | * Class version version. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | public $version = '1.1.10'; |
||
37 | |||
38 | /** |
||
39 | * Class textdomain. |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | public $textdomain = 'font-awesome-settings'; |
||
44 | |||
45 | /** |
||
46 | * Latest version of Font Awesome at time of publish published. |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | public $latest = "6.4.2"; |
||
51 | |||
52 | /** |
||
53 | * The title. |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | public $name = 'Font Awesome'; |
||
58 | |||
59 | /** |
||
60 | * Holds the settings values. |
||
61 | * |
||
62 | * @var array |
||
63 | */ |
||
64 | private $settings; |
||
65 | |||
66 | /** |
||
67 | * WP_Font_Awesome_Settings instance. |
||
68 | * |
||
69 | * @access private |
||
70 | * @since 1.0.0 |
||
71 | * @var WP_Font_Awesome_Settings There can be only one! |
||
72 | */ |
||
73 | private static $instance = null; |
||
74 | |||
75 | /** |
||
76 | * Main WP_Font_Awesome_Settings Instance. |
||
77 | * |
||
78 | * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
||
79 | * |
||
80 | * @since 1.0.0 |
||
81 | * @static |
||
82 | * @return WP_Font_Awesome_Settings - Main instance. |
||
83 | */ |
||
84 | public static function instance() { |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * Define any constants that may be needed by other packages. |
||
105 | * |
||
106 | * @return void |
||
107 | */ |
||
108 | public function constants(){ |
||
109 | |||
110 | // register iconpicker constant |
||
111 | if ( ! defined( 'FAS_ICONPICKER_JS_URL' ) ) { |
||
112 | $url = $this->get_path_url(); |
||
113 | $version = $this->settings['version']; |
||
114 | |||
115 | if( !$version || version_compare($version,'5.999','>')){ |
||
116 | $url .= 'assets/js/fa-iconpicker-v6.min.js'; |
||
117 | }else{ |
||
118 | $url .= 'assets/js/fa-iconpicker-v5.min.js'; |
||
119 | } |
||
120 | |||
121 | define( 'FAS_ICONPICKER_JS_URL', $url ); |
||
122 | |||
123 | } |
||
124 | |||
125 | // Set a constant if pro enabled |
||
126 | if ( ! defined( 'FAS_PRO' ) && $this->settings['pro'] ) { |
||
127 | define( 'FAS_PRO', true ); |
||
128 | } |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Get the url path to the current folder. |
||
133 | * |
||
134 | * @return string |
||
135 | */ |
||
136 | public function get_path_url() { |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * Initiate the settings and add the required action hooks. |
||
154 | * |
||
155 | * @since 1.0.8 Settings name wrong - FIXED |
||
156 | */ |
||
157 | public function init() { |
||
158 | // Download fontawesome locally. |
||
159 | add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 ); |
||
160 | add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
||
161 | |||
162 | $this->settings = $this->get_settings(); |
||
163 | |||
164 | // Check if the official plugin is active and use that instead if so. |
||
165 | if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
||
166 | if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
||
167 | add_action( 'admin_head', array( $this, 'add_generator' ), 99 ); |
||
168 | } |
||
169 | |||
170 | if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
||
171 | add_action( 'wp_head', array( $this, 'add_generator' ), 99 ); |
||
172 | } |
||
173 | |||
174 | if ( $this->settings['type'] == 'CSS' ) { |
||
175 | if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
||
176 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
||
177 | //add_action( 'wp_footer', array( $this, 'enqueue_style' ), 5000 ); // not sure why this was added, seems to break frontend |
||
178 | } |
||
179 | |||
180 | if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
||
181 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
||
182 | add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 ); |
||
183 | } |
||
184 | } else { |
||
185 | $enqueue = false; |
||
186 | |||
187 | if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
||
188 | $enqueue = true; |
||
189 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
||
190 | } |
||
191 | |||
192 | if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
||
193 | $enqueue = true; |
||
194 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
||
195 | add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 ); |
||
196 | } |
||
197 | |||
198 | if ( $enqueue ) { |
||
199 | add_filter( 'script_loader_tag', array( $this, 'script_loader_tag' ), 20, 3 ); |
||
200 | } |
||
201 | } |
||
202 | |||
203 | // remove font awesome if set to do so |
||
204 | if ( $this->settings['dequeue'] == '1' ) { |
||
205 | add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
||
206 | } |
||
207 | } |
||
208 | |||
209 | } |
||
210 | |||
211 | /** |
||
212 | * Add FA to the FSE. |
||
213 | * |
||
214 | * @param $editor_settings |
||
215 | * @param $block_editor_context |
||
216 | * |
||
217 | * @return array |
||
218 | */ |
||
219 | public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
||
|
|||
220 | |||
221 | if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
||
222 | $url = $this->get_url(); |
||
223 | $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
||
224 | } |
||
225 | |||
226 | return $editor_settings; |
||
227 | } |
||
228 | |||
229 | /** |
||
230 | * Add FA to the FSE. |
||
231 | * |
||
232 | * @param $editor_settings |
||
233 | * @param $block_editor_context |
||
234 | * |
||
235 | * @return array |
||
236 | */ |
||
237 | public function enqueue_editor_scripts( $editor_settings, $block_editor_context ) { |
||
238 | $url = $this->get_url(); |
||
239 | |||
240 | $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js' defer crossorigin='anonymous'></script>"; |
||
241 | |||
242 | return $editor_settings; |
||
243 | } |
||
244 | |||
245 | /** |
||
246 | * Adds the Font Awesome styles. |
||
247 | */ |
||
248 | public function enqueue_style() { |
||
249 | // build url |
||
250 | $url = $this->get_url(); |
||
251 | $version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null; |
||
252 | |||
253 | wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
||
254 | wp_register_style( 'font-awesome', $url, array(), $version ); |
||
255 | wp_enqueue_style( 'font-awesome' ); |
||
256 | |||
257 | // RTL language support CSS. |
||
258 | if ( is_rtl() ) { |
||
259 | wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
||
260 | } |
||
261 | |||
262 | if ( $this->settings['shims'] ) { |
||
263 | $url = $this->get_url( true ); |
||
264 | wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
||
265 | wp_register_style( 'font-awesome-shims', $url, array(), $version ); |
||
266 | wp_enqueue_style( 'font-awesome-shims' ); |
||
267 | } |
||
268 | } |
||
269 | |||
270 | /** |
||
271 | * Adds the Font Awesome JS. |
||
272 | */ |
||
273 | public function enqueue_scripts() { |
||
274 | // build url |
||
275 | $url = $this->get_url(); |
||
276 | |||
277 | $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
||
278 | call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
||
279 | wp_register_script( 'font-awesome', $url, array(), null ); |
||
280 | wp_enqueue_script( 'font-awesome' ); |
||
281 | |||
282 | if ( $this->settings['shims'] ) { |
||
283 | $url = $this->get_url( true ); |
||
284 | call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
||
285 | wp_register_script( 'font-awesome-shims', $url, array(), null ); |
||
286 | wp_enqueue_script( 'font-awesome-shims' ); |
||
287 | } |
||
288 | } |
||
289 | |||
290 | /** |
||
291 | * Get the url of the Font Awesome files. |
||
292 | * |
||
293 | * @param bool $shims If this is a shim file or not. |
||
294 | * @param bool $local Load locally if allowed. |
||
295 | * |
||
296 | * @return string The url to the file. |
||
297 | */ |
||
298 | public function get_url( $shims = false, $local = true ) { |
||
330 | } |
||
331 | |||
332 | /** |
||
333 | * Try and remove any other versions of Font Awesome added by other plugins/themes. |
||
334 | * |
||
335 | * 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. |
||
336 | * |
||
337 | * @param $url |
||
338 | * @param $original_url |
||
339 | * @param $_context |
||
340 | * |
||
341 | * @return string The filtered url. |
||
342 | */ |
||
343 | public function remove_font_awesome( $url, $original_url, $_context ) { |
||
365 | } |
||
366 | |||
367 | /** |
||
368 | * Register the database settings with WordPress. |
||
369 | */ |
||
370 | public function register_settings() { |
||
371 | register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
||
372 | } |
||
373 | |||
374 | /** |
||
375 | * Add the WordPress settings menu item. |
||
376 | * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
||
377 | */ |
||
378 | public function menu_item() { |
||
379 | $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
||
380 | call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
||
381 | $this, |
||
382 | 'settings_page' |
||
383 | ) ); |
||
384 | } |
||
385 | |||
386 | /** |
||
387 | * Get the current Font Awesome output settings. |
||
388 | * |
||
389 | * @return array The array of settings. |
||
390 | */ |
||
391 | public function get_settings() { |
||
415 | } |
||
416 | |||
417 | /** |
||
418 | * The settings page html output. |
||
419 | */ |
||
420 | public function settings_page() { |
||
421 | if ( ! current_user_can( 'manage_options' ) ) { |
||
422 | wp_die( __( 'You do not have sufficient permissions to access this page.', 'ayecode-connect' ) ); |
||
423 | } |
||
424 | |||
425 | // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
||
426 | if ( isset( $_REQUEST['force-version-check'] ) ) { |
||
427 | $this->get_latest_version( $force_api = true ); |
||
428 | } |
||
429 | |||
430 | if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
||
431 | ?> |
||
432 | <style> |
||
433 | .wpfas-kit-show { |
||
434 | display: none; |
||
435 | } |
||
436 | .wpfas-kit-set .wpfas-kit-hide,.wpfas-has-pro .wpfas-hide-pro { |
||
437 | display: none; |
||
438 | } |
||
439 | .wpfas-kit-set .wpfas-kit-show { |
||
440 | display: table-row; |
||
441 | } |
||
442 | .fas-settings-form .submit{ |
||
443 | display: inline; |
||
444 | padding-right: 5px; |
||
445 | } |
||
446 | .fas-settings-form .fas-buttons{ |
||
447 | margin: 15px 0; |
||
448 | } |
||
449 | #wpfas-version{ |
||
450 | color: #646970; |
||
451 | } |
||
452 | </style> |
||
453 | <div class="wrap"> |
||
454 | <h1><?php echo $this->name; ?></h1> |
||
455 | <form method="post" action="options.php" class="fas-settings-form"> |
||
456 | <?php |
||
457 | settings_fields( 'wp-font-awesome-settings' ); |
||
458 | do_settings_sections( 'wp-font-awesome-settings' ); |
||
459 | $table_class = ''; |
||
460 | if ( $this->settings['type'] ) { |
||
461 | $table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set'; |
||
462 | } |
||
463 | if ( ! empty( $this->settings['pro'] ) ) { |
||
464 | $table_class .= ' wpfas-has-pro'; |
||
465 | } |
||
466 | ?> |
||
467 | <?php if ( $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ) { ?> |
||
468 | <?php if ( $this->has_local() ) { ?> |
||
469 | <div class="notice notice-info"><p><strong><?php _e( 'Font Awesome fonts are loading locally.', 'ayecode-connect' ); ?></strong></p></div> |
||
470 | <?php } else { ?> |
||
471 | <div class="notice notice-error"><p><strong><?php _e( 'Font Awesome fonts are not loading locally!', 'ayecode-connect' ); ?></strong></p></div> |
||
472 | <?php } ?> |
||
473 | <?php } ?> |
||
474 | <table class="form-table wpfas-table-settings <?php echo esc_attr( $table_class ); ?>"> |
||
475 | <tr valign="top"> |
||
476 | <th scope="row"><label for="wpfas-type"><?php _e( 'Type', 'ayecode-connect' ); ?></label></th> |
||
477 | <td> |
||
478 | <select name="wp-font-awesome-settings[type]" id="wpfas-type" onchange="if(this.value=='KIT'){jQuery('.wpfas-table-settings').addClass('wpfas-kit-set');}else{jQuery('.wpfas-table-settings').removeClass('wpfas-kit-set');}"> |
||
479 | <option value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e( 'CSS (default)', 'ayecode-connect' ); ?></option> |
||
480 | <option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option> |
||
481 | <option value="KIT" <?php selected( $this->settings['type'], 'KIT' ); ?>><?php _e( 'Kits (settings managed on fontawesome.com)', 'ayecode-connect' ); ?></option> |
||
482 | </select> |
||
483 | </td> |
||
484 | </tr> |
||
485 | |||
486 | <tr valign="top" class="wpfas-kit-show"> |
||
487 | <th scope="row"><label for="wpfas-kit-url"><?php _e( 'Kit URL', 'ayecode-connect' ); ?></label></th> |
||
488 | <td> |
||
489 | <input class="regular-text" id="wpfas-kit-url" type="url" name="wp-font-awesome-settings[kit-url]" value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
||
490 | <span><?php |
||
491 | echo wp_sprintf( |
||
492 | __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'ayecode-connect' ), |
||
493 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i> ', |
||
494 | '</a>' |
||
495 | ); |
||
496 | ?></span> |
||
497 | </td> |
||
498 | </tr> |
||
499 | <tr valign="top" class="wpfas-kit-hide"> |
||
500 | <th scope="row"><label for="wpfas-version"><?php _e( 'Version', 'ayecode-connect' ); ?></label></th> |
||
501 | <td> |
||
502 | <select name="wp-font-awesome-settings[version]" id="wpfas-version"> |
||
503 | <?php /* @todo Remove after FA7 compatibility */ ?> |
||
504 | <option value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo wp_sprintf( __( '%s (default)', 'ayecode-connect' ), '6.7.2' ); ?></option> |
||
505 | <?php $latest_version = $this->get_latest_version( false, true ); if ( $latest_version && version_compare( $latest_version, '7.0.0', '>' ) ) { ?> |
||
506 | <option value="<?php echo esc_attr( $latest_version ); ?>" <?php selected( $this->settings['version'], $latest_version ); ?>><?php echo esc_html( $latest_version ); ?></option> |
||
507 | <?php } ?> |
||
508 | <?php /* @todo Remove after after FA7 compatibility */ ?> |
||
509 | |||
510 | <?php /* @todo Un-comment after FA7 compatibility */ ?> |
||
511 | <?php /* ?><option value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo wp_sprintf( __( 'Latest - %s (default)', 'ayecode-connect' ), $this->get_latest_version() ); ?></option><?php */ ?> |
||
512 | <option value="7.0.0" <?php selected( $this->settings['version'], '7.0.0' ); ?>>7.0.0</option> |
||
513 | <option value="6.4.2" <?php selected( $this->settings['version'], '6.4.2' ); ?>>6.4.2</option> |
||
514 | <option value="6.1.0" <?php selected( $this->settings['version'], '6.1.0' ); ?>>6.1.0</option> |
||
515 | <option value="6.0.0" <?php selected( $this->settings['version'], '6.0.0' ); ?>>6.0.0</option> |
||
516 | <option value="5.15.4" <?php selected( $this->settings['version'], '5.15.4' ); ?>>5.15.4</option> |
||
517 | <option value="5.6.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>>5.6.0</option> |
||
518 | <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>>5.5.0</option> |
||
519 | <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>>5.4.0</option> |
||
520 | <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>>5.3.0</option> |
||
521 | <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>>5.2.0</option> |
||
522 | <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>>5.1.0</option> |
||
523 | <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>>4.7.1 (CSS only)</option> |
||
524 | </select> |
||
525 | </td> |
||
526 | </tr> |
||
527 | |||
528 | <tr valign="top"> |
||
529 | <th scope="row"><label for="wpfas-enqueue"><?php _e( 'Enqueue', 'ayecode-connect' ); ?></label></th> |
||
530 | <td> |
||
531 | <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue"> |
||
532 | <option value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)', 'ayecode-connect' ); ?></option> |
||
533 | <option value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend', 'ayecode-connect' ); ?></option> |
||
534 | <option value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend', 'ayecode-connect' ); ?></option> |
||
535 | </select> |
||
536 | </td> |
||
537 | </tr> |
||
538 | |||
539 | <tr valign="top" class="wpfas-kit-hide"> |
||
540 | <th scope="row"><label |
||
541 | for="wpfas-pro"><?php _e( 'Enable pro', 'ayecode-connect' ); ?></label></th> |
||
542 | <td> |
||
543 | <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/> |
||
544 | <input type="checkbox" name="wp-font-awesome-settings[pro]" value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro" onchange="if(jQuery(this).is(':checked')){jQuery('.wpfas-table-settings').addClass('wpfas-has-pro')}else{jQuery('.wpfas-table-settings').removeClass('wpfas-has-pro')}"/> |
||
545 | <span><?php |
||
546 | echo wp_sprintf( |
||
547 | __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'ayecode-connect' ), |
||
548 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
||
549 | ' <i class="fas fa-external-link-alt"></i></a>', |
||
550 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
||
551 | ' <i class="fas fa-external-link-alt"></i></a>' |
||
552 | ); |
||
553 | ?></span> |
||
554 | </td> |
||
555 | </tr> |
||
556 | |||
557 | <tr valign="top" class="wpfas-kit-hide wpfas-hide-pro"> |
||
558 | <th scope="row"><label for="wpfas-local"><?php _e( 'Load Fonts Locally', 'ayecode-connect' ); ?></label></th> |
||
559 | <td> |
||
560 | <input type="hidden" name="wp-font-awesome-settings[local]" value="0"/> |
||
561 | <input type="hidden" name="wp-font-awesome-settings[local_version]" value="<?php echo esc_attr( $this->settings['local_version'] ); ?>"/> |
||
562 | <input type="checkbox" name="wp-font-awesome-settings[local]" value="1" <?php checked( $this->settings['local'], '1' ); ?> id="wpfas-local"/> |
||
563 | <span><?php _e( '(For free version only) Load FontAwesome fonts from locally. This downloads FontAwesome fonts from fontawesome.com & stores at the local site.', 'ayecode-connect' ); ?></span> |
||
564 | </td> |
||
565 | </tr> |
||
566 | |||
567 | <tr valign="top" class="wpfas-kit-hide"> |
||
568 | <th scope="row"><label |
||
569 | for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility', 'ayecode-connect' ); ?></label> |
||
570 | </th> |
||
571 | <td> |
||
572 | <input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/> |
||
573 | <input type="checkbox" name="wp-font-awesome-settings[shims]" |
||
574 | value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims"/> |
||
575 | <span><?php _e( 'This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'ayecode-connect' ); ?></span> |
||
576 | </td> |
||
577 | </tr> |
||
578 | |||
579 | <tr valign="top" class="wpfas-kit-hide"> |
||
580 | <th scope="row"><label |
||
581 | for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)', 'ayecode-connect' ); ?></label> |
||
582 | </th> |
||
583 | <td> |
||
584 | <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/> |
||
585 | <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]" |
||
586 | value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?> |
||
587 | id="wpfas-js-pseudo"/> |
||
588 | <span><?php _e( 'Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'ayecode-connect' ); ?></span> |
||
589 | </td> |
||
590 | </tr> |
||
591 | |||
592 | <tr valign="top"> |
||
593 | <th scope="row"><label |
||
594 | for="wpfas-dequeue"><?php _e( 'Dequeue', 'ayecode-connect' ); ?></label></th> |
||
595 | <td> |
||
596 | <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/> |
||
597 | <input type="checkbox" name="wp-font-awesome-settings[dequeue]" |
||
598 | value="1" <?php checked( $this->settings['dequeue'], '1' ); ?> |
||
599 | id="wpfas-dequeue"/> |
||
600 | <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.', 'ayecode-connect' ); ?></span> |
||
601 | </td> |
||
602 | </tr> |
||
603 | |||
604 | </table> |
||
605 | <div class="fas-buttons"> |
||
606 | <?php |
||
607 | submit_button(); |
||
608 | ?> |
||
609 | <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 24,000+ more icons with Font Awesome Pro','ayecode-connect'); ?> <i class="fas fa-external-link-alt"></i></a></p> |
||
610 | |||
611 | </div> |
||
612 | </form> |
||
613 | |||
614 | <div id="wpfas-version"><?php echo wp_sprintf(__( 'Version: %s (affiliate links provided)', 'ayecode-connect' ), $this->version ); ?></div> |
||
615 | </div> |
||
616 | <?php |
||
617 | } |
||
618 | } |
||
619 | |||
620 | /** |
||
621 | * Check a version number is valid and if so return it or else return an empty string. |
||
622 | * |
||
623 | * @param $version string The version number to check. |
||
624 | * |
||
625 | * @since 1.0.6 |
||
626 | * |
||
627 | * @return string Either a valid version number or an empty string. |
||
628 | */ |
||
629 | public function validate_version_number( $version ) { |
||
630 | |||
631 | if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
||
632 | // valid |
||
633 | } else { |
||
634 | $version = '';// not validated |
||
635 | } |
||
636 | |||
637 | return $version; |
||
638 | } |
||
639 | |||
640 | |||
641 | /** |
||
642 | * Get the latest version of Font Awesome. |
||
643 | * |
||
644 | * 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. |
||
645 | * |
||
646 | * @since 1.0.7 |
||
647 | * @return mixed|string The latest version number found. |
||
648 | */ |
||
649 | public function get_latest_version( $force_api = false, $force_latest = false ) { |
||
650 | $latest_version = $this->latest; |
||
651 | |||
652 | $cache = get_transient( 'wp-font-awesome-settings-version' ); |
||
653 | |||
654 | if ( $cache === false || $force_api ) { // its not set |
||
655 | $api_ver = $this->get_latest_version_from_api(); |
||
656 | if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
||
657 | $latest_version = $api_ver; |
||
658 | set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
||
659 | } |
||
660 | } elseif ( $this->validate_version_number( $cache ) ) { |
||
661 | if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
||
662 | $latest_version = $cache; |
||
663 | } |
||
664 | } |
||
665 | |||
666 | // @todo remove after FA7 compatibility |
||
667 | if ( ! $force_latest && version_compare( $cache, '7.0.0', '>=' ) >= 0 ) { |
||
668 | $latest_version = '6.7.2'; |
||
669 | } |
||
670 | |||
671 | // Check and auto download fonts locally. |
||
672 | if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) { |
||
673 | if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) { |
||
674 | $this->download_package( $latest_version ); |
||
675 | } |
||
676 | } |
||
677 | |||
678 | return $latest_version; |
||
679 | } |
||
680 | |||
681 | /** |
||
682 | * Get the latest Font Awesome version from the github API. |
||
683 | * |
||
684 | * @since 1.0.7 |
||
685 | * @return string The latest version number or `0` on API fail. |
||
686 | */ |
||
687 | public function get_latest_version_from_api() { |
||
688 | $version = "0"; |
||
689 | $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
||
690 | if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
||
691 | $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
||
692 | if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
||
693 | $version = $api_response['tag_name']; |
||
694 | } |
||
695 | } |
||
696 | |||
697 | return $version; |
||
698 | } |
||
699 | |||
700 | /** |
||
701 | * Inline CSS for RTL language support. |
||
702 | * |
||
703 | * @since 1.0.13 |
||
704 | * @return string Inline CSS. |
||
705 | */ |
||
706 | public function rtl_inline_css() { |
||
707 | $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}'; |
||
708 | |||
709 | return $inline_css; |
||
710 | } |
||
711 | |||
712 | /** |
||
713 | * Show any warnings as an admin notice. |
||
714 | * |
||
715 | * @return void |
||
716 | */ |
||
717 | public function admin_notices() { |
||
718 | $settings = $this->settings; |
||
719 | |||
720 | if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
||
721 | if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
||
722 | ?> |
||
723 | <div class="notice notice-error is-dismissible"> |
||
724 | <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'ayecode-connect' ); ?></p> |
||
725 | </div> |
||
726 | <?php |
||
727 | } |
||
728 | } else { |
||
729 | if ( ! empty( $settings ) ) { |
||
730 | if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
||
731 | $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
||
732 | ?> |
||
733 | <div class="notice notice-error is-dismissible"> |
||
734 | <p><?php echo wp_sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'ayecode-connect' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p> |
||
735 | </div> |
||
736 | <?php |
||
737 | } |
||
738 | } |
||
739 | } |
||
740 | } |
||
741 | |||
742 | /** |
||
743 | * Handle fontawesome add settings to download fontawesome to store locally. |
||
744 | * |
||
745 | * @since 1.1.1 |
||
746 | * |
||
747 | * @param string $option The option name. |
||
748 | * @param mixed $value The option value. |
||
749 | */ |
||
750 | public function add_option_wp_font_awesome_settings( $option, $value ) { |
||
751 | // Do nothing if WordPress is being installed. |
||
752 | if ( wp_installing() ) { |
||
753 | return; |
||
754 | } |
||
755 | |||
756 | if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) { |
||
757 | $version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version(); |
||
758 | |||
759 | if ( ! empty( $version ) ) { |
||
760 | $response = $this->download_package( $version, $value ); |
||
761 | |||
762 | if ( is_wp_error( $response ) ) { |
||
763 | add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' ); |
||
764 | } |
||
765 | } |
||
766 | } |
||
767 | } |
||
768 | |||
769 | /** |
||
770 | * Handle fontawesome update settings to download fontawesome to store locally. |
||
771 | * |
||
772 | * @since 1.1.0 |
||
773 | * |
||
774 | * @param mixed $old_value The old option value. |
||
775 | * @param mixed $value The new option value. |
||
776 | */ |
||
777 | public function update_option_wp_font_awesome_settings( $old_value, $new_value ) { |
||
778 | // Do nothing if WordPress is being installed. |
||
779 | if ( wp_installing() ) { |
||
780 | return; |
||
781 | } |
||
782 | |||
783 | if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) { |
||
784 | // Old values |
||
785 | $old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' ); |
||
786 | $old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0; |
||
787 | |||
788 | // New values |
||
789 | $new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version(); |
||
790 | |||
791 | if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
||
792 | $response = $this->download_package( $new_version, $new_value ); |
||
793 | |||
794 | if ( is_wp_error( $response ) ) { |
||
795 | add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' ); |
||
796 | } |
||
797 | } |
||
798 | } |
||
799 | } |
||
800 | |||
801 | /** |
||
802 | * Get the fonts directory local path. |
||
803 | * |
||
804 | * @since 1.1.0 |
||
805 | * |
||
806 | * @param string Fonts directory local path. |
||
807 | */ |
||
808 | public function get_fonts_dir() { |
||
812 | } |
||
813 | |||
814 | /** |
||
815 | * Get the fonts directory local url. |
||
816 | * |
||
817 | * @since 1.1.0 |
||
818 | * |
||
819 | * @param string Fonts directory local url. |
||
820 | */ |
||
821 | public function get_fonts_url() { |
||
825 | } |
||
826 | |||
827 | /** |
||
828 | * Check whether load locally active. |
||
829 | * |
||
830 | * @since 1.1.0 |
||
831 | * |
||
832 | * @return bool True if active else false. |
||
833 | */ |
||
834 | public function has_local() { |
||
835 | if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
||
836 | return true; |
||
837 | } |
||
838 | |||
839 | return false; |
||
840 | } |
||
841 | |||
842 | /** |
||
843 | * Get the WP Filesystem access. |
||
844 | * |
||
845 | * @since 1.1.0 |
||
846 | * |
||
847 | * @return object The WP Filesystem. |
||
848 | */ |
||
849 | public function get_wp_filesystem() { |
||
850 | if ( ! function_exists( 'get_filesystem_method' ) ) { |
||
851 | require_once( ABSPATH . "/wp-admin/includes/file.php" ); |
||
852 | } |
||
853 | |||
854 | $access_type = get_filesystem_method(); |
||
855 | |||
856 | if ( $access_type === 'direct' ) { |
||
857 | /* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */ |
||
858 | $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
||
859 | |||
860 | /* Initialize the API */ |
||
861 | if ( ! WP_Filesystem( $creds ) ) { |
||
862 | /* Any problems and we exit */ |
||
863 | return false; |
||
864 | } |
||
865 | |||
866 | global $wp_filesystem; |
||
867 | |||
868 | return $wp_filesystem; |
||
869 | /* Do our file manipulations below */ |
||
870 | } else if ( defined( 'FTP_USER' ) ) { |
||
871 | $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
||
872 | |||
873 | /* Initialize the API */ |
||
874 | if ( ! WP_Filesystem( $creds ) ) { |
||
875 | /* Any problems and we exit */ |
||
876 | return false; |
||
877 | } |
||
878 | |||
879 | global $wp_filesystem; |
||
880 | |||
881 | return $wp_filesystem; |
||
882 | } else { |
||
883 | /* Don't have direct write access. Prompt user with our notice */ |
||
884 | return false; |
||
885 | } |
||
886 | } |
||
887 | |||
888 | /** |
||
889 | * Download the fontawesome package file. |
||
890 | * |
||
891 | * @since 1.1.0 |
||
892 | * |
||
893 | * @param mixed $version The font awesome. |
||
894 | * @param array $option Fontawesome settings. |
||
895 | * @return WP_ERROR|bool Error on fail and true on success. |
||
896 | */ |
||
897 | public function download_package( $version, $option = array() ) { |
||
898 | $filename = 'fontawesome-free-' . $version . '-web'; |
||
899 | $url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip'; |
||
900 | |||
901 | if ( ! function_exists( 'wp_handle_upload' ) ) { |
||
902 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
||
903 | } |
||
904 | |||
905 | $download_file = download_url( esc_url_raw( $url ) ); |
||
906 | |||
907 | if ( is_wp_error( $download_file ) ) { |
||
908 | return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'ayecode-connect' ) ); |
||
909 | } else if ( empty( $download_file ) ) { |
||
910 | return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'ayecode-connect' ) ); |
||
911 | } |
||
912 | |||
913 | $response = $this->extract_package( $download_file, $filename, true ); |
||
914 | |||
915 | // Update local version. |
||
916 | if ( is_wp_error( $response ) ) { |
||
917 | return $response; |
||
918 | } else if ( $response ) { |
||
919 | if ( empty( $option ) ) { |
||
920 | $option = get_option( 'wp-font-awesome-settings' ); |
||
921 | } |
||
922 | |||
923 | $option['local_version'] = $version; |
||
924 | |||
925 | // Remove action to prevent looping. |
||
926 | remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
||
927 | |||
928 | update_option( 'wp-font-awesome-settings', $option ); |
||
929 | |||
930 | return true; |
||
931 | } |
||
932 | |||
933 | return false; |
||
934 | } |
||
935 | |||
936 | /** |
||
937 | * Extract the fontawesome package file. |
||
938 | * |
||
939 | * @since 1.1.0 |
||
940 | * |
||
941 | * @param string $package The package file path. |
||
942 | * @param string $dirname Package file name. |
||
943 | * @param bool $delete_package Delete temp file or not. |
||
944 | * @return WP_Error|bool True on success WP_Error on fail. |
||
945 | */ |
||
946 | public function extract_package( $package, $dirname = '', $delete_package = false ) { |
||
947 | global $wp_filesystem; |
||
948 | |||
949 | $wp_filesystem = $this->get_wp_filesystem(); |
||
950 | |||
951 | if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { |
||
952 | return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'ayecode-connect' ) ); |
||
953 | } else if ( empty( $wp_filesystem ) ) { |
||
954 | return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'ayecode-connect' ) ); |
||
955 | } |
||
956 | |||
957 | $fonts_dir = $this->get_fonts_dir(); |
||
958 | $fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR; |
||
959 | |||
960 | if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
||
961 | $wp_filesystem->delete( $fonts_tmp_dir, true ); |
||
962 | } |
||
963 | |||
964 | // Unzip package to working directory. |
||
965 | $result = unzip_file( $package, $fonts_tmp_dir ); |
||
966 | |||
967 | if ( is_wp_error( $result ) ) { |
||
968 | $wp_filesystem->delete( $fonts_tmp_dir, true ); |
||
969 | |||
970 | if ( 'incompatible_archive' === $result->get_error_code() ) { |
||
971 | return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'ayecode-connect' ) ); |
||
972 | } |
||
973 | |||
974 | return $result; |
||
975 | } |
||
976 | |||
977 | if ( $wp_filesystem->is_dir( $fonts_dir ) ) { |
||
978 | $wp_filesystem->delete( $fonts_dir, true ); |
||
979 | } |
||
980 | |||
981 | $extract_dir = $fonts_tmp_dir; |
||
982 | |||
983 | if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) { |
||
984 | $extract_dir .= $dirname . DIRECTORY_SEPARATOR; |
||
985 | } |
||
986 | |||
987 | try { |
||
988 | $return = $wp_filesystem->move( $extract_dir, $fonts_dir, true ); |
||
989 | } catch ( Exception $e ) { |
||
990 | $return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'ayecode-connect' ) ); |
||
991 | } |
||
992 | |||
993 | if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
||
994 | $wp_filesystem->delete( $fonts_tmp_dir, true ); |
||
995 | } |
||
996 | |||
997 | // Once extracted, delete the package if required. |
||
998 | if ( $delete_package ) { |
||
999 | unlink( $package ); |
||
1000 | } |
||
1001 | |||
1002 | return $return; |
||
1003 | } |
||
1004 | |||
1005 | /** |
||
1006 | * Output the version in the header. |
||
1007 | */ |
||
1008 | public function add_generator() { |
||
1009 | $file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) ); |
||
1010 | $plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) ); |
||
1011 | |||
1012 | // Find source plugin/theme. |
||
1013 | $source = array(); |
||
1014 | if ( strpos( $file, $plugins_dir ) !== false ) { |
||
1015 | $source = explode( "/", plugin_basename( $file ) ); |
||
1016 | } else if ( function_exists( 'get_theme_root' ) ) { |
||
1017 | $themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) ); |
||
1018 | |||
1019 | if ( strpos( $file, $themes_dir ) !== false ) { |
||
1020 | $source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) ); |
||
1021 | } |
||
1022 | } |
||
1023 | |||
1024 | echo '<meta name="generator" content="WP Font Awesome Settings v' . esc_attr( $this->version ) . '"' . ( ! empty( $source[0] ) ? ' data-ac-source="' . esc_attr( $source[0] ) . '"' : '' ) . ' />'; |
||
1025 | } |
||
1026 | |||
1027 | /** |
||
1028 | * Add extra parameters to the script tag. |
||
1029 | * |
||
1030 | * Add crossorigin="anonymous" to prevent OpaqueResponseBlocking |
||
1031 | * (NS_BINDING_ABORTED) http error. |
||
1032 | * |
||
1033 | * @since 1.1.8 |
||
1034 | * |
||
1035 | * @param string $tag The script tag. |
||
1036 | * @param string $handle The script handle. |
||
1037 | * @param string $src The script url. |
||
1038 | * @return string The script tag. |
||
1039 | */ |
||
1040 | public function script_loader_tag( $tag, $handle, $src ) { |
||
1050 | } |
||
1051 | } |
||
1052 | |||
1053 | /** |
||
1054 | * Run the class if found. |
||
1055 | */ |
||
1056 | WP_Font_Awesome_Settings::instance(); |
||
1057 | } |
||
1058 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.