From 7def38f966aa816a32d5de17918b1b5c0450c81d Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Tue, 2 Mar 2021 23:43:18 +0000 Subject: [PATCH 1/5] Fix public_id on downsync --- php/sync/class-download-sync.php | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/php/sync/class-download-sync.php b/php/sync/class-download-sync.php index 4586e12a7..62a536c81 100644 --- a/php/sync/class-download-sync.php +++ b/php/sync/class-download-sync.php @@ -126,19 +126,18 @@ public function rest_download_asset( \WP_REST_Request $request ) { } /** - * Prepare and sync down an asset stored remotely. + * Get downloaded Public ID. * - * @param int $attachment_id The attachment ID. + * @param string $source The source URL. * - * @return array|\WP_Error + * @return string */ - public function down_sync( $attachment_id ) { - $file = get_post_meta( $attachment_id, '_wp_attached_file', true ); - $path = wp_parse_url( $file, PHP_URL_PATH ); + public function get_public_id( $source ) { + $path = wp_parse_url( $source, PHP_URL_PATH ); $media = $this->plugin->components['media']; $parts = explode( '/', $path ); $parts = array_map( - function ( $val ) use ( $media ) { + static function ( $val ) use ( $media ) { if ( empty( $val ) ) { return false; } @@ -152,7 +151,7 @@ function ( $val ) use ( $media ) { if ( ! empty( $transformation_maybe ) ) { return false; } - if ( substr( $val, 0, 1 ) === 'v' && is_numeric( substr( $val, 1 ) ) ) { + if ( 'v' === $val[0] && is_numeric( substr( $val, 1 ) ) ) { return false; } @@ -166,20 +165,8 @@ function ( $val ) use ( $media ) { // Remove extension. $path = pathinfo( $public_id ); $public_id = strstr( $public_id, '.' . $path['extension'], true ); - // Save public ID. - $media->update_post_meta( $attachment_id, Sync::META_KEYS['public_id'], $public_id ); - // Check if the asset is in the same folder as the defined Cloudinary folder. - if ( false !== strpos( $public_id, '/' ) ) { - $path = pathinfo( $public_id ); - $asset_folder = trailingslashit( $path['dirname'] ); - $cloudinary_folder = trailingslashit( $this->plugin->settings->get_value( 'cloudinary_folder' ) ); - if ( $asset_folder === $cloudinary_folder ) { - // The asset folder matches the defined cloudinary folder, flag it as being in a folder sync. - $media->update_post_meta( $attachment_id, Sync::META_KEYS['folder_sync'], true ); - } - } - return $this->download_asset( $attachment_id, $file ); + return $public_id; } /** @@ -247,7 +234,7 @@ public function download_asset( $attachment_id, $source = null, $date = null ) { } wp_update_attachment_metadata( $attachment_id, $meta ); // Update the folder synced flag. - $public_id = $this->media->get_public_id( $attachment_id ); + $public_id = $this->get_public_id( $source ); $asset_folder = strpos( $public_id, '/' ) ? dirname( $public_id ) : '/'; $cloudinary_folder = untrailingslashit( $this->media->get_cloudinary_folder() ); if ( $asset_folder === $cloudinary_folder ) { From 4306bf1ba10ade96f9a07ce9db1124816fc03cbe Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Thu, 4 Mar 2021 00:26:55 +0000 Subject: [PATCH 2/5] Sometimes, the public_id is already set on downsync --- php/sync/class-download-sync.php | 75 +++++++++++++++++--------------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/php/sync/class-download-sync.php b/php/sync/class-download-sync.php index 62a536c81..72976966e 100644 --- a/php/sync/class-download-sync.php +++ b/php/sync/class-download-sync.php @@ -128,43 +128,48 @@ public function rest_download_asset( \WP_REST_Request $request ) { /** * Get downloaded Public ID. * - * @param string $source The source URL. + * @param int $attachment_id The attachment ID. + * @param string $source The source URL. * * @return string */ - public function get_public_id( $source ) { - $path = wp_parse_url( $source, PHP_URL_PATH ); - $media = $this->plugin->components['media']; - $parts = explode( '/', $path ); - $parts = array_map( - static function ( $val ) use ( $media ) { - if ( empty( $val ) ) { - return false; - } - if ( $val === $media->credentials['cloud_name'] ) { - return false; - } - if ( in_array( $val, array( 'image', 'video', 'upload' ), true ) ) { - return false; - } - $transformation_maybe = $media->get_transformations_from_string( $val ); - if ( ! empty( $transformation_maybe ) ) { - return false; - } - if ( 'v' === $val[0] && is_numeric( substr( $val, 1 ) ) ) { - return false; - } - - return $val; - }, - $parts - ); - // Build public_id. - $parts = array_filter( $parts ); - $public_id = implode( '/', $parts ); - // Remove extension. - $path = pathinfo( $public_id ); - $public_id = strstr( $public_id, '.' . $path['extension'], true ); + public function get_public_id( $attachment_id, $source ) { + $public_id = $this->media->get_post_meta( $attachment_id, Sync::META_KEYS['public_id'], true ); + + if ( empty( $public_id ) ) { + $path = wp_parse_url( $source, PHP_URL_PATH ); + $media = $this->plugin->components['media']; + $parts = explode( '/', $path ); + $parts = array_map( + static function ( $val ) use ( $media ) { + if ( empty( $val ) ) { + return false; + } + if ( $val === $media->credentials['cloud_name'] ) { + return false; + } + if ( in_array( $val, array( 'image', 'video', 'upload' ), true ) ) { + return false; + } + $transformation_maybe = $media->get_transformations_from_string( $val ); + if ( ! empty( $transformation_maybe ) ) { + return false; + } + if ( 'v' === $val[0] && is_numeric( substr( $val, 1 ) ) ) { + return false; + } + + return $val; + }, + $parts + ); + // Build public_id. + $parts = array_filter( $parts ); + $public_id = implode( '/', $parts ); + // Remove extension. + $path = pathinfo( $public_id ); + $public_id = strstr( $public_id, '.' . $path['extension'], true ); + } return $public_id; } @@ -234,7 +239,7 @@ public function download_asset( $attachment_id, $source = null, $date = null ) { } wp_update_attachment_metadata( $attachment_id, $meta ); // Update the folder synced flag. - $public_id = $this->get_public_id( $source ); + $public_id = $this->get_public_id( $attachment_id, $source ); $asset_folder = strpos( $public_id, '/' ) ? dirname( $public_id ) : '/'; $cloudinary_folder = untrailingslashit( $this->media->get_cloudinary_folder() ); if ( $asset_folder === $cloudinary_folder ) { From 324e1731e4a07a66570aae03db9edd536f98a71b Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Thu, 4 Mar 2021 00:27:29 +0000 Subject: [PATCH 3/5] Fix missing variables --- php/sync/class-push-sync.php | 1 + php/sync/class-sync-queue.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/php/sync/class-push-sync.php b/php/sync/class-push-sync.php index 8c03c429e..792882af7 100644 --- a/php/sync/class-push-sync.php +++ b/php/sync/class-push-sync.php @@ -213,6 +213,7 @@ public function process_assets( $attachments = array() ) { } // Flag attachment as being processed. update_post_meta( $attachment_id, Sync::META_KEYS['syncing'], time() ); + $stat[ $attachment_id ] = array(); while ( $type = $this->sync->get_sync_type( $attachment_id, false ) ) { // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition if ( isset( $stat[ $attachment_id ][ $type ] ) ) { // Loop prevention. diff --git a/php/sync/class-sync-queue.php b/php/sync/class-sync-queue.php index f751bc370..91b887a9e 100644 --- a/php/sync/class-sync-queue.php +++ b/php/sync/class-sync-queue.php @@ -312,13 +312,13 @@ public function build_queue() { ); // translators: variable is page number. - $action_message = sprintf( __( 'Building Queue.', 'cloudinary' ), $args['paged'] ); + $action_message = __( 'Building Queue.', 'cloudinary' ); do_action( '_cloudinary_queue_action', $action_message ); $query = new \WP_Query( $args ); if ( ! $query->have_posts() ) { // translators: variable is page number. - $action_message = sprintf( __( 'No posts', 'cloudinary' ), $args['paged'] ); + $action_message = __( 'No posts', 'cloudinary' ); do_action( '_cloudinary_queue_action', $action_message ); return; From b6a99b4eadbc0fd96ed863ee6496440e128d019f Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Thu, 4 Mar 2021 00:28:25 +0000 Subject: [PATCH 4/5] Improve delete attachment files. Sometimes those are not images and are missing the file key --- php/sync/class-storage.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/php/sync/class-storage.php b/php/sync/class-storage.php index 47ff25150..76dc82691 100644 --- a/php/sync/class-storage.php +++ b/php/sync/class-storage.php @@ -242,12 +242,21 @@ public function sync( $attachment_id ) { protected function remove_local_assets( $attachment_id ) { // Delete local versions of images. $meta = wp_get_attachment_metadata( $attachment_id ); + $backup_sizes = ''; if ( ! empty( $meta['backup_sizes'] ) ) { // Replace backup sizes. $meta['sizes'] = $meta['backup_sizes']; } - return wp_delete_attachment_files( $attachment_id, $meta, array(), get_attached_file( $attachment_id ) ); + if ( ! empty( $meta['sizes'] ) ) { + $backup_sizes = $meta['sizes']; + } + + if ( empty( $meta['file'] ) ) { + $meta['file'] = get_the_guid( $attachment_id ); + } + + return wp_delete_attachment_files( $attachment_id, $meta, $backup_sizes, get_attached_file( $attachment_id ) ); } /** From a01c88ce42a8f468a37df78a80b5ad17a83c66e5 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Thu, 4 Mar 2021 14:40:42 +0200 Subject: [PATCH 5/5] Refactor cleanup of metadata and public_id storage. --- php/class-media.php | 34 ++++++++++---------- php/class-sync.php | 49 +++++++++++++++++++++++------ php/media/class-upgrade.php | 2 +- php/sync/class-download-sync.php | 54 ++------------------------------ php/sync/class-storage.php | 4 +-- 5 files changed, 61 insertions(+), 82 deletions(-) diff --git a/php/class-media.php b/php/class-media.php index 2e927358d..1d5973bc1 100644 --- a/php/class-media.php +++ b/php/class-media.php @@ -1092,7 +1092,7 @@ public function get_cloudinary_folder( $add_trailing_slash = true ) { public function get_public_id( $attachment_id, $suffixed = false ) { // Check for a public_id. if ( $this->has_public_id( $attachment_id ) ) { - $public_id = $this->get_post_meta( $attachment_id, Sync::META_KEYS['public_id'], true ); + $public_id = get_post_meta( $attachment_id, Sync::META_KEYS['public_id'], true ); if ( $this->is_folder_synced( $attachment_id ) ) { $public_id = $this->get_cloudinary_folder() . pathinfo( $public_id, PATHINFO_BASENAME ); } @@ -1114,7 +1114,7 @@ public function get_public_id( $attachment_id, $suffixed = false ) { * @return bool */ public function has_public_id( $attachment_id ) { - return ! empty( $this->get_post_meta( $attachment_id, Sync::META_KEYS['public_id'], true ) ); + return ! empty( get_post_meta( $attachment_id, Sync::META_KEYS['public_id'], true ) ); } /** @@ -1129,9 +1129,8 @@ public function get_cloudinary_id( $attachment_id ) { $cloudinary_id = null; // A cloudinary_id is a public_id with a file extension. if ( $this->has_public_id( $attachment_id ) ) { - $public_id = $this->get_post_meta( $attachment_id, Sync::META_KEYS['public_id'], true ); // Since this is based on saved and not a dynamic, append a suffix. - $public_id .= $this->get_post_meta( $attachment_id, Sync::META_KEYS['suffix'], true ); + $public_id = $this->get_public_id( $attachment_id, true ); // Get the file, and use the same extension. $file = get_attached_file( $attachment_id ); // @todo: Make this use the globals, overrides, and application conversion. @@ -1443,24 +1442,24 @@ private function create_attachment( $asset, $public_id ) { $sync_key = $asset['sync_key']; // Capture public_id. Use core update_post_meta since this attachment data doesnt exist yet. - update_post_meta( $attachment_id, Sync::META_KEYS['public_id'], $public_id ); + $this->update_post_meta( $attachment_id, Sync::META_KEYS['public_id'], $public_id ); // Capture version number. - update_post_meta( $attachment_id, Sync::META_KEYS['version'], $asset['version'] ); + $this->update_post_meta( $attachment_id, Sync::META_KEYS['version'], $asset['version'] ); if ( ! empty( $asset['transformations'] ) ) { // Save a combined key. $sync_key .= wp_json_encode( $asset['transformations'] ); - update_post_meta( $attachment_id, Sync::META_KEYS['transformation'], $asset['transformations'] ); + $this->update_post_meta( $attachment_id, Sync::META_KEYS['transformation'], $asset['transformations'] ); } // create a trackable key in post meta. update_post_meta( $attachment_id, '_' . md5( $sync_key ), true ); // record a base to ensure primary isn't deleted. update_post_meta( $attachment_id, '_' . md5( 'base_' . $public_id ), true ); // capture the delivery type. - update_post_meta( $attachment_id, Sync::META_KEYS['delivery'], $asset['type'] ); + $this->update_post_meta( $attachment_id, Sync::META_KEYS['delivery'], $asset['type'] ); // Capture the ALT Text. if ( ! empty( $asset['meta']['alt'] ) ) { $alt_text = wp_strip_all_tags( $asset['meta']['alt'] ); - update_post_meta( $attachment_id, '_wp_attachment_image_alt', $alt_text ); + $this->update_post_meta( $attachment_id, '_wp_attachment_image_alt', $alt_text ); } return $attachment_id; @@ -1775,13 +1774,13 @@ public function get_transformation_from_meta( $post_id ) { /** * Get Cloudinary related Post meta. * - * @param int $post_id The attachment ID. - * @param string $key The meta key to get. - * @param bool $single If single or not. + * @param int $post_id The attachment ID. + * @param string|null $key The meta key to get. + * @param bool $single If single or not. * * @return mixed */ - public function get_post_meta( $post_id, $key, $single = false ) { + public function get_post_meta( $post_id, $key = null, $single = false ) { $meta_data = wp_get_attachment_metadata( $post_id, true ); if ( ! is_array( $meta_data ) ) { @@ -1790,7 +1789,10 @@ public function get_post_meta( $post_id, $key, $single = false ) { if ( ! isset( $meta_data[ Sync::META_KEYS['cloudinary'] ] ) ) { $meta_data[ Sync::META_KEYS['cloudinary'] ] = array(); } - if ( ! empty( $meta_data[ Sync::META_KEYS['cloudinary'] ][ $key ] ) ) { + + if ( null === $key ) { + $data = $meta_data[ Sync::META_KEYS['cloudinary'] ]; + } elseif ( ! empty( $meta_data[ Sync::META_KEYS['cloudinary'] ][ $key ] ) ) { $data = $meta_data[ Sync::META_KEYS['cloudinary'] ][ $key ]; } else { $data = $this->build_cached_meta( $post_id, $key, $single ); @@ -1812,8 +1814,6 @@ public function build_cached_meta( $post_id, $key, $single ) { $data = get_post_meta( $post_id, $key, $single ); if ( '' !== $data ) { $this->update_post_meta( $post_id, $key, $data ); - // Remove the low level meta. - delete_post_meta( $post_id, $key ); } return $data; @@ -1853,8 +1853,6 @@ public function delete_post_meta( $post_id, $key ) { unset( $meta_data[ Sync::META_KEYS['cloudinary'] ][ $key ] ); wp_update_attachment_metadata( $post_id, $meta_data ); } - // Delete meta data. - delete_post_meta( $post_id, $key ); } /** diff --git a/php/class-sync.php b/php/class-sync.php index d8ccf3578..24120df6b 100644 --- a/php/class-sync.php +++ b/php/class-sync.php @@ -377,7 +377,7 @@ public function register_sync_type( $type, $structure ) { public function setup_sync_base_struct() { $base_struct = array( - 'upgrade' => array( + 'upgrade' => array( 'generate' => array( $this, 'get_sync_version' ), // Method to generate a signature. 'validate' => array( $this, 'been_synced' ), 'priority' => 0, @@ -386,7 +386,7 @@ public function setup_sync_base_struct() { 'note' => __( 'Upgrading from previous version', 'cloudinary' ), 'realtime' => true, ), - 'download' => array( + 'download' => array( 'generate' => '__return_false', 'validate' => function ( $attachment_id ) { $file = get_attached_file( $attachment_id ); @@ -398,7 +398,7 @@ public function setup_sync_base_struct() { 'state' => 'info downloading', 'note' => __( 'Downloading from Cloudinary', 'cloudinary' ), ), - 'file' => array( + 'file' => array( 'generate' => array( $this, 'generate_file_signature' ), 'priority' => 5.1, 'sync' => array( $this->managers['upload'], 'upload_asset' ), @@ -409,7 +409,7 @@ public function setup_sync_base_struct() { 'note' => __( 'Uploading to Cloudinary', 'cloudinary' ), 'required' => true, // Required to complete URL render flag. ), - 'folder' => array( + 'folder' => array( 'generate' => array( $this->managers['media'], 'get_cloudinary_folder' ), 'validate' => array( $this->managers['media'], 'is_folder_synced' ), 'priority' => 10, @@ -424,7 +424,7 @@ public function setup_sync_base_struct() { }, 'required' => true, // Required to complete URL render flag. ), - 'public_id' => array( + 'public_id' => array( 'generate' => array( $this->managers['media'], 'get_public_id' ), 'validate' => function ( $attachment_id ) { $public_id = $this->managers['media']->has_public_id( $attachment_id ); @@ -437,7 +437,7 @@ public function setup_sync_base_struct() { 'note' => __( 'Updating metadata', 'cloudinary' ), 'required' => true, ), - 'breakpoints' => array( + 'breakpoints' => array( 'generate' => array( $this->managers['media'], 'get_breakpoint_options' ), 'priority' => 25, 'sync' => array( $this->managers['upload'], 'explicit_update' ), @@ -449,14 +449,14 @@ public function setup_sync_base_struct() { 'state' => 'info syncing', 'note' => __( 'Updating breakpoints', 'cloudinary' ), ), - 'options' => array( + 'options' => array( 'generate' => array( $this->managers['media'], 'get_upload_options' ), 'priority' => 30, 'sync' => array( $this->managers['upload'], 'context_update' ), 'state' => 'info syncing', 'note' => __( 'Updating metadata', 'cloudinary' ), ), - 'cloud_name' => array( + 'cloud_name' => array( 'generate' => array( $this->managers['connect'], 'get_cloud_name' ), 'priority' => 5.5, 'sync' => array( $this->managers['upload'], 'upload_asset' ), @@ -464,6 +464,34 @@ public function setup_sync_base_struct() { 'note' => __( 'Uploading to new cloud name.', 'cloudinary' ), 'required' => true, ), + 'meta_cleanup' => array( + 'generate' => function ( $attachment_id ) { + $meta = $this->managers['media']->get_post_meta( $attachment_id ); + $return = false; + foreach ( $meta as $key => $value ) { + if ( get_post_meta( $attachment_id, $key, true ) === $value ) { + $return = true; + break; + } + } + + return $return; + }, + 'priority' => 100, // Always be the highest. + 'sync' => function ( $attachment_id ) { + $meta = $this->managers['media']->get_post_meta( $attachment_id ); + foreach ( $meta as $key => $value ) { + if ( self::META_KEYS['public_id'] === $key ) { + $this->managers['media']->delete_post_meta( $attachment_id, $key ); + continue; + } + delete_post_meta( $attachment_id, $key, $value ); + } + $this->set_signature_item( $attachment_id, 'meta_cleanup' ); + }, + 'required' => true, + 'realtime' => true, + ), ); /** @@ -909,7 +937,10 @@ public function settings() { array( 'type' => 'radio', 'title' => __( 'Sync method', 'cloudinary' ), - 'tooltip_text' => __( 'Auto sync: Ensures that all of your WordPress assets are automatically synced with Cloudinary when they are added to the WordPress Media Library. Manual sync: Assets must be synced manually using the WordPress Media Library', 'cloudinary' ), + 'tooltip_text' => __( + 'Auto sync: Ensures that all of your WordPress assets are automatically synced with Cloudinary when they are added to the WordPress Media Library. Manual sync: Assets must be synced manually using the WordPress Media Library', + 'cloudinary' + ), 'slug' => 'auto_sync', 'no_cached' => true, 'default' => 'on', diff --git a/php/media/class-upgrade.php b/php/media/class-upgrade.php index e132dcca9..851b01bb1 100644 --- a/php/media/class-upgrade.php +++ b/php/media/class-upgrade.php @@ -109,7 +109,7 @@ public function convert_cloudinary_version( $attachment_id ) { $public_id = $this->media->get_public_id( $attachment_id, true ); // Check folder sync in order. if ( $this->media->is_folder_synced( $attachment_id ) ) { - $public_id_folder = ltrim( dirname( $this->media->get_post_meta( $attachment_id, Sync::META_KEYS['public_id'], true ) ), '.' ); + $public_id_folder = ltrim( dirname( $this->media->get_public_id( $attachment_id ) ) ); $test_signature = md5( false ); $folder_signature = md5( $public_id_folder ); $signature = $this->sync->get_signature( $attachment_id ); diff --git a/php/sync/class-download-sync.php b/php/sync/class-download-sync.php index 72976966e..932e0e5d9 100644 --- a/php/sync/class-download-sync.php +++ b/php/sync/class-download-sync.php @@ -125,55 +125,6 @@ public function rest_download_asset( \WP_REST_Request $request ) { return rest_ensure_response( $response ); } - /** - * Get downloaded Public ID. - * - * @param int $attachment_id The attachment ID. - * @param string $source The source URL. - * - * @return string - */ - public function get_public_id( $attachment_id, $source ) { - $public_id = $this->media->get_post_meta( $attachment_id, Sync::META_KEYS['public_id'], true ); - - if ( empty( $public_id ) ) { - $path = wp_parse_url( $source, PHP_URL_PATH ); - $media = $this->plugin->components['media']; - $parts = explode( '/', $path ); - $parts = array_map( - static function ( $val ) use ( $media ) { - if ( empty( $val ) ) { - return false; - } - if ( $val === $media->credentials['cloud_name'] ) { - return false; - } - if ( in_array( $val, array( 'image', 'video', 'upload' ), true ) ) { - return false; - } - $transformation_maybe = $media->get_transformations_from_string( $val ); - if ( ! empty( $transformation_maybe ) ) { - return false; - } - if ( 'v' === $val[0] && is_numeric( substr( $val, 1 ) ) ) { - return false; - } - - return $val; - }, - $parts - ); - // Build public_id. - $parts = array_filter( $parts ); - $public_id = implode( '/', $parts ); - // Remove extension. - $path = pathinfo( $public_id ); - $public_id = strstr( $public_id, '.' . $path['extension'], true ); - } - - return $public_id; - } - /** * Download an attachment source to the file system. * @@ -239,14 +190,13 @@ public function download_asset( $attachment_id, $source = null, $date = null ) { } wp_update_attachment_metadata( $attachment_id, $meta ); // Update the folder synced flag. - $public_id = $this->get_public_id( $attachment_id, $source ); + $public_id = $this->media->get_public_id( $attachment_id ); $asset_folder = strpos( $public_id, '/' ) ? dirname( $public_id ) : '/'; $cloudinary_folder = untrailingslashit( $this->media->get_cloudinary_folder() ); if ( $asset_folder === $cloudinary_folder ) { $this->media->update_post_meta( $attachment_id, Sync::META_KEYS['folder_sync'], true ); } - // Create synced post meta as a way to search for synced / unsynced items. - update_post_meta( $attachment_id, Sync::META_KEYS['public_id'], $public_id ); + // Generate signatures. $this->sync->set_signature_item( $attachment_id, 'options' ); $this->sync->set_signature_item( $attachment_id, 'cloud_name' ); diff --git a/php/sync/class-storage.php b/php/sync/class-storage.php index 76dc82691..83cdf9059 100644 --- a/php/sync/class-storage.php +++ b/php/sync/class-storage.php @@ -170,7 +170,7 @@ public function generate_signature( $attachment_id ) { } } - return $this->settings['offload'] . $this->media->get_post_meta( $attachment_id, Sync::META_KEYS['public_id'], true ) . $file_exists; + return $this->settings['offload'] . $this->media->get_public_id( $attachment_id ) . $file_exists; } /** @@ -241,7 +241,7 @@ public function sync( $attachment_id ) { */ protected function remove_local_assets( $attachment_id ) { // Delete local versions of images. - $meta = wp_get_attachment_metadata( $attachment_id ); + $meta = wp_get_attachment_metadata( $attachment_id ); $backup_sizes = ''; if ( ! empty( $meta['backup_sizes'] ) ) { // Replace backup sizes.