From a88ee9546987f4e6c3defccf9c0df4d824a61b82 Mon Sep 17 00:00:00 2001 From: Jacob Morrison Date: Fri, 27 Jan 2017 14:24:24 +0000 Subject: [PATCH 1/5] Add Twitter partner ID for `[tweet]` and `[twitter-timeline]` shortcodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enables Twitter partner tracking discovery in Jetpack’s Twitter shortcodes. See: automattic/jetpack#5984 --- modules/shortcodes/tweet.php | 6 ++++++ modules/shortcodes/twitter-timeline.php | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/modules/shortcodes/tweet.php b/modules/shortcodes/tweet.php index 5f73aef73f77b..1c61e3141644f 100644 --- a/modules/shortcodes/tweet.php +++ b/modules/shortcodes/tweet.php @@ -111,6 +111,12 @@ static public function jetpack_tweet_url_extra_args( $provider, $url, $args = ar // Twitter doesn't support maxheight so don't send it $provider = remove_query_arg( 'maxheight', $provider ); + // Add Twitter partner ID to track embeds from Jetpack + $partner = apply_filters( 'jetpack_twitter_partner_id', 'jetpack' ); + if ( false !== $partner ) { + $provider = add_query_arg( 'partner', $partner, $provider ); + } + return $provider; } diff --git a/modules/shortcodes/twitter-timeline.php b/modules/shortcodes/twitter-timeline.php index bce9d2a9eac07..d844ba862e5d1 100644 --- a/modules/shortcodes/twitter-timeline.php +++ b/modules/shortcodes/twitter-timeline.php @@ -19,6 +19,10 @@ function twitter_timeline_shortcode( $atts ) { $output = ' Date: Fri, 27 Jan 2017 15:27:03 +0000 Subject: [PATCH 2/5] Add tests for Twitter shortcodes' inclusion of Jetpack's partner ID --- tests/php/modules/shortcodes/test_class.tweet.php | 14 +++++++++++++- .../shortcodes/test_class.twitter-timeline.php | 12 ++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/php/modules/shortcodes/test_class.tweet.php b/tests/php/modules/shortcodes/test_class.tweet.php index 84a60467e0e7c..71828453ffee8 100644 --- a/tests/php/modules/shortcodes/test_class.tweet.php +++ b/tests/php/modules/shortcodes/test_class.tweet.php @@ -67,4 +67,16 @@ public function test_shortcodes_tweet_id_only() { $this->assertContains( '', $shortcode_content ); } -} \ No newline at end of file + /** + * Verify that rendering the shortcode contains Jetpack's partner ID + * + * @since 4.6.0 + */ + public function test_shortcode_tweet_partner_id() { + $content = "[tweet 759034293385502721]"; + + $shortcode_content = do_shortcode( $content ); + + $this->assertContains( 'data-partner="jetpack"', $shortcode_content ); + } +} diff --git a/tests/php/modules/shortcodes/test_class.twitter-timeline.php b/tests/php/modules/shortcodes/test_class.twitter-timeline.php index fae6f4e8d42d5..fab52b0e2bf67 100644 --- a/tests/php/modules/shortcodes/test_class.twitter-timeline.php +++ b/tests/php/modules/shortcodes/test_class.twitter-timeline.php @@ -24,4 +24,16 @@ public function test_shortcodes_twitter_timeline() { $this->assertNotEquals( $content, $shortcode_content ); } + /** + * Verify that rendering the shortcode contains Jetpack's partner ID + * + * @since 4.6.0 + */ + public function test_shortcode_tweet_partner_id() { + $content = "[twitter-timeline username=automattic]"; + + $shortcode_content = do_shortcode( $content ); + + $this->assertContains( 'data-partner="jetpack"', $shortcode_content ); + } } From 9d8957baa281926bb2974e092c0db411c2353ccc Mon Sep 17 00:00:00 2001 From: Jacob Morrison Date: Fri, 27 Jan 2017 16:42:40 +0000 Subject: [PATCH 3/5] Change to hide empty Twitter partner ID from relevant shortcodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Will also hide partner ID from shortcodes if null, ‘’, or 0. --- modules/shortcodes/tweet.php | 2 +- modules/shortcodes/twitter-timeline.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/shortcodes/tweet.php b/modules/shortcodes/tweet.php index 1c61e3141644f..6fdf75de5c914 100644 --- a/modules/shortcodes/tweet.php +++ b/modules/shortcodes/tweet.php @@ -113,7 +113,7 @@ static public function jetpack_tweet_url_extra_args( $provider, $url, $args = ar // Add Twitter partner ID to track embeds from Jetpack $partner = apply_filters( 'jetpack_twitter_partner_id', 'jetpack' ); - if ( false !== $partner ) { + if ( ! empty( $partner ) ) { $provider = add_query_arg( 'partner', $partner, $provider ); } diff --git a/modules/shortcodes/twitter-timeline.php b/modules/shortcodes/twitter-timeline.php index d844ba862e5d1..c3abb26db099c 100644 --- a/modules/shortcodes/twitter-timeline.php +++ b/modules/shortcodes/twitter-timeline.php @@ -20,7 +20,7 @@ function twitter_timeline_shortcode( $atts ) { $output = ' Date: Fri, 27 Jan 2017 17:36:24 +0000 Subject: [PATCH 4/5] Add filter documentation for 'jetpack_twitter_partner_id' --- modules/shortcodes/tweet.php | 12 +++++++++++- modules/shortcodes/twitter-timeline.php | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/shortcodes/tweet.php b/modules/shortcodes/tweet.php index 6fdf75de5c914..9a6a679a8dbdc 100644 --- a/modules/shortcodes/tweet.php +++ b/modules/shortcodes/tweet.php @@ -111,8 +111,18 @@ static public function jetpack_tweet_url_extra_args( $provider, $url, $args = ar // Twitter doesn't support maxheight so don't send it $provider = remove_query_arg( 'maxheight', $provider ); - // Add Twitter partner ID to track embeds from Jetpack + /** + * Filter the Twitter Partner ID. + * + * @module shortcodes + * + * @since 4.6.0 + * + * @param string $partner_id Twitter partner ID. + */ $partner = apply_filters( 'jetpack_twitter_partner_id', 'jetpack' ); + + // Add Twitter partner ID to track embeds from Jetpack if ( ! empty( $partner ) ) { $provider = add_query_arg( 'partner', $partner, $provider ); } diff --git a/modules/shortcodes/twitter-timeline.php b/modules/shortcodes/twitter-timeline.php index c3abb26db099c..38558b49d3512 100644 --- a/modules/shortcodes/twitter-timeline.php +++ b/modules/shortcodes/twitter-timeline.php @@ -19,6 +19,7 @@ function twitter_timeline_shortcode( $atts ) { $output = ' Date: Fri, 27 Jan 2017 17:42:56 +0000 Subject: [PATCH 5/5] Add Twitter partner ID to Twitter timeline widget --- modules/widgets/twitter-timeline.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/widgets/twitter-timeline.php b/modules/widgets/twitter-timeline.php index 573127f59ee74..4e6f3da7ea56a 100644 --- a/modules/widgets/twitter-timeline.php +++ b/modules/widgets/twitter-timeline.php @@ -108,6 +108,12 @@ public function widget( $args, $instance ) { } } + /** This filter is documented in modules/shortcodes/tweet.php */ + $partner = apply_filters( 'jetpack_twitter_partner_id', 'jetpack' ); + if ( ! empty( $partner ) ) { + echo ' data-partner="' . esc_attr( $partner ) . '"'; + } + if ( ! empty( $instance['chrome'] ) && is_array( $instance['chrome'] ) ) { echo ' data-chrome="' . esc_attr( join( ' ', $instance['chrome'] ) ) . '"'; }