Skip to content

Commit f7f3667

Browse files
authored
Merge pull request #348 from cloudinary/fix/ws-broken-videos
Exclude AMP pages from Cloudinary URL removal when saving
2 parents 6014ebb + 7dcf9b9 commit f7f3667

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Cloudinary\Media;
99

1010
use Cloudinary\Connect\Api;
11+
use Cloudinary\Utils;
1112

1213
/**
1314
* Class Filter.
@@ -243,6 +244,10 @@ public function filter_video_shortcodes( $content ) {
243244
* @return array
244245
*/
245246
public function filter_out_cloudinary( $data ) {
247+
// Check whether this page is powered by AMP or is a web story. Bail if that's the case.
248+
if ( Utils::is_webstory_post_type( $data['post_type'] ) || Utils::is_amp( $data['post_content'] ) ) {
249+
return $data;
250+
}
246251

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

phpcs.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
</properties>
2222
</rule>
2323

24+
<rule ref="Generic.Commenting.DocComment.LongNotCapital">
25+
<exclude-pattern>php/class-cli.php</exclude-pattern>
26+
</rule>
27+
2428
<!-- Include WP VIP coding standard checks -->
2529
<rule ref="WordPress-VIP-Go" />
2630
<rule ref="WordPressVIPMinimum" />

0 commit comments

Comments
 (0)