Skip to content

Commit b068e09

Browse files
authored
Merge pull request #352 from cloudinary/fix/ws-broken-videos
Take care of freshly uploaded assets and make sure they sync first in AMP posts
2 parents 75238cd + 0c64ef5 commit b068e09

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

php/media/class-filter.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,23 @@ public function filter_video_shortcodes( $content ) {
236236
return $content;
237237
}
238238

239+
/**
240+
* If the post is a web story or AMP-powered, take care of the special AMP tags.
241+
*
242+
* @param array $data The post data array to save.
243+
*
244+
* @return array
245+
*/
246+
public function prepare_amp_posts( $data ) {
247+
if ( ! Utils::is_webstory_post_type( $data['post_type'] ) && ! Utils::is_amp( $data['post_content'] ) ) {
248+
return $data;
249+
}
250+
251+
$data['post_content'] = $this->filter_out_local( wp_unslash( $data['post_content'] ), 'amp-img|source' );
252+
253+
return $data;
254+
}
255+
239256
/**
240257
* Filter out Cloudinary URL when saving to the DB.
241258
*
@@ -284,12 +301,13 @@ public function filter_out_cloudinary( $data ) {
284301
* Filter content to replace local src urls with Cloudinary urls.
285302
*
286303
* @param string $content The content to filter urls.
304+
* @param string $tags The tags to look out for in the post content.
287305
*
288306
* @return string The filtered content.
289307
*/
290-
public function filter_out_local( $content ) {
308+
public function filter_out_local( $content, $tags = 'img' ) {
291309

292-
$assets = $this->get_media_tags( $content, 'img' );
310+
$assets = $this->get_media_tags( $content, $tags );
293311
foreach ( $assets as $asset ) {
294312

295313
$url = $this->get_url_from_tag( $asset );
@@ -718,6 +736,7 @@ public function init_rest_filters() {
718736
public function setup_hooks() {
719737
// Filter URLS within content.
720738
add_action( 'wp_insert_post_data', array( $this, 'filter_out_cloudinary' ) );
739+
add_action( 'wp_insert_post_data', array( $this, 'prepare_amp_posts' ), 11 );
721740
add_filter( 'wp_prepare_attachment_for_js', array( $this, 'filter_attachment_for_js' ), 11 );
722741

723742
// Add support for custom header.

0 commit comments

Comments
 (0)