@@ -33,7 +33,7 @@ class WP_Font_Awesome_Settings {
3333 *
3434 * @var string
3535 */
36- public $ version = '1.1.7 ' ;
36+ public $ version = '1.1.8 ' ;
3737
3838 /**
3939 * Class textdomain.
@@ -122,7 +122,7 @@ public function constants(){
122122
123123 }
124124
125- // Set a constant if pro enbaled
125+ // Set a constant if pro enabled
126126 if ( ! defined ( 'FAS_PRO ' ) && $ this ->settings ['pro ' ] ) {
127127 define ( 'FAS_PRO ' , true );
128128 }
@@ -182,14 +182,22 @@ public function init() {
182182 add_filter ( 'block_editor_settings_all ' , array ( $ this , 'enqueue_editor_styles ' ), 10 , 2 );
183183 }
184184 } else {
185+ $ enqueue = false ;
186+
185187 if ( $ this ->settings ['enqueue ' ] == '' || $ this ->settings ['enqueue ' ] == 'frontend ' ) {
188+ $ enqueue = true ;
186189 add_action ( 'wp_enqueue_scripts ' , array ( $ this , 'enqueue_scripts ' ), 5000 );
187190 }
188191
189192 if ( $ this ->settings ['enqueue ' ] == '' || $ this ->settings ['enqueue ' ] == 'backend ' ) {
193+ $ enqueue = true ;
190194 add_action ( 'admin_enqueue_scripts ' , array ( $ this , 'enqueue_scripts ' ), 5000 );
191195 add_filter ( 'block_editor_settings_all ' , array ( $ this , 'enqueue_editor_scripts ' ), 10 , 2 );
192196 }
197+
198+ if ( $ enqueue ) {
199+ add_filter ( 'script_loader_tag ' , array ( $ this , 'script_loader_tag ' ), 20 , 3 );
200+ }
193201 }
194202
195203 // remove font awesome if set to do so
@@ -226,10 +234,10 @@ public function enqueue_editor_styles( $editor_settings, $block_editor_context )
226234 *
227235 * @return array
228236 */
229- public function enqueue_editor_scripts ( $ editor_settings , $ block_editor_context ){
230-
237+ public function enqueue_editor_scripts ( $ editor_settings , $ block_editor_context ) {
231238 $ url = $ this ->get_url ();
232- $ editor_settings ['__unstableResolvedAssets ' ]['scripts ' ] .= "<script src=' $ url' id='font-awesome-js'></script> " ;
239+
240+ $ editor_settings ['__unstableResolvedAssets ' ]['scripts ' ] .= "<script src=' $ url' id='font-awesome-js' defer crossorigin='anonymous'></script> " ;
233241
234242 return $ editor_settings ;
235243 }
@@ -292,7 +300,7 @@ public function get_url( $shims = false, $local = true ) {
292300 $ sub = $ this ->settings ['pro ' ] ? 'pro ' : 'use ' ;
293301 $ type = $ this ->settings ['type ' ];
294302 $ version = $ this ->settings ['version ' ];
295- $ kit_url = $ this ->settings ['kit-url ' ] ? esc_url ( $ this ->settings ['kit-url ' ] ) : '' ;
303+ $ kit_url = $ this ->settings ['kit-url ' ] ? sanitize_text_field ( $ this ->settings ['kit-url ' ] ) : '' ;
296304 $ url = '' ;
297305
298306 if ( $ type == 'KIT ' && $ kit_url ) {
@@ -482,7 +490,7 @@ public function settings_page() {
482490 <span><?php
483491 echo wp_sprintf (
484492 __ ( 'Requires a free account with Font Awesome. %sGet kit url%s ' , 'ayecode-connect ' ),
485- '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i> ' ,
493+ '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i> ' ,
486494 '</a> '
487495 );
488496 ?> </span>
@@ -1001,6 +1009,31 @@ public function add_generator() {
10011009
10021010 echo '<meta name="generator" content="WP Font Awesome Settings v ' . esc_attr ( $ this ->version ) . '" ' . ( ! empty ( $ source [0 ] ) ? ' data-ac-source=" ' . esc_attr ( $ source [0 ] ) . '" ' : '' ) . ' /> ' ;
10031011 }
1012+
1013+ /**
1014+ * Add extra parameters to the script tag.
1015+ *
1016+ * Add crossorigin="anonymous" to prevent OpaqueResponseBlocking
1017+ * (NS_BINDING_ABORTED) http error.
1018+ *
1019+ * @since 1.1.8
1020+ *
1021+ * @param string $tag The script tag.
1022+ * @param string $handle The script handle.
1023+ * @param string $src The script url.
1024+ * @return string The script tag.
1025+ */
1026+ public function script_loader_tag ( $ tag , $ handle , $ src ) {
1027+ if ( ( $ handle == 'font-awesome ' || $ handle == 'font-awesome-shims ' ) && ( strpos ( $ src , "kit.fontawesome.com " ) !== false || strpos ( $ src , ".fontawesome.com/releases/ " ) !== false ) ) {
1028+ $ tag = preg_replace (
1029+ '/<script[\s]+(.*?)>/ ' ,
1030+ '<script defer crossorigin="anonymous" \1> ' ,
1031+ $ tag
1032+ );
1033+ }
1034+
1035+ return $ tag ;
1036+ }
10041037 }
10051038
10061039 /**
0 commit comments