Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Twitter partner ID for Twitter shortcodes and timeline widget #6190

Merged
merged 5 commits into from
Jan 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions modules/shortcodes/tweet.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ 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 );

/**
* 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' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a docblock to this new filter, so it can be parsed and integrated in the Jetpack Codex? It also helps whoever may want to use the filter later.

Here is an example of how to format your docblock.


// Add Twitter partner ID to track embeds from Jetpack
if ( ! empty( $partner ) ) {
$provider = add_query_arg( 'partner', $partner, $provider );
}

return $provider;
}

Expand Down
5 changes: 5 additions & 0 deletions modules/shortcodes/twitter-timeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ function twitter_timeline_shortcode( $atts ) {

$output = '<a class="twitter-timeline"';

/** This filter is documented in modules/shortcodes/tweet.php */
$partner = apply_filters( 'jetpack_twitter_partner_id', 'jetpack' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you've documented the filter in one place, you can refer to it like so:
/** This filter is documented in modules/shortcodes/tweet.php */

if ( ! empty( $partner ) ) {
$output .= ' data-partner="' . esc_attr( $partner ) . '"';
}
if ( is_numeric( $atts['width'] ) ) {
$output .= ' data-width="' . esc_attr( $atts['width'] ) . '"';
}
Expand Down
6 changes: 6 additions & 0 deletions modules/widgets/twitter-timeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) ) . '"';
}
Expand Down
14 changes: 13 additions & 1 deletion tests/php/modules/shortcodes/test_class.tweet.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,16 @@ public function test_shortcodes_tweet_id_only() {
$this->assertContains( '<a href="https://twitter.com/jetpack/status/759034293385502721">', $shortcode_content );
}

}
/**
* Verify that rendering the shortcode contains Jetpack's partner ID
*
* @since 4.6.0
*/
public function test_shortcode_tweet_partner_id() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

$content = "[tweet 759034293385502721]";

$shortcode_content = do_shortcode( $content );

$this->assertContains( 'data-partner="jetpack"', $shortcode_content );
}
}
12 changes: 12 additions & 0 deletions tests/php/modules/shortcodes/test_class.twitter-timeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}