Twitter - Version 2.0.1

Version Description

  • Enqueue Twitter widgets JavaScript and advertising JavaScript early in the page build process if a widget is active on the page
  • Tweet button: update expected length of a wrapped t.co URL with HTTP scheme
  • Support expanded post metadata descriptors in WordPress 4.6+. Includes REST API support for custom Tweet button and Twitter Cards values
  • Fix post metadata deletion for custom Tweet button and Twitter Card text
Download this release

Release Info

Developer niallkennedy
Plugin Icon 128x128 Twitter
Version 2.0.1
Comparing to
See all releases

Code changes from version 2.0.0 to 2.0.1

readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: Twitter, niallkennedy
3
  Tags: twitter, embedded tweet, embedded timeline, twitter profile, twitter list, twitter moment, twitter video, twitter grid, vine, periscope, twitter cards, tweet button, follow button, twitter analytics, twitter ads
4
  Requires at least: 4.1
5
  Tested up to: 4.7
6
- Stable tag: 2.0.0
7
  License: MIT
8
  License URI: https://opensource.org/licenses/MIT
9
 
@@ -72,6 +72,12 @@ Shortcode improvements for ajax-loaded posts. Remove photo, gallery, and product
72
  Display admin notice if current PHP version does not meet minimum requirements. Do not display Tweet button in auto-generated excerpt.
73
 
74
  == Changelog ==
 
 
 
 
 
 
75
  = 2.0.0 =
76
  * Embed a [profile timeline](https://dev.twitter.com/web/embedded-timelines/user "Twitter embedded profile timeline"), [list timeline](https://dev.twitter.com/web/embedded-timelines/list "Twitter embedded list timeline"), or [collection](https://dev.twitter.com/web/embedded-timelines/collection "Twitter embedded collection") by pasting a URL, customizing a shortcode, or a widget
77
  * Embed a [search timeline](https://dev.twitter.com/web/embedded-timelines/search "Twitter embedded search timeline") by shortcode or widget using a widget ID configured on Twitter.com
3
  Tags: twitter, embedded tweet, embedded timeline, twitter profile, twitter list, twitter moment, twitter video, twitter grid, vine, periscope, twitter cards, tweet button, follow button, twitter analytics, twitter ads
4
  Requires at least: 4.1
5
  Tested up to: 4.7
6
+ Stable tag: 2.0.1
7
  License: MIT
8
  License URI: https://opensource.org/licenses/MIT
9
 
72
  Display admin notice if current PHP version does not meet minimum requirements. Do not display Tweet button in auto-generated excerpt.
73
 
74
  == Changelog ==
75
+ = 2.0.1 =
76
+ * Enqueue Twitter widgets JavaScript and advertising JavaScript early in the page build process if a widget is active on the page
77
+ * Tweet button: update expected length of a wrapped t.co URL with HTTP scheme
78
+ * Support expanded post metadata descriptors in WordPress 4.6+. Includes REST API support for custom Tweet button and Twitter Cards values
79
+ * Fix post metadata deletion for custom Tweet button and Twitter Card text
80
+
81
  = 2.0.0 =
82
  * Embed a [profile timeline](https://dev.twitter.com/web/embedded-timelines/user "Twitter embedded profile timeline"), [list timeline](https://dev.twitter.com/web/embedded-timelines/list "Twitter embedded list timeline"), or [collection](https://dev.twitter.com/web/embedded-timelines/collection "Twitter embedded collection") by pasting a URL, customizing a shortcode, or a widget
83
  * Embed a [search timeline](https://dev.twitter.com/web/embedded-timelines/search "Twitter embedded search timeline") by shortcode or widget using a widget ID configured on Twitter.com
src/Twitter/WordPress/Admin/Post/TweetIntent.php CHANGED
@@ -71,10 +71,21 @@ class TweetIntent
71
  */
72
  public static function registerPostMeta()
73
  {
 
 
 
 
 
 
 
 
 
 
 
74
  register_meta(
75
  'post',
76
  static::META_KEY,
77
- array( __CLASS__, 'sanitizeFields' )
78
  );
79
  }
80
 
@@ -86,13 +97,14 @@ class TweetIntent
86
  *
87
  * @since 1.0.0
88
  *
 
 
89
  * @return object object with short_url_length and optional short_url_length_https properties
90
  */
91
  public static function getTwitterConfiguration()
92
  {
93
  $config = new \stdClass();
94
- $config->short_url_length = 22;
95
- $config->short_url_length_https = $config->short_url_length + 1;
96
 
97
  return $config;
98
  }
@@ -111,27 +123,7 @@ class TweetIntent
111
  if ( ! ( is_object( $config ) && isset( $config->short_url_length ) ) ) {
112
  return 0;
113
  }
114
- $url_length = absint( $config->short_url_length );
115
-
116
- // check if the post URL to be wrapped uses the HTTPS scheme
117
- if ( isset( $config->short_url_length_https ) ) {
118
- $post_url = get_permalink();
119
- if ( $post_url ) {
120
- $is_https = false;
121
- try {
122
- if ( 'https' === strtolower( parse_url( $post_url, PHP_URL_SCHEME ) ) ) {
123
- $is_https = true;
124
- }
125
- } catch (\Exception $e) {
126
- // assume not HTTPS if parse_url throws exception
127
- }
128
- if ( $is_https ) {
129
- $url_length = absint( $config->short_url_length_https );
130
- }
131
- }
132
- }
133
-
134
- return $url_length;
135
  }
136
 
137
  /**
@@ -302,7 +294,7 @@ class TweetIntent
302
 
303
  $fields = static::sanitizeFields( $fields );
304
  if ( empty( $fields ) ) {
305
- delete_post_meta_by_key( static::META_KEY );
306
  } else {
307
  update_post_meta( $post->ID, static::META_KEY, $fields );
308
  }
71
  */
72
  public static function registerPostMeta()
73
  {
74
+ $args = array( get_called_class(), 'sanitizeFields' );
75
+ // extra parameters for WordPress 4.6+
76
+ if ( function_exists( 'registered_meta_key_exists' ) ) {
77
+ $args = array(
78
+ 'sanitize_callback' => $args,
79
+ 'description' => __( 'Customize Tweet button pre-populated share text and hashtags', 'twitter' ),
80
+ 'show_in_rest' => true,
81
+ 'type' => 'array',
82
+ 'single' => true,
83
+ );
84
+ }
85
  register_meta(
86
  'post',
87
  static::META_KEY,
88
+ $args
89
  );
90
  }
91
 
97
  *
98
  * @since 1.0.0
99
  *
100
+ * @see https://dev.twitter.com/rest/reference/get/help/configuration
101
+ *
102
  * @return object object with short_url_length and optional short_url_length_https properties
103
  */
104
  public static function getTwitterConfiguration()
105
  {
106
  $config = new \stdClass();
107
+ $config->short_url_length = 23;
 
108
 
109
  return $config;
110
  }
123
  if ( ! ( is_object( $config ) && isset( $config->short_url_length ) ) ) {
124
  return 0;
125
  }
126
+ return absint( $config->short_url_length );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  }
128
 
129
  /**
294
 
295
  $fields = static::sanitizeFields( $fields );
296
  if ( empty( $fields ) ) {
297
+ delete_post_meta( $post->ID, static::META_KEY );
298
  } else {
299
  update_post_meta( $post->ID, static::META_KEY, $fields );
300
  }
src/Twitter/WordPress/Admin/Post/TwitterCard.php CHANGED
@@ -71,10 +71,20 @@ class TwitterCard
71
  */
72
  public static function registerPostMeta()
73
  {
 
 
 
 
 
 
 
 
 
 
74
  register_meta(
75
  'post',
76
  static::META_KEY,
77
- array( __CLASS__, 'sanitizeFields' )
78
  );
79
  }
80
 
@@ -248,7 +258,7 @@ class TwitterCard
248
 
249
  $fields = static::sanitizeFields( $fields );
250
  if ( empty( $fields ) ) {
251
- delete_post_meta_by_key( static::META_KEY );
252
  } else {
253
  update_post_meta( $post->ID, static::META_KEY, $fields );
254
  }
71
  */
72
  public static function registerPostMeta()
73
  {
74
+ $args = array( get_called_class(), 'sanitizeFields' );
75
+ if ( function_exists( 'registered_meta_key_exists' ) ) {
76
+ $args = array(
77
+ 'sanitize_callback' => $args,
78
+ 'description' => __( 'Customize title and description shown in Twitter link previews', 'twitter' ),
79
+ 'show_in_rest' => true,
80
+ 'type' => 'array',
81
+ 'single' => true,
82
+ );
83
+ }
84
  register_meta(
85
  'post',
86
  static::META_KEY,
87
+ $args
88
  );
89
  }
90
 
258
 
259
  $fields = static::sanitizeFields( $fields );
260
  if ( empty( $fields ) ) {
261
+ delete_post_meta( $post->ID, static::META_KEY );
262
  } else {
263
  update_post_meta( $post->ID, static::META_KEY, $fields );
264
  }
src/Twitter/WordPress/PluginLoader.php CHANGED
@@ -41,7 +41,7 @@ class PluginLoader
41
  *
42
  * @type string
43
  */
44
- const VERSION = '2.0.0';
45
 
46
  /**
47
  * Unique domain of the plugin's translated text
@@ -166,6 +166,66 @@ class PluginLoader
166
  }
167
  }
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  /**
170
  * Hook into actions and filters specific to a WordPress administrative view
171
  *
@@ -209,14 +269,9 @@ class PluginLoader
209
  $features = \Twitter\WordPress\Features::getEnabledFeatures();
210
 
211
  // load widgets JS if a Twitter widget is active
212
- if ( ( isset( $features[ \Twitter\WordPress\Features::FOLLOW_BUTTON ] ) && is_active_widget( false, false, \Twitter\WordPress\Widgets\Buttons\Follow::BASE_ID, true ) )
213
- || ( isset( $features[ \Twitter\WordPress\Features::PERISCOPE_ON_AIR ] ) && is_active_widget( false, false, \Twitter\WordPress\Widgets\Buttons\Periscope\OnAir::BASE_ID, true ) )
214
- ) {
215
- // enqueue after the script is registered in wp_enqueue_scripts action priority 1
216
- add_action( 'wp_enqueue_scripts', array( '\Twitter\WordPress\JavaScriptLoaders\Widgets', 'enqueue' ) );
217
- // register DNS prefetch before WordPress resource hints run at wp_head priority 2
218
- add_action( 'wp_head', array( '\Twitter\WordPress\JavaScriptLoaders\Widgets', 'dnsPrefetch' ), 1 );
219
- }
220
 
221
  // do not add content filters to HTTP 404 response
222
  if ( is_404() ) {
41
  *
42
  * @type string
43
  */
44
+ const VERSION = '2.0.1';
45
 
46
  /**
47
  * Unique domain of the plugin's translated text
166
  }
167
  }
168
 
169
+ /**
170
+ * Load Twitter widgets JavaScript early in the page build if a dependent widget will be rendered
171
+ *
172
+ * @since 2.0.1
173
+ *
174
+ * @return void
175
+ */
176
+ public static function loadTwitterWidgetsJavaScriptWhenWidgetsActive()
177
+ {
178
+ $widgets_js_widgets = static::getAvailableWidgets();
179
+ // remove widgets not depending on Twitter widgets JS
180
+ unset( $widgets_js_widgets[ \Twitter\WordPress\Features::TRACKING_PIXEL ] );
181
+ if ( empty( $widgets_js_widgets ) ) {
182
+ return;
183
+ }
184
+
185
+ $features = \Twitter\WordPress\Features::getEnabledFeatures();
186
+ foreach ( $widgets_js_widgets as $feature_name => $widget_class ) {
187
+ if ( isset( $features[ $feature_name ] ) ) {
188
+ if ( method_exists( $widget_class, 'getBaseID' ) ) {
189
+ $base_id = $widget_class::getBaseID();
190
+ if ( $base_id && is_active_widget( false, false, $base_id, true ) ) {
191
+ // enqueue after the script is registered in wp_enqueue_scripts action priority 1
192
+ add_action( 'wp_enqueue_scripts', array( '\Twitter\WordPress\JavaScriptLoaders\Widgets', 'enqueue' ) );
193
+
194
+ // register DNS prefetch before WordPress resource hints run at wp_head priority 2
195
+ add_action( 'wp_head', array( '\Twitter\WordPress\JavaScriptLoaders\Widgets', 'dnsPrefetch' ), 1 );
196
+
197
+ // only enqueue once
198
+ return;
199
+ }
200
+ unset( $base_id );
201
+ }
202
+ }
203
+ }
204
+ }
205
+
206
+ /**
207
+ * Load Twitter advertising JavaScript early in the page build if an ad tracker widget will be rendered
208
+ *
209
+ * @since 2.0.1
210
+ *
211
+ * @return void
212
+ */
213
+ public static function loadTwitterAdvertisingJavaScriptWhenWidgetsActive()
214
+ {
215
+ $features = \Twitter\WordPress\Features::getEnabledFeatures();
216
+ if ( ! isset( $features[ \Twitter\WordPress\Features::TRACKING_PIXEL ] ) ) {
217
+ return;
218
+ }
219
+
220
+ if ( is_active_widget( false, false, \Twitter\WordPress\Widgets\Advertising\Tracking::getBaseID(), true ) ) {
221
+ // enqueue after the script is registered in wp_enqueue_scripts action priority 1
222
+ add_action( 'wp_enqueue_scripts', array( '\Twitter\WordPress\JavaScriptLoaders\Tracking', 'enqueue' ) );
223
+
224
+ // register DNS prefetch before WordPress resource hints run at wp_head priority 2
225
+ add_action( 'wp_head', array( '\Twitter\WordPress\JavaScriptLoaders\Tracking', 'dnsPrefetch' ), 1 );
226
+ }
227
+ }
228
+
229
  /**
230
  * Hook into actions and filters specific to a WordPress administrative view
231
  *
269
  $features = \Twitter\WordPress\Features::getEnabledFeatures();
270
 
271
  // load widgets JS if a Twitter widget is active
272
+ static::loadTwitterWidgetsJavaScriptWhenWidgetsActive();
273
+ // load advertising JS if an ad tracking widget is active
274
+ static::loadTwitterAdvertisingJavaScriptWhenWidgetsActive();
 
 
 
 
 
275
 
276
  // do not add content filters to HTTP 404 response
277
  if ( is_404() ) {
src/Twitter/WordPress/Widgets/Advertising/Tracking.php CHANGED
@@ -34,6 +34,15 @@ namespace Twitter\WordPress\Widgets\Advertising;
34
  */
35
  class Tracking extends \Twitter\WordPress\Widgets\Widget
36
  {
 
 
 
 
 
 
 
 
 
37
  /**
38
  * Class of the related shortcode handler
39
  *
@@ -54,7 +63,7 @@ class Tracking extends \Twitter\WordPress\Widgets\Widget
54
  {
55
  $shortcode_class = static::SHORTCODE_CLASS;
56
  parent::__construct(
57
- 'twitter-tracking', // Base ID
58
  $shortcode_class::featureName(), // name
59
  array(
60
  'description' => static::getDescription(),
@@ -62,6 +71,18 @@ class Tracking extends \Twitter\WordPress\Widgets\Widget
62
  );
63
  }
64
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  /**
66
  * Describe the functionality offered by the widget
67
  *
34
  */
35
  class Tracking extends \Twitter\WordPress\Widgets\Widget
36
  {
37
+ /**
38
+ * Widget base ID
39
+ *
40
+ * @since 2.0.1
41
+ *
42
+ * @type string
43
+ */
44
+ const BASE_ID = 'twitter-tracking';
45
+
46
  /**
47
  * Class of the related shortcode handler
48
  *
63
  {
64
  $shortcode_class = static::SHORTCODE_CLASS;
65
  parent::__construct(
66
+ static::BASE_ID, // Base ID
67
  $shortcode_class::featureName(), // name
68
  array(
69
  'description' => static::getDescription(),
71
  );
72
  }
73
 
74
+ /**
75
+ * Get the base ID used to identify widgets of this type installed in a widget area
76
+ *
77
+ * @since 2.0.1
78
+ *
79
+ * @return string widget base ID
80
+ */
81
+ public static function getBaseID()
82
+ {
83
+ return static::BASE_ID;
84
+ }
85
+
86
  /**
87
  * Describe the functionality offered by the widget
88
  *
src/Twitter/WordPress/Widgets/Buttons/Follow.php CHANGED
@@ -62,6 +62,18 @@ class Follow extends \Twitter\WordPress\Widgets\Widget implements \Twitter\WordP
62
  );
63
  }
64
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  /**
66
  * Describe the functionality offered by the widget
67
  *
62
  );
63
  }
64
 
65
+ /**
66
+ * Get the base ID used to identify widgets of this type installed in a widget area
67
+ *
68
+ * @since 2.0.1
69
+ *
70
+ * @return string widget base ID
71
+ */
72
+ public static function getBaseID()
73
+ {
74
+ return static::BASE_ID;
75
+ }
76
+
77
  /**
78
  * Describe the functionality offered by the widget
79
  *
src/Twitter/WordPress/Widgets/Buttons/Periscope/OnAir.php CHANGED
@@ -62,6 +62,18 @@ class OnAir extends \Twitter\WordPress\Widgets\Widget implements \Twitter\WordPr
62
  );
63
  }
64
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  /**
66
  * Describe the functionality offered by the widget
67
  *
62
  );
63
  }
64
 
65
+ /**
66
+ * Get the base ID used to identify widgets of this type installed in a widget area
67
+ *
68
+ * @since 2.0.1
69
+ *
70
+ * @return string widget base ID
71
+ */
72
+ public static function getBaseID()
73
+ {
74
+ return static::BASE_ID;
75
+ }
76
+
77
  /**
78
  * Describe the functionality offered by the widget
79
  *
src/Twitter/WordPress/Widgets/Embeds/Timeline.php CHANGED
@@ -53,6 +53,19 @@ abstract class Timeline extends \Twitter\WordPress\Widgets\Widget implements \Tw
53
  );
54
  }
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  /**
57
  * Get displayed options for chrome configuration with label
58
  *
53
  );
54
  }
55
 
56
+ /**
57
+ * Get the base ID used to identify widgets of this type installed in a widget area
58
+ *
59
+ * @since 2.0.1
60
+ *
61
+ * @return string widget base ID
62
+ */
63
+ public static function getBaseID()
64
+ {
65
+ $shortcode_class = static::SHORTCODE_CLASS;
66
+ return $shortcode_class::HTML_CLASS;
67
+ }
68
+
69
  /**
70
  * Get displayed options for chrome configuration with label
71
  *
src/Twitter/WordPress/Widgets/WidgetInterface.php CHANGED
@@ -40,6 +40,15 @@ interface WidgetInterface
40
  */
41
  function __construct();
42
 
 
 
 
 
 
 
 
 
 
43
  /**
44
  * Describe the functionality offered by the widget
45
  *
40
  */
41
  function __construct();
42
 
43
+ /**
44
+ * Get the base ID used to identify widgets of this type installed in a widget area
45
+ *
46
+ * @since 2.0.1
47
+ *
48
+ * @return string widget base ID
49
+ */
50
+ public static function getBaseID();
51
+
52
  /**
53
  * Describe the functionality offered by the widget
54
  *
twitter.php CHANGED
@@ -24,13 +24,13 @@ THE SOFTWARE.
24
  */
25
  /**
26
  * @package twitter
27
- * @version 2.0.0
28
  */
29
  /*
30
  Plugin Name: Twitter
31
  Plugin URI: http://wordpress.org/plugins/twitter/
32
  Description: Official Twitter plugin for WordPress. Embed Twitter content and grow your audience on Twitter. Requires PHP 5.4 or greater.
33
- Version: 2.0.0
34
  Author: Twitter
35
  Author URI: https://dev.twitter.com/
36
  License: MIT
24
  */
25
  /**
26
  * @package twitter
27
+ * @version 2.0.1
28
  */
29
  /*
30
  Plugin Name: Twitter
31
  Plugin URI: http://wordpress.org/plugins/twitter/
32
  Description: Official Twitter plugin for WordPress. Embed Twitter content and grow your audience on Twitter. Requires PHP 5.4 or greater.
33
+ Version: 2.0.1
34
  Author: Twitter
35
  Author URI: https://dev.twitter.com/
36
  License: MIT