Skip to content
Merged
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
23 changes: 21 additions & 2 deletions php/media/class-filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,23 @@ public function filter_video_shortcodes( $content ) {
return $content;
}

/**
* If the post is a web story or AMP-powered, take care of the special AMP tags.
*
* @param array $data The post data array to save.
*
* @return array
*/
public function prepare_amp_posts( $data ) {
if ( ! Utils::is_webstory_post_type( $data['post_type'] ) && ! Utils::is_amp( $data['post_content'] ) ) {
return $data;
}

$data['post_content'] = $this->filter_out_local( wp_unslash( $data['post_content'] ), 'amp-img|source' );

return $data;
}

/**
* Filter out Cloudinary URL when saving to the DB.
*
Expand Down Expand Up @@ -284,12 +301,13 @@ public function filter_out_cloudinary( $data ) {
* Filter content to replace local src urls with Cloudinary urls.
*
* @param string $content The content to filter urls.
* @param string $tags The tags to look out for in the post content.
*
* @return string The filtered content.
*/
public function filter_out_local( $content ) {
public function filter_out_local( $content, $tags = 'img' ) {

$assets = $this->get_media_tags( $content, 'img' );
$assets = $this->get_media_tags( $content, $tags );
foreach ( $assets as $asset ) {

$url = $this->get_url_from_tag( $asset );
Expand Down Expand Up @@ -718,6 +736,7 @@ public function init_rest_filters() {
public function setup_hooks() {
// Filter URLS within content.
add_action( 'wp_insert_post_data', array( $this, 'filter_out_cloudinary' ) );
add_action( 'wp_insert_post_data', array( $this, 'prepare_amp_posts' ), 11 );
add_filter( 'wp_prepare_attachment_for_js', array( $this, 'filter_attachment_for_js' ), 11 );

// Add support for custom header.
Expand Down