Skip to content

Commit b1a50cd

Browse files
committed
Handle post (any type) on-save and don't filter out cld urls if dealing with amp
1 parent 94e2f8e commit b1a50cd

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

php/class-cli.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct( $plugin ) {
6161
* Syncs assets with Cloudinary.
6262
* ## EXAMPLES
6363
*
64-
* wp cloudinary sync
64+
* Wp cloudinary sync
6565
*
6666
* @when after_wp_load
6767
* @since 2.5.1
@@ -102,7 +102,7 @@ public function sync( $args, $assoc_args ) {
102102
* Analyze assets with Cloudinary.
103103
* ## EXAMPLES
104104
*
105-
* wp cloudinary analyze
105+
* Wp cloudinary analyze
106106
*
107107
* @when after_wp_load
108108
* @since 2.5.1

php/class-utils.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Cloudinary;
99

1010
use Cloudinary\Settings\Setting;
11+
use Google\Web_Stories\Story_Post_Type;
1112

1213
/**
1314
* Class that includes utility methods.
@@ -81,4 +82,27 @@ public static function expand_dot_notation( array $input, $separator = '.' ) {
8182

8283
return $result;
8384
}
85+
86+
/**
87+
* Check whether the inputted HTML string is powered by AMP.
88+
* Reference on how to detect an AMP page: https://amp.dev/documentation/guides-and-tutorials/learn/spec/amphtml/?format=websites#ampd.
89+
*
90+
* @param string $html_string The HTML string to check.
91+
*
92+
* @return bool
93+
*/
94+
public static function is_amp( $html_string ) {
95+
return strpos( $html_string, '<html amp' ) !== false || strpos( $html_string, '<html ⚡' ) !== false;
96+
}
97+
98+
/**
99+
* Check whether the inputted post type is a webstory.
100+
*
101+
* @param string $post_type The post type to compare to.
102+
*
103+
* @return bool
104+
*/
105+
public static function is_webstory_post_type( $post_type ) {
106+
return class_exists( Story_Post_Type::class ) && Story_Post_Type::POST_TYPE_SLUG === $post_type;
107+
}
84108
}

php/media/class-filter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
namespace Cloudinary\Media;
99

1010
use Cloudinary\Connect\Api;
11+
use Cloudinary\Utils;
12+
use Google\Web_Stories\Story_Post_Type;
1113

1214
/**
1315
* Class Filter.
@@ -243,6 +245,10 @@ public function filter_video_shortcodes( $content ) {
243245
* @return array
244246
*/
245247
public function filter_out_cloudinary( $data ) {
248+
// Check whether this page is powered by AMP or is a web story. Bail if that's the case.
249+
if ( Utils::is_webstory_post_type( $data['post_type'] ) || Utils::is_amp( $data['post_content'] ) ) {
250+
return $data;
251+
}
246252

247253
$content = trim( wp_unslash( $data['post_content'] ) );
248254
$assets = $this->get_media_tags( $content );

php/media/class-video.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public function filter_video_shortcode( $html, $attr ) {
256256
*/
257257
public function filter_video_tags( $content ) {
258258

259-
$video_tags = $this->media->filter->get_media_tags( $content, 'video|source' );
259+
$video_tags = $this->media->filter->get_media_tags( $content, 'video' );
260260
foreach ( $video_tags as $tag ) {
261261
$args = array();
262262

@@ -282,10 +282,7 @@ public function filter_video_tags( $content ) {
282282
}
283283
$attachment_id = $this->media->filter->get_id_from_tag( $tag );
284284
if ( empty( $attachment_id ) ) {
285-
$attachment_id = attachment_url_to_postid( $url );
286-
if ( ! $attachment_id ) {
287-
continue; // Missing or no attachment ID found.
288-
}
285+
continue; // Missing or no attachment ID found.
289286
}
290287
// Enable Autoplay for this video.
291288
if ( false !== strpos( $tag, 'autoplay' ) ) {

0 commit comments

Comments
 (0)