AddToAny Share Buttons - Version 1.8.2

Version Description

  • Update AddToAny core script loading
  • Rename enqueued addtoany scripts to addtoany-core and addtoany-jquery
  • Load the local JS file asynchronously by default
Download this release

Release Info

Developer micropat
Plugin Icon 128x128 AddToAny Share Buttons
Version 1.8.2
Comparing to
See all releases

Code changes from version 1.8.1 to 1.8.2

Files changed (2) hide show
  1. README.txt +6 -1
  2. add-to-any.php +13 -18
README.txt CHANGED
@@ -4,7 +4,7 @@ Tags: buttons, share, icons, social media, share buttons, sharing, share button,
4
  Requires at least: 4.5
5
  Tested up to: 5.8
6
  Requires PHP: 5.6
7
- Stable tag: 1.8.1
8
 
9
  Share buttons for WordPress including the AddToAny sharing button, Facebook, Twitter, WhatsApp, Pinterest, Reddit, many more, and follow icons too.
10
 
@@ -346,6 +346,11 @@ Upload (or move) the `add-to-any` plugin directory into the `/wp-content/mu-plug
346
 
347
  == Changelog ==
348
 
 
 
 
 
 
349
  = 1.8.1 =
350
  * Add Discord follow button
351
  * Add Snapchat share button
4
  Requires at least: 4.5
5
  Tested up to: 5.8
6
  Requires PHP: 5.6
7
+ Stable tag: 1.8.2
8
 
9
  Share buttons for WordPress including the AddToAny sharing button, Facebook, Twitter, WhatsApp, Pinterest, Reddit, many more, and follow icons too.
10
 
346
 
347
  == Changelog ==
348
 
349
+ = 1.8.2 =
350
+ * Update AddToAny core script loading
351
+ * Rename enqueued `addtoany` scripts to `addtoany-core` and `addtoany-jquery`
352
+ * Load the local JS file asynchronously by default
353
+
354
  = 1.8.1 =
355
  * Add Discord follow button
356
  * Add Snapchat share button
add-to-any.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: AddToAny Share Buttons
4
  * Plugin URI: https://www.addtoany.com/
5
  * Description: Share buttons for your pages including AddToAny's universal sharing button, Facebook, Twitter, LinkedIn, Pinterest, WhatsApp and many more.
6
- * Version: 1.8.1
7
  * Author: AddToAny
8
  * Author URI: https://www.addtoany.com/
9
  * Text Domain: add-to-any
@@ -1090,22 +1090,18 @@ function A2A_SHARE_SAVE_enqueue_script() {
1090
  . addtoany_menu_locale_escaped()
1091
  . $floating_js_escaped
1092
  . $script_configs_escaped
1093
- . "\n"
1094
- . '(function(d,s,a,b){'
1095
- . 'a=d.createElement(s);'
1096
- . 'b=d.getElementsByTagName(s)[0];'
1097
- . 'a.async=1;'
1098
- . 'a.src=' . wp_json_encode( esc_url( $static_server . '/page.js' . $querystring ), JSON_UNESCAPED_SLASHES ) . ';'
1099
- . 'b.parentNode.insertBefore(a,b);'
1100
- . '})(document,"script");'
1101
  . "\n";
1102
 
1103
- // Require an empty `addtoany` script to be enqueued because wp_add_inline_script() below requires a queued script.
1104
- wp_register_script( 'addtoany', '' );
1105
- wp_enqueue_script( 'addtoany' );
1106
 
 
 
 
 
1107
  // Add inline JavaScript. Arbitrary JavaScript is expected from users with the `unfiltered_html` capability.
1108
- wp_add_inline_script( 'addtoany', $inline_javascript );
1109
 
1110
  // Load script that depends on jQuery only if jQuery is registered.
1111
  if ( wp_script_is( 'jquery', 'registered' ) ) {
@@ -1114,11 +1110,10 @@ function A2A_SHARE_SAVE_enqueue_script() {
1114
 
1115
  // Adjust script tag attributes.
1116
  add_filter( 'script_loader_tag', function ( $tag, $handle, $src ) {
1117
- if ( 'addtoany' === $handle ) {
1118
- // Add async attribute to the script tag with the src attribute.
1119
- $tag = preg_replace( '/<script src/', '<script async src', $tag, 1 );
1120
- // Add data-cfasync="false" attribute to the inline script tag.
1121
- $tag = preg_replace( '/<script id=\'addtoany-js-/', '<script data-cfasync="false" id=\'addtoany-js-', $tag, 1 );
1122
  }
1123
  return $tag;
1124
  }, 10, 3 );
3
  * Plugin Name: AddToAny Share Buttons
4
  * Plugin URI: https://www.addtoany.com/
5
  * Description: Share buttons for your pages including AddToAny's universal sharing button, Facebook, Twitter, LinkedIn, Pinterest, WhatsApp and many more.
6
+ * Version: 1.8.2
7
  * Author: AddToAny
8
  * Author URI: https://www.addtoany.com/
9
  * Text Domain: add-to-any
1090
  . addtoany_menu_locale_escaped()
1091
  . $floating_js_escaped
1092
  . $script_configs_escaped
 
 
 
 
 
 
 
 
1093
  . "\n";
1094
 
1095
+ // Name the handle `addtoany-core` instead of `addtoany` which was previously only used for the local addtoany.min.js file.
1096
+ $script_handle = 'addtoany-core';
1097
+ $script_src = $static_server . '/page.js' . $querystring;
1098
 
1099
+ // Require an empty `addtoany-core` script to be enqueued because wp_add_inline_script() below requires a queued script.
1100
+ wp_register_script( $script_handle, $script_src, array(), null );
1101
+ wp_enqueue_script( $script_handle );
1102
+
1103
  // Add inline JavaScript. Arbitrary JavaScript is expected from users with the `unfiltered_html` capability.
1104
+ wp_add_inline_script( $script_handle, $inline_javascript, 'before' );
1105
 
1106
  // Load script that depends on jQuery only if jQuery is registered.
1107
  if ( wp_script_is( 'jquery', 'registered' ) ) {
1110
 
1111
  // Adjust script tag attributes.
1112
  add_filter( 'script_loader_tag', function ( $tag, $handle, $src ) {
1113
+ $script_handles = array( 'addtoany-core', 'addtoany-jquery' );
1114
+ if ( in_array( $handle, $script_handles ) ) {
1115
+ // Add async attribute to the script tags with the src attribute.
1116
+ $tag = preg_replace( '/ src=/', ' async src=', $tag, 1 );
 
1117
  }
1118
  return $tag;
1119
  }, 10, 3 );