From bd021057f19d340204bc5c6a0eb1c811f6565567 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Wed, 30 Jun 2021 12:29:45 +0100 Subject: [PATCH 1/6] Cleanup --- php/class-media.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/class-media.php b/php/class-media.php index 85971e9a9..020db038f 100644 --- a/php/class-media.php +++ b/php/class-media.php @@ -955,7 +955,7 @@ public function default_image_freeform_transformations( $default ) { * @return string The converted URL. */ public function cloudinary_url( $attachment_id, $size = array(), $transformations = array(), $cloudinary_id = null, $overwrite_transformations = false ) { - if ( ! ( $cloudinary_id ) ) { + if ( ! $cloudinary_id ) { $cloudinary_id = $this->cloudinary_id( $attachment_id ); if ( ! $cloudinary_id ) { return null; From f1d56121e158f6479f3a55ac2929dbcbb476f442 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Wed, 30 Jun 2021 12:30:35 +0100 Subject: [PATCH 2/6] Improve output consistency --- php/class-media.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/php/class-media.php b/php/class-media.php index 020db038f..76015c6a6 100644 --- a/php/class-media.php +++ b/php/class-media.php @@ -1159,7 +1159,7 @@ public function get_cloudinary_id( $attachment_id ) { * * @param int $attachment_id The ID to get Cloudinary id for. * - * @return string|false the ID or null if not existing. + * @return string|false the ID or false if not existing. */ public function cloudinary_id( $attachment_id ) { static $cloudinary_ids = array(); @@ -1170,8 +1170,8 @@ public function cloudinary_id( $attachment_id ) { } if ( ! $this->is_media( $attachment_id ) ) { - $cloudinary_ids[ $attachment_id ] = null; - return null; + $cloudinary_ids[ $attachment_id ] = false; + return false; } if ( ! $this->sync->is_synced( $attachment_id ) && ! defined( 'REST_REQUEST' ) ) { From c714cb09c75722eb8aead5497046f645f1041002 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Wed, 30 Jun 2021 12:31:26 +0100 Subject: [PATCH 3/6] Default get meta to null --- php/class-media.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/class-media.php b/php/class-media.php index 76015c6a6..8304a7076 100644 --- a/php/class-media.php +++ b/php/class-media.php @@ -1857,7 +1857,7 @@ public function get_post_meta( $post_id, $key = '', $single = false ) { } } if ( '' !== $key ) { - $meta = isset( $meta[ $key ] ) ? $meta[ $key ] : ''; + $meta = isset( $meta[ $key ] ) ? $meta[ $key ] : null; } return $single ? $meta : (array) $meta; From 9f59afc560ba8e674b5cd07bc27a3e37799ee5d1 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Wed, 30 Jun 2021 12:32:00 +0100 Subject: [PATCH 4/6] Get single key for delivery type --- php/class-sync.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/class-sync.php b/php/class-sync.php index a8dadfe19..63589bb54 100644 --- a/php/class-sync.php +++ b/php/class-sync.php @@ -499,7 +499,7 @@ public function setup_sync_base_struct() { 'priority' => 25, 'sync' => array( $this->managers['upload'], 'explicit_update' ), 'validate' => function ( $attachment_id ) { - $delivery = $this->managers['media']->get_post_meta( $attachment_id, self::META_KEYS['delivery'] ); + $delivery = $this->managers['media']->get_post_meta( $attachment_id, self::META_KEYS['delivery'], true ); return empty( $delivery ) || 'upload' === $delivery; }, From 23ab2c0f71e652eb8843d360095546c3b496a331 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Wed, 30 Jun 2021 12:32:35 +0100 Subject: [PATCH 5/6] Change the source of information into the newly added Cloudinary meta key --- php/class-report.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/php/class-report.php b/php/class-report.php index fe7beb66e..b9de63d41 100644 --- a/php/class-report.php +++ b/php/class-report.php @@ -163,7 +163,8 @@ public function image_meta_viewer() { */ public function render( $post ) { if ( 'attachment' === $post->post_type ) { - $meta = wp_get_attachment_metadata( $post->ID ); + $sync = $this->plugin->get_component( 'sync' ); + $meta = get_post_meta( $post->ID, $sync::META_KEYS['cloudinary'], true ); $args = array( 'type' => 'tag', From fca6001572c136bcc6f002e0006b15500ba654e2 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Wed, 30 Jun 2021 12:33:06 +0100 Subject: [PATCH 6/6] Use plugin internal logic to check if the media is local --- php/connect/class-api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php/connect/class-api.php b/php/connect/class-api.php index 45e43b852..147412e11 100644 --- a/php/connect/class-api.php +++ b/php/connect/class-api.php @@ -396,13 +396,13 @@ function_exists( 'wp_get_original_image_url' ) && } else { $file_url = wp_get_attachment_url( $attachment_id ); } - if ( ! is_local_attachment( $attachment_id ) ) { + $media = get_plugin_instance()->get_component( 'media' ); + if ( ! $media->is_local_media( $attachment_id ) ) { $disable_https_fetch = false; // Remote can upload via url. // translators: variable is thread name and queue size. $action_message = sprintf( __( 'Uploading remote url: %1$s.', 'cloudinary' ), $file_url ); do_action( '_cloudinary_queue_action', $action_message ); } - $media = get_plugin_instance()->get_component( 'media' ); $tempfile = false; if ( $media && $media->is_cloudinary_url( $file_url ) ) { // If this is a Cloudinary URL, then we can use it to fetch from that location.