@@ -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 | } |
@@ -12,14 +12,14 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if (!defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Only add if the class does not already exist. |
21 | 21 | */ |
22 | -if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
|
22 | +if (!class_exists('WP_Font_Awesome_Settings')) { |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * A Class to be able to change settings for Font Awesome. |
@@ -90,18 +90,18 @@ discard block |
||
90 | 90 | * @return WP_Font_Awesome_Settings - Main instance. |
91 | 91 | */ |
92 | 92 | public static function instance() { |
93 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
93 | + if (!isset(self::$instance) && !(self::$instance instanceof WP_Font_Awesome_Settings)) { |
|
94 | 94 | self::$instance = new WP_Font_Awesome_Settings; |
95 | 95 | |
96 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
96 | + add_action('init', array(self::$instance, 'init')); // set settings |
|
97 | 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' ) ); |
|
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 | 102 | } |
103 | 103 | |
104 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
104 | + do_action('wp_font_awesome_settings_loaded'); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | return self::$instance; |
@@ -116,34 +116,34 @@ discard block |
||
116 | 116 | $this->settings = $this->get_settings(); |
117 | 117 | |
118 | 118 | // check if the official plugin is active and use that instead if so. |
119 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
119 | + if (!defined('FONTAWESOME_PLUGIN_FILE')) { |
|
120 | 120 | |
121 | - if ( $this->settings['type'] == 'CSS' ) { |
|
121 | + if ($this->settings['type'] == 'CSS') { |
|
122 | 122 | |
123 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
124 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
123 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
124 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
125 | 125 | } |
126 | 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 ); |
|
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 | 130 | } |
131 | 131 | |
132 | 132 | } else { |
133 | 133 | |
134 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
135 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
134 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
135 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
136 | 136 | } |
137 | 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 ); |
|
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 | 141 | } |
142 | 142 | } |
143 | 143 | |
144 | 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 ); |
|
145 | + if ($this->settings['dequeue'] == '1') { |
|
146 | + add_action('clean_url', array($this, 'remove_font_awesome'), 5000, 3); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @return array |
159 | 159 | */ |
160 | - public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
|
160 | + public function enqueue_editor_styles($editor_settings, $block_editor_context) { |
|
161 | 161 | |
162 | - if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
|
162 | + if (!empty($editor_settings['__unstableResolvedAssets']['styles'])) { |
|
163 | 163 | $url = $this->get_url(); |
164 | 164 | $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
165 | 165 | } |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @return array |
177 | 177 | */ |
178 | - public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){ |
|
178 | + public function enqueue_editor_scripts($editor_settings, $block_editor_context) { |
|
179 | 179 | |
180 | 180 | $url = $this->get_url(); |
181 | 181 | $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>"; |
@@ -190,20 +190,20 @@ discard block |
||
190 | 190 | // build url |
191 | 191 | $url = $this->get_url(); |
192 | 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' ); |
|
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 | 196 | |
197 | 197 | // RTL language support CSS. |
198 | - if ( is_rtl() ) { |
|
199 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
198 | + if (is_rtl()) { |
|
199 | + wp_add_inline_style('font-awesome', $this->rtl_inline_css()); |
|
200 | 200 | } |
201 | 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' ); |
|
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 | 207 | } |
208 | 208 | } |
209 | 209 | |
@@ -215,15 +215,15 @@ discard block |
||
215 | 215 | $url = $this->get_url(); |
216 | 216 | |
217 | 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' ); |
|
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 | 227 | } |
228 | 228 | } |
229 | 229 | |
@@ -234,16 +234,16 @@ discard block |
||
234 | 234 | * |
235 | 235 | * @return string The url to the file. |
236 | 236 | */ |
237 | - public function get_url( $shims = false ) { |
|
237 | + public function get_url($shims = false) { |
|
238 | 238 | $script = $shims ? 'v4-shims' : 'all'; |
239 | 239 | $sub = $this->settings['pro'] ? 'pro' : 'use'; |
240 | 240 | $type = $this->settings['type']; |
241 | 241 | $version = $this->settings['version']; |
242 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
242 | + $kit_url = $this->settings['kit-url'] ? esc_url($this->settings['kit-url']) : ''; |
|
243 | 243 | $url = ''; |
244 | 244 | |
245 | - if ( $type == 'KIT' && $kit_url ) { |
|
246 | - if ( $shims ) { |
|
245 | + if ($type == 'KIT' && $kit_url) { |
|
246 | + if ($shims) { |
|
247 | 247 | // if its a kit then we don't add shims here |
248 | 248 | return ''; |
249 | 249 | } |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | $url .= "?wpfas=true"; // set our var so our version is not removed |
252 | 252 | } else { |
253 | 253 | $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
254 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
254 | + $url .= !empty($version) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
255 | 255 | $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
256 | 256 | $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
257 | 257 | $url .= "?wpfas=true"; // set our var so our version is not removed |
@@ -271,16 +271,16 @@ discard block |
||
271 | 271 | * |
272 | 272 | * @return string The filtered url. |
273 | 273 | */ |
274 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
274 | + public function remove_font_awesome($url, $original_url, $_context) { |
|
275 | 275 | |
276 | - if ( $_context == 'display' |
|
277 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
278 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
276 | + if ($_context == 'display' |
|
277 | + && (strstr($url, "fontawesome") !== false || strstr($url, "font-awesome") !== false) |
|
278 | + && (strstr($url, ".js") !== false || strstr($url, ".css") !== false) |
|
279 | 279 | ) {// it's a font-awesome-url (probably) |
280 | 280 | |
281 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
282 | - if ( $this->settings['type'] == 'JS' ) { |
|
283 | - if ( $this->settings['js-pseudo'] ) { |
|
281 | + if (strstr($url, "wpfas=true") !== false) { |
|
282 | + if ($this->settings['type'] == 'JS') { |
|
283 | + if ($this->settings['js-pseudo']) { |
|
284 | 284 | $url .= "' data-search-pseudo-elements defer='defer"; |
285 | 285 | } else { |
286 | 286 | $url .= "' defer='defer"; |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * Register the database settings with WordPress. |
300 | 300 | */ |
301 | 301 | public function register_settings() { |
302 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
302 | + register_setting('wp-font-awesome-settings', 'wp-font-awesome-settings'); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -308,10 +308,10 @@ discard block |
||
308 | 308 | */ |
309 | 309 | public function menu_item() { |
310 | 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( |
|
311 | + call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
312 | 312 | $this, |
313 | 313 | 'settings_page' |
314 | - ) ); |
|
314 | + )); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | */ |
322 | 322 | public function get_settings() { |
323 | 323 | |
324 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
324 | + $db_settings = get_option('wp-font-awesome-settings'); |
|
325 | 325 | |
326 | 326 | $defaults = array( |
327 | 327 | 'type' => 'CSS', // type to use, CSS or JS or KIT |
@@ -334,14 +334,14 @@ discard block |
||
334 | 334 | 'kit-url' => '', // the kit url |
335 | 335 | ); |
336 | 336 | |
337 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
337 | + $settings = wp_parse_args($db_settings, $defaults); |
|
338 | 338 | |
339 | 339 | /** |
340 | 340 | * Filter the Font Awesome settings. |
341 | 341 | * |
342 | 342 | * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
343 | 343 | */ |
344 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
344 | + return $this->settings = apply_filters('wp-font-awesome-settings', $settings, $db_settings, $defaults); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | |
@@ -349,16 +349,16 @@ discard block |
||
349 | 349 | * The settings page html output. |
350 | 350 | */ |
351 | 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' ) ); |
|
352 | + if (!current_user_can('manage_options')) { |
|
353 | + wp_die(__('You do not have sufficient permissions to access this page.', 'font-awesome-settings')); |
|
354 | 354 | } |
355 | 355 | |
356 | 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 ); |
|
357 | + if (isset($_REQUEST['force-version-check'])) { |
|
358 | + $this->get_latest_version($force_api = true); |
|
359 | 359 | } |
360 | 360 | |
361 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
361 | + if (!defined('FONTAWESOME_PLUGIN_FILE')) { |
|
362 | 362 | ?> |
363 | 363 | <style> |
364 | 364 | .wpfas-kit-show { |
@@ -377,37 +377,37 @@ 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' ); |
|
380 | + settings_fields('wp-font-awesome-settings'); |
|
381 | + do_settings_sections('wp-font-awesome-settings'); |
|
382 | 382 | $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
383 | 383 | ?> |
384 | - <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
|
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 |
387 | - for="wpfas-type"><?php _e( 'Type', 'font-awesome-settings' ); ?></label></th> |
|
387 | + for="wpfas-type"><?php _e('Type', 'font-awesome-settings'); ?></label></th> |
|
388 | 388 | <td> |
389 | 389 | <select name="wp-font-awesome-settings[type]" id="wpfas-type" |
390 | 390 | onchange="if(this.value=='KIT'){jQuery('.wpfas-table-settings').addClass('wpfas-kit-set');}else{jQuery('.wpfas-table-settings').removeClass('wpfas-kit-set');}"> |
391 | 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> |
|
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 | 394 | <option |
395 | - value="KIT" <?php selected( $this->settings['type'], 'KIT' ); ?>><?php _e( 'Kits (settings managed on fontawesome.com)', 'font-awesome-settings' ); ?></option> |
|
395 | + value="KIT" <?php selected($this->settings['type'], 'KIT'); ?>><?php _e('Kits (settings managed on fontawesome.com)', 'font-awesome-settings'); ?></option> |
|
396 | 396 | </select> |
397 | 397 | </td> |
398 | 398 | </tr> |
399 | 399 | |
400 | 400 | <tr valign="top" class="wpfas-kit-show"> |
401 | 401 | <th scope="row"><label |
402 | - for="wpfas-kit-url"><?php _e( 'Kit URL', 'font-awesome-settings' ); ?></label></th> |
|
402 | + for="wpfas-kit-url"><?php _e('Kit URL', 'font-awesome-settings'); ?></label></th> |
|
403 | 403 | <td> |
404 | 404 | <input class="regular-text" id="wpfas-kit-url" type="url" |
405 | 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 :(?>"/> |
|
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 | 408 | <span><?php |
409 | 409 | echo sprintf( |
410 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
410 | + __('Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings'), |
|
411 | 411 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
412 | 412 | '</a>' |
413 | 413 | ); |
@@ -417,40 +417,40 @@ discard block |
||
417 | 417 | |
418 | 418 | <tr valign="top" class="wpfas-kit-hide"> |
419 | 419 | <th scope="row"><label |
420 | - for="wpfas-version"><?php _e( 'Version', 'font-awesome-settings' ); ?></label></th> |
|
420 | + for="wpfas-version"><?php _e('Version', 'font-awesome-settings'); ?></label></th> |
|
421 | 421 | <td> |
422 | 422 | <select name="wp-font-awesome-settings[version]" id="wpfas-version"> |
423 | 423 | <option |
424 | - value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo sprintf( __( 'Latest - %s (default)', 'font-awesome-settings' ), $this->get_latest_version() ); ?> |
|
424 | + value="" <?php selected($this->settings['version'], ''); ?>><?php echo sprintf(__('Latest - %s (default)', 'font-awesome-settings'), $this->get_latest_version()); ?> |
|
425 | 425 | </option> |
426 | - <option value="6.1.0" <?php selected( $this->settings['version'], '6.1.0' ); ?>> |
|
426 | + <option value="6.1.0" <?php selected($this->settings['version'], '6.1.0'); ?>> |
|
427 | 427 | 6.1.0 |
428 | 428 | </option> |
429 | - <option value="6.0.0" <?php selected( $this->settings['version'], '6.0.0' ); ?>> |
|
429 | + <option value="6.0.0" <?php selected($this->settings['version'], '6.0.0'); ?>> |
|
430 | 430 | 6.0.0 |
431 | 431 | </option> |
432 | - <option value="5.15.4" <?php selected( $this->settings['version'], '5.15.4' ); ?>> |
|
432 | + <option value="5.15.4" <?php selected($this->settings['version'], '5.15.4'); ?>> |
|
433 | 433 | 5.15.4 |
434 | 434 | </option> |
435 | - <option value="5.6.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>> |
|
435 | + <option value="5.6.0" <?php selected($this->settings['version'], '5.6.0'); ?>> |
|
436 | 436 | 5.6.0 |
437 | 437 | </option> |
438 | - <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>> |
|
438 | + <option value="5.5.0" <?php selected($this->settings['version'], '5.5.0'); ?>> |
|
439 | 439 | 5.5.0 |
440 | 440 | </option> |
441 | - <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>> |
|
441 | + <option value="5.4.0" <?php selected($this->settings['version'], '5.4.0'); ?>> |
|
442 | 442 | 5.4.0 |
443 | 443 | </option> |
444 | - <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>> |
|
444 | + <option value="5.3.0" <?php selected($this->settings['version'], '5.3.0'); ?>> |
|
445 | 445 | 5.3.0 |
446 | 446 | </option> |
447 | - <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>> |
|
447 | + <option value="5.2.0" <?php selected($this->settings['version'], '5.2.0'); ?>> |
|
448 | 448 | 5.2.0 |
449 | 449 | </option> |
450 | - <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>> |
|
450 | + <option value="5.1.0" <?php selected($this->settings['version'], '5.1.0'); ?>> |
|
451 | 451 | 5.1.0 |
452 | 452 | </option> |
453 | - <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>> |
|
453 | + <option value="4.7.0" <?php selected($this->settings['version'], '4.7.0'); ?>> |
|
454 | 454 | 4.7.1 (CSS only) |
455 | 455 | </option> |
456 | 456 | </select> |
@@ -459,29 +459,29 @@ discard block |
||
459 | 459 | |
460 | 460 | <tr valign="top"> |
461 | 461 | <th scope="row"><label |
462 | - for="wpfas-enqueue"><?php _e( 'Enqueue', 'font-awesome-settings' ); ?></label></th> |
|
462 | + for="wpfas-enqueue"><?php _e('Enqueue', 'font-awesome-settings'); ?></label></th> |
|
463 | 463 | <td> |
464 | 464 | <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue"> |
465 | 465 | <option |
466 | - value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)', 'font-awesome-settings' ); ?></option> |
|
466 | + value="" <?php selected($this->settings['enqueue'], ''); ?>><?php _e('Frontend + Backend (default)', 'font-awesome-settings'); ?></option> |
|
467 | 467 | <option |
468 | - value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend', 'font-awesome-settings' ); ?></option> |
|
468 | + value="frontend" <?php selected($this->settings['enqueue'], 'frontend'); ?>><?php _e('Frontend', 'font-awesome-settings'); ?></option> |
|
469 | 469 | <option |
470 | - value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend', 'font-awesome-settings' ); ?></option> |
|
470 | + value="backend" <?php selected($this->settings['enqueue'], 'backend'); ?>><?php _e('Backend', 'font-awesome-settings'); ?></option> |
|
471 | 471 | </select> |
472 | 472 | </td> |
473 | 473 | </tr> |
474 | 474 | |
475 | 475 | <tr valign="top" class="wpfas-kit-hide"> |
476 | 476 | <th scope="row"><label |
477 | - for="wpfas-pro"><?php _e( 'Enable pro', 'font-awesome-settings' ); ?></label></th> |
|
477 | + for="wpfas-pro"><?php _e('Enable pro', 'font-awesome-settings'); ?></label></th> |
|
478 | 478 | <td> |
479 | 479 | <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/> |
480 | 480 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
481 | - value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
|
481 | + value="1" <?php checked($this->settings['pro'], '1'); ?> id="wpfas-pro"/> |
|
482 | 482 | <span><?php |
483 | 483 | echo sprintf( |
484 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
484 | + __('Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings'), |
|
485 | 485 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
486 | 486 | ' <i class="fas fa-external-link-alt"></i></a>', |
487 | 487 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
@@ -493,38 +493,38 @@ discard block |
||
493 | 493 | |
494 | 494 | <tr valign="top" class="wpfas-kit-hide"> |
495 | 495 | <th scope="row"><label |
496 | - for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility', 'font-awesome-settings' ); ?></label> |
|
496 | + for="wpfas-shims"><?php _e('Enable v4 shims compatibility', 'font-awesome-settings'); ?></label> |
|
497 | 497 | </th> |
498 | 498 | <td> |
499 | 499 | <input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/> |
500 | 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> |
|
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 | 503 | </td> |
504 | 504 | </tr> |
505 | 505 | |
506 | 506 | <tr valign="top" class="wpfas-kit-hide"> |
507 | 507 | <th scope="row"><label |
508 | - for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)', 'font-awesome-settings' ); ?></label> |
|
508 | + for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)', 'font-awesome-settings'); ?></label> |
|
509 | 509 | </th> |
510 | 510 | <td> |
511 | 511 | <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/> |
512 | 512 | <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]" |
513 | - value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?> |
|
513 | + value="1" <?php checked($this->settings['js-pseudo'], '1'); ?> |
|
514 | 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> |
|
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 | 516 | </td> |
517 | 517 | </tr> |
518 | 518 | |
519 | 519 | <tr valign="top"> |
520 | 520 | <th scope="row"><label |
521 | - for="wpfas-dequeue"><?php _e( 'Dequeue', 'font-awesome-settings' ); ?></label></th> |
|
521 | + for="wpfas-dequeue"><?php _e('Dequeue', 'font-awesome-settings'); ?></label></th> |
|
522 | 522 | <td> |
523 | 523 | <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/> |
524 | 524 | <input type="checkbox" name="wp-font-awesome-settings[dequeue]" |
525 | - value="1" <?php checked( $this->settings['dequeue'], '1' ); ?> |
|
525 | + value="1" <?php checked($this->settings['dequeue'], '1'); ?> |
|
526 | 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> |
|
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 | 528 | </td> |
529 | 529 | </tr> |
530 | 530 | |
@@ -533,12 +533,12 @@ discard block |
||
533 | 533 | <?php |
534 | 534 | submit_button(); |
535 | 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> |
|
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> |
539 | 539 | </form> |
540 | 540 | |
541 | - <div id="wpfas-version"><?php echo sprintf(__( 'Version: %s (affiliate links provided)', 'font-awesome-settings' ), $this->version ); ?></div> |
|
541 | + <div id="wpfas-version"><?php echo sprintf(__('Version: %s (affiliate links provided)', 'font-awesome-settings'), $this->version); ?></div> |
|
542 | 542 | </div> |
543 | 543 | |
544 | 544 | <style> |
@@ -568,12 +568,12 @@ discard block |
||
568 | 568 | * |
569 | 569 | * @return string Either a valid version number or an empty string. |
570 | 570 | */ |
571 | - public function validate_version_number( $version ) { |
|
571 | + public function validate_version_number($version) { |
|
572 | 572 | |
573 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
573 | + if (version_compare($version, '0.0.1', '>=') >= 0) { |
|
574 | 574 | // valid |
575 | 575 | } else { |
576 | - $version = '';// not validated |
|
576 | + $version = ''; // not validated |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | return $version; |
@@ -588,19 +588,19 @@ discard block |
||
588 | 588 | * @since 1.0.7 |
589 | 589 | * @return mixed|string The latest version number found. |
590 | 590 | */ |
591 | - public function get_latest_version( $force_api = false ) { |
|
591 | + public function get_latest_version($force_api = false) { |
|
592 | 592 | $latest_version = $this->latest; |
593 | 593 | |
594 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
594 | + $cache = get_transient('wp-font-awesome-settings-version'); |
|
595 | 595 | |
596 | - if ( $cache === false || $force_api ) { // its not set |
|
596 | + if ($cache === false || $force_api) { // its not set |
|
597 | 597 | $api_ver = $this->get_latest_version_from_api(); |
598 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
598 | + if (version_compare($api_ver, $this->latest, '>=') >= 0) { |
|
599 | 599 | $latest_version = $api_ver; |
600 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
600 | + set_transient('wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS); |
|
601 | 601 | } |
602 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
603 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
602 | + } elseif ($this->validate_version_number($cache)) { |
|
603 | + if (version_compare($cache, $this->latest, '>=') >= 0) { |
|
604 | 604 | $latest_version = $cache; |
605 | 605 | } |
606 | 606 | } |
@@ -616,10 +616,10 @@ discard block |
||
616 | 616 | */ |
617 | 617 | public function get_latest_version_from_api() { |
618 | 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'] ) ) { |
|
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 | 623 | $version = $api_response['tag_name']; |
624 | 624 | } |
625 | 625 | } |
@@ -644,26 +644,26 @@ discard block |
||
644 | 644 | * |
645 | 645 | * @return void |
646 | 646 | */ |
647 | - public function admin_notices(){ |
|
647 | + public function admin_notices() { |
|
648 | 648 | $settings = $this->settings; |
649 | 649 | |
650 | - if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
650 | + if (defined('FONTAWESOME_PLUGIN_FILE')) { |
|
651 | 651 | |
652 | - if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
652 | + if (!empty($_REQUEST['page']) && $_REQUEST['page'] == 'wp-font-awesome-settings') { |
|
653 | 653 | ?> |
654 | 654 | <div class="notice notice-error is-dismissible"> |
655 | - <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'font-awesome-settings' ); ?></p> |
|
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', '>=' ) ) ) { |
|
660 | + } else { |
|
661 | + if (!empty($settings)) { |
|
662 | + if ($settings['type'] != 'KIT' && $settings['pro'] && ($settings['version'] == '' || version_compare($settings['version'], '6', '>='))) { |
|
663 | 663 | $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
664 | 664 | ?> |
665 | 665 | <div class="notice notice-error is-dismissible"> |
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> |
|
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 | 669 | } |