From f03614fbc23bde1acb8af836bc21ac8fd54d864a Mon Sep 17 00:00:00 2001 From: David Cramer Date: Mon, 21 Jun 2021 13:47:46 +0200 Subject: [PATCH 1/4] fix filter key --- php/class-delivery.php | 2 +- php/media/class-global-transformations.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/php/class-delivery.php b/php/class-delivery.php index 47a3a315b..fde4e3d09 100644 --- a/php/class-delivery.php +++ b/php/class-delivery.php @@ -80,7 +80,7 @@ public function __construct( Plugin $plugin ) { protected function setup_hooks() { add_filter( 'cloudinary_filter_out_local', '__return_false' ); add_action( 'update_option_cloudinary_media_display', array( $this, 'clear_cache' ) ); - add_filter( 'cloudinary_post_id_taxonomy', array( $this, 'get_current_post_id' ) ); + add_filter( 'cloudinary_current_post_id', array( $this, 'get_current_post_id' ) ); add_filter( 'the_content', array( $this, 'add_post_id' ) ); } diff --git a/php/media/class-global-transformations.php b/php/media/class-global-transformations.php index 7ab36d060..e83a23e78 100644 --- a/php/media/class-global-transformations.php +++ b/php/media/class-global-transformations.php @@ -576,7 +576,7 @@ protected function get_current_post() { * * @return {WP_Post|null} */ - $post_id = apply_filters( 'cloudinary_post_id', null ); + $post_id = apply_filters( 'cloudinary_current_post_id', null ); if ( is_null( $post_id ) ) { return null; From 5be5ba9d0110577d73508d2c12ddea3b27ebc901 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Mon, 21 Jun 2021 13:48:45 +0200 Subject: [PATCH 2/4] revert return to false, return filtered null --- php/class-delivery.php | 2 +- php/media/class-filter.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/php/class-delivery.php b/php/class-delivery.php index fde4e3d09..6b5e1fe84 100644 --- a/php/class-delivery.php +++ b/php/class-delivery.php @@ -118,7 +118,7 @@ public function add_post_id( $content ) { * @return int|null */ public function get_current_post_id() { - return $this->current_post_id; + return $this->current_post_id ? $this->current_post_id : null; } /** diff --git a/php/media/class-filter.php b/php/media/class-filter.php index ab2a832c4..8af9bb830 100644 --- a/php/media/class-filter.php +++ b/php/media/class-filter.php @@ -92,10 +92,10 @@ public function get_video_shortcodes( $html ) { * * @param string $asset The media tag. * @param string $type The type. - * @return int|null + * @return int|false */ public function get_id_from_tag( $asset, $type = 'wp-image-|wp-video-' ) { - $attachment_id = null; + $attachment_id = false; // Get attachment id from class name. if ( preg_match( '#class=["|\']?[^"\']*(' . $type . ')([\d]+)[^"\']*["|\']?#i', $asset, $found ) ) { $attachment_id = intval( $found[2] ); From 2b270f7288099409abdeea21286a0e0c24de936d Mon Sep 17 00:00:00 2001 From: David Cramer Date: Mon, 21 Jun 2021 13:49:34 +0200 Subject: [PATCH 3/4] clear cache on term updates --- php/class-delivery.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/php/class-delivery.php b/php/class-delivery.php index 6b5e1fe84..ce2970d8f 100644 --- a/php/class-delivery.php +++ b/php/class-delivery.php @@ -82,6 +82,12 @@ protected function setup_hooks() { add_action( 'update_option_cloudinary_media_display', array( $this, 'clear_cache' ) ); add_filter( 'cloudinary_current_post_id', array( $this, 'get_current_post_id' ) ); add_filter( 'the_content', array( $this, 'add_post_id' ) ); + + // Clear cache on taxonomy update. + $taxonomies = get_taxonomies( array( 'show_ui' => true ) ); + foreach ( $taxonomies as $taxonomy ) { + add_action( "saved_{$taxonomy}", array( $this, 'clear_cache' ) ); + } } /** From 1091f6e965947e4f358ad543035cf9f69215f43d Mon Sep 17 00:00:00 2001 From: David Cramer Date: Mon, 21 Jun 2021 13:52:02 +0200 Subject: [PATCH 4/4] update filter doc --- php/media/class-global-transformations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/media/class-global-transformations.php b/php/media/class-global-transformations.php index e83a23e78..6d3c3d1a5 100644 --- a/php/media/class-global-transformations.php +++ b/php/media/class-global-transformations.php @@ -571,7 +571,7 @@ protected function get_current_post() { /** * Filter the post ID. * - * @hook cloudinary_post_id + * @hook cloudinary_current_post_id * @default null * * @return {WP_Post|null}