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

Remove handling of Jetpack shortcodes #3678

Merged
merged 36 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9436ac2
Add a way to deprecate the AMP plugin's handling of Vimeo shortcode
kienstra Oct 31, 2019
73b8b10
Change the name of the class, as it changed in the Jetpack PR
kienstra Nov 1, 2019
5ceb39b
Change the name of the filter again, as it changed in the Jetpack PR
kienstra Nov 1, 2019
26a22c7
Allow using the helper function in any embed handler
kienstra Nov 1, 2019
92d9de1
Use the helper function before adding the [tweet] shortcode
kienstra Nov 1, 2019
a98f88c
Merge branch 'develop' into update/vimeo-shortocode-support
kienstra Nov 1, 2019
85077be
Also defer AMP [soundcloud] shortcode handling to Jetpack
kienstra Nov 1, 2019
b64392b
Simplify check for whether Jetpack AMP shortocode is available
kienstra Nov 4, 2019
3e0e649
Change @deprecated tag to be 'Moved to...'
kienstra Nov 4, 2019
d0b73eb
Update the class_exists() call to funciton_exists(), as it's now a fu…
kienstra Nov 5, 2019
0192ff5
Change function name to reflect the change in the Jetpack PR
kienstra Nov 6, 2019
93cfaba
Update the function names to reflect the latest in the PR
kienstra Nov 7, 2019
fcda766
Deprecate this plugin's handling of the [youtube] shortcode
kienstra Nov 11, 2019
302d611
Update the souncloud conditional for the new function
kienstra Nov 13, 2019
822ca4b
Remove add_shortcode() and remove_shortcode() for the [soundcloud] sh…
kienstra Nov 14, 2019
a4bcd1b
Remove the add_shortcode() and remove_shortcode() calls for [tweet]
kienstra Nov 14, 2019
5d74750
Deprecate the handling of the [instagram] shortcode
kienstra Nov 15, 2019
00b2e2c
Remove [dailymotion] shortcode handling and deprecate function
kienstra Nov 16, 2019
ec5257e
Remove needless SHORTCODE_TAG constants
kienstra Nov 19, 2019
6f6d3f7
For the [vimeo] shortcode, remove the add_shortcode() call
kienstra Nov 19, 2019
e2e2d5c
Merge in develop, resolve conflicts
kienstra Nov 19, 2019
d53df79
Delete shortcode handlers and their tests
kienstra Nov 20, 2019
bac7db1
Remove unused SHORTCODE_TAG constant
kienstra Nov 20, 2019
672997e
Merge branch 'develop' of github.com:ampproject/amp-wp into update/vi…
westonruter Dec 4, 2019
e168813
Remove call to removed method; update phpdoc
westonruter Dec 4, 2019
1a4b700
Merge in develop, resolve conflicts
kienstra Dec 4, 2019
9f9c2ff
Remove AMP_Twitter_Embed_Handler::filter_embed_oembed_html()
kienstra Dec 4, 2019
2d5ae27
Correct an apparent error I made in resolving a merge conflict
kienstra Dec 4, 2019
5097040
Restore AMP_YouTube_Embed_Handler::video_override()
kienstra Dec 4, 2019
b300e9d
Deprecate AMP_YouTube_Embed_Handler::shortcode()
kienstra Dec 4, 2019
fdb463e
Refactor AMP_Vimeo_Embed_Handler::shortcode() into video_override()
kienstra Dec 4, 2019
2d71b6b
Replace a call to ->shortcode() with the logic from shortcode()
kienstra Dec 4, 2019
ba51034
Align @param descriptions in test_video_override
kienstra Dec 4, 2019
6ae3419
Delete AMP_Twitter_Embed_Handler::oembed()
kienstra Dec 5, 2019
4726922
Delete AMP_YouTube_Embed_Handler::shortcode() and oembed()
kienstra Dec 5, 2019
19e05de
Remove unused AMP_YouTube_Embed_Handler::sanitize_v_arg method after …
westonruter Dec 6, 2019
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
32 changes: 1 addition & 31 deletions includes/embeds/class-amp-dailymotion-embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,43 +49,13 @@ public function __construct( $args = [] ) {
*/
public function register_embed() {
wp_embed_register_handler( 'amp-dailymotion', self::URL_PATTERN, [ $this, 'oembed' ], -1 );
add_shortcode( 'dailymotion', [ $this, 'shortcode' ] );
}

/**
* Unregister embed.
*/
public function unregister_embed() {
wp_embed_unregister_handler( 'amp-dailymotion', -1 );
remove_shortcode( 'dailymotion' );
}

/**
* Gets AMP-compliant markup for the Dailymotion shortcode.
*
* @param array $attr The Dailymotion attributes.
* @return string Dailymotion shortcode markup.
*/
public function shortcode( $attr ) {
$video_id = false;

if ( isset( $attr['id'] ) ) {
$video_id = $attr['id'];
} elseif ( isset( $attr[0] ) ) {
$video_id = $attr[0];
} elseif ( function_exists( 'shortcode_new_to_old_params' ) ) {
$video_id = shortcode_new_to_old_params( $attr );
}

if ( empty( $video_id ) ) {
return '';
}

return $this->render(
[
'video_id' => $video_id,
]
);
}

/**
Expand All @@ -94,7 +64,7 @@ public function shortcode( $attr ) {
* @see \WP_Embed::shortcode()
*
* @param array $matches URL pattern matches.
* @param array $attr Shortcode attribues.
* @param array $attr Shortcode attributes.
* @param string $url URL.
* @param string $rawattr Unmodified shortcode attributes.
* @return string Rendered oEmbed.
Expand Down
4 changes: 2 additions & 2 deletions includes/embeds/class-amp-gfycat-embed-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public function unregister_embed() {
/**
* Filter oEmbed HTML for Gfycat to prepare it for AMP.
*
* @param mixed $return The shortcode callback function to call.
* @param mixed $return The oEmbed HTML.
* @param string $url The attempted embed URL.
* @param array $attr An array of shortcode attributes.
* @param array $attr Attributes.
* @return string Embed.
*/
public function filter_embed_oembed_html( $return, $url, $attr ) {
Expand Down
4 changes: 2 additions & 2 deletions includes/embeds/class-amp-hulu-embed-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public function unregister_embed() {
/**
* Filter oEmbed HTML for Hulu to prepare it for AMP.
*
* @param mixed $return The shortcode callback function to call.
* @param mixed $return The oEmbed HTML.
* @param string $url The attempted embed URL.
* @param array $attr An array of shortcode attributes.
* @param array $attr Attributes.
* @return string Embed.
*/
public function filter_embed_oembed_html( $return, $url, $attr ) {
Expand Down
4 changes: 2 additions & 2 deletions includes/embeds/class-amp-imgur-embed-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public function render( $args ) {
/**
* Filter oEmbed HTML for Imgur to prepare it for AMP.
*
* @param mixed $return The shortcode callback function to call.
* @param mixed $return The oEmbed HTML.
* @param string $url The attempted embed URL.
* @param array $attr An array of shortcode attributes.
* @param array $attr Attributes.
* @return string Embed.
*/
public function filter_embed_oembed_html( $return, $url, $attr ) {
Expand Down
29 changes: 0 additions & 29 deletions includes/embeds/class-amp-instagram-embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,42 +47,13 @@ class AMP_Instagram_Embed_Handler extends AMP_Base_Embed_Handler {
*/
public function register_embed() {
wp_embed_register_handler( $this->amp_tag, self::URL_PATTERN, [ $this, 'oembed' ], -1 );
add_shortcode( 'instagram', [ $this, 'shortcode' ] );
}

/**
* Unregisters embed.
*/
public function unregister_embed() {
wp_embed_unregister_handler( $this->amp_tag, -1 );
remove_shortcode( 'instagram' );
}

/**
* WordPress shortcode rendering callback.
*
* @param array $attr Shortcode attributes.
* @return string HTML markup for rendered embed.
*/
public function shortcode( $attr ) {
$url = false;

if ( isset( $attr['url'] ) ) {
$url = trim( $attr['url'] );
}

if ( empty( $url ) ) {
return '';
}

$instagram_id = $this->get_instagram_id_from_url( $url );

return $this->render(
[
'url' => $url,
'instagram_id' => $instagram_id,
]
);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions includes/embeds/class-amp-issuu-embed-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public function unregister_embed() {
/**
* Filter oEmbed HTML for Meetup to prepare it for AMP.
*
* @param mixed $return The shortcode callback function to call.
* @param mixed $return The oEmbed HTML.
* @param string $url The attempted embed URL.
* @param array $attr An array of shortcode attributes.
* @param array $attr Attributes.
* @return string Embed.
*/
public function filter_embed_oembed_html( $return, $url, $attr ) {
Expand Down
46 changes: 0 additions & 46 deletions includes/embeds/class-amp-soundcloud-embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,13 @@ class AMP_SoundCloud_Embed_Handler extends AMP_Base_Embed_Handler {
* Register embed.
*/
public function register_embed() {
if ( function_exists( 'soundcloud_shortcode' ) ) {
// @todo Move this to Jetpack.
add_shortcode( 'soundcloud', [ $this, 'shortcode' ] );
}
add_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10, 2 );
}

/**
* Unregister embed.
*/
public function unregister_embed() {
if ( function_exists( 'soundcloud_shortcode' ) ) {
// @todo Move this to Jetpack.
remove_shortcode( 'soundcloud' );
}
remove_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10 );
}

Expand Down Expand Up @@ -111,44 +103,6 @@ private function parse_amp_component_from_iframe( $html, $url = null ) {
return $this->render( $props, $url );
}

/**
* Render shortcode.
*
* @todo Move this to Jetpack.
*
* @param array $attr Shortcode attributes.
* @param string $content Shortcode content.
* @return string Rendered shortcode.
*/
public function shortcode( $attr, $content = null ) {
if ( ! function_exists( 'soundcloud_shortcode' ) ) {
return '';
}

if ( isset( $attr['url'] ) ) {
$url = $attr['url'];
} elseif ( isset( $attr['id'] ) ) {
$url = 'https://api.soundcloud.com/tracks/' . $attr['id'];
} elseif ( isset( $attr[0] ) ) {
$url = is_numeric( $attr[0] ) ? 'https://api.soundcloud.com/tracks/' . $attr[0] : $attr[0];
} elseif ( function_exists( 'shortcode_new_to_old_params' ) ) {
$url = shortcode_new_to_old_params( $attr );
}

// Defer to oEmbed if an oEmbeddable URL is provided.
if ( isset( $url ) && 'api.soundcloud.com' !== wp_parse_url( $url, PHP_URL_HOST ) ) {
global $wp_embed;
return $wp_embed->shortcode( $attr, $url );
}

if ( isset( $url ) && ! isset( $attr['url'] ) ) {
$attr['url'] = $url;
}
$output = soundcloud_shortcode( $attr, $content );

return $this->parse_amp_component_from_iframe( $output, null );
}

/**
* Render embed.
*
Expand Down
75 changes: 0 additions & 75 deletions includes/embeds/class-amp-twitter-embed-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,91 +46,16 @@ class AMP_Twitter_Embed_Handler extends AMP_Base_Embed_Handler {
* Registers embed.
*/
public function register_embed() {
add_shortcode( 'tweet', [ $this, 'shortcode' ] ); // Note: This is a Jetpack shortcode.
wp_embed_register_handler( 'amp-twitter-timeline', self::URL_PATTERN_TIMELINE, [ $this, 'oembed_timeline' ], -1 );
}

/**
* Unregisters embed.
*/
public function unregister_embed() {
remove_shortcode( 'tweet' ); // Note: This is a Jetpack shortcode.
wp_embed_unregister_handler( 'amp-twitter-timeline', -1 );
}

/**
* Gets AMP-compliant markup for the Twitter shortcode.
*
* Note that this shortcode is is defined in Jetpack.
*
* @param array $attr The Twitter attributes.
* @return string Twitter shortcode markup.
*/
public function shortcode( $attr ) {
$attr = wp_parse_args(
$attr,
[
'tweet' => false,
]
);

if ( empty( $attr['tweet'] ) && ! empty( $attr[0] ) ) {
$attr['tweet'] = $attr[0];
}

$id = false;
if ( is_numeric( $attr['tweet'] ) ) {
$id = $attr['tweet'];
} else {
preg_match( self::URL_PATTERN, $attr['tweet'], $matches );
if ( isset( $matches['tweet'] ) && is_numeric( $matches['tweet'] ) ) {
$id = $matches['tweet'];
}

if ( empty( $id ) ) {
return '';
}
}

$this->did_convert_elements = true;

return AMP_HTML_Utils::build_tag(
$this->amp_tag,
[
'data-tweetid' => $id,
'layout' => 'responsive',
'width' => $this->args['width'],
'height' => $this->args['height'],
]
);
}

/**
* Render oEmbed.
*
* @deprecated Since 1.1 as now the sanitize_raw_embeds() is used exclusively, allowing the
* original oEmbed response to be wrapped with `amp-twitter`.
*
* @see \WP_Embed::shortcode()
*
* @param array $matches URL pattern matches.
* @return string Rendered oEmbed.
*/
public function oembed( $matches ) {
_deprecated_function( __METHOD__, '1.1' );
$id = false;

if ( isset( $matches['tweet'] ) && is_numeric( $matches['tweet'] ) ) {
$id = $matches['tweet'];
}

if ( ! $id ) {
return '';
}

return $this->shortcode( [ 'tweet' => $id ] );
}

/**
* Render oEmbed for a timeline.
*
Expand Down
54 changes: 19 additions & 35 deletions includes/embeds/class-amp-vimeo-embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@
*/
class AMP_Vimeo_Embed_Handler extends AMP_Base_Embed_Handler {

/**
* The embed URL pattern.
*
* @var string
*/
const URL_PATTERN = '#https?:\/\/(www\.)?vimeo\.com\/.*#i';

/**
* The aspect ratio.
*
* @var float
*/
const RATIO = 0.5625;

/**
Expand Down Expand Up @@ -50,7 +60,6 @@ public function __construct( $args = [] ) {
*/
public function register_embed() {
wp_embed_register_handler( 'amp-vimeo', self::URL_PATTERN, [ $this, 'oembed' ], -1 );
add_shortcode( 'vimeo', [ $this, 'shortcode' ] );
add_filter( 'wp_video_shortcode_override', [ $this, 'video_override' ], 10, 2 );
}

Expand All @@ -59,37 +68,6 @@ public function register_embed() {
*/
public function unregister_embed() {
wp_embed_unregister_handler( 'amp-vimeo', -1 );
remove_shortcode( 'vimeo' );
}

/**
* Gets AMP-compliant markup for the Vimeo shortcode.
*
* @param array $attr The Vimeo attributes.
* @return string Vimeo shortcode markup.
*/
public function shortcode( $attr ) {
$video_id = false;

if ( isset( $attr['id'] ) ) {
$video_id = $attr['id'];
} elseif ( isset( $attr['url'] ) ) {
$video_id = $this->get_video_id_from_url( $attr['url'] );
} elseif ( isset( $attr[0] ) ) {
$video_id = $this->get_video_id_from_url( $attr[0] );
} elseif ( function_exists( 'shortcode_new_to_old_params' ) ) {
$video_id = shortcode_new_to_old_params( $attr );
}

if ( empty( $video_id ) ) {
return '';
}

return $this->render(
[
'video_id' => $video_id,
]
);
}

/**
Expand Down Expand Up @@ -186,10 +164,16 @@ public function video_override( $html, $attr ) {
}
$src = $attr['src'];
$vimeo_pattern = '#^https?://(.+\.)?vimeo\.com/.*#';
if ( 1 === preg_match( $vimeo_pattern, $src ) ) {
return $this->shortcode( [ $src ] );
if ( 1 !== preg_match( $vimeo_pattern, $src ) ) {
return $html;
}
return $html;

$video_id = $this->get_video_id_from_url( $src );
if ( empty( $video_id ) ) {
return '';
}

return $this->render( compact( 'video_id' ) );
}

}
Loading