Skip to content

Commit 735c00c

Browse files
authored
Merge pull request #112 from cloudinary/fix/ltrim-forward-slash
ltrim forward slashes on public ID
2 parents 3d3e28a + 48d84a4 commit 735c00c

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ public function prepare_upload( $post, $down_sync = false ) {
487487
}
488488

489489
// Restructure the path to the filename to allow correct placement in Cloudinary.
490-
$public_id = $public_id_folder . $options['public_id'];
490+
$public_id = ltrim( $public_id_folder . $options['public_id'], '/' );
491491
$return = array(
492492
'file' => $file,
493493
'folder' => $cld_folder,

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-sync.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private function register_hooks() {
7272
// Hook for on demand upload push.
7373
add_action( 'shutdown', array( $this, 'init_background_upload' ) );
7474
// Hook into auto upload sync.
75-
add_filter( 'cloudinary_on_demand_sync_enabled', array( $this, 'auto_sync_enabled' ) );
75+
add_filter( 'cloudinary_on_demand_sync_enabled', array( $this, 'auto_sync_enabled' ), 10, 2 );
7676
// Handle bulk and inline actions.
7777
add_filter( 'handle_bulk_actions-upload', array( $this, 'handle_bulk_actions' ), 10, 3 );
7878
// Add inline action.
@@ -160,14 +160,20 @@ public function handle_bulk_actions( $location, $action, $post_ids ) {
160160
* Check if auto-sync is enabled.
161161
*
162162
* @param bool $enabled Flag to determine if autosync is enabled.
163+
* @param int $post_id The post id currently processing.
163164
*
164165
* @return bool
165166
*/
166-
public function auto_sync_enabled( $enabled ) {
167+
public function auto_sync_enabled( $enabled, $post_id ) {
167168
if ( isset( $this->plugin->config['settings']['sync_media']['auto_sync'] ) && 'on' === $this->plugin->config['settings']['sync_media']['auto_sync'] ) {
168169
$enabled = true;
169170
}
170171

172+
// Check if it was synced before to allow re-sync for changes.
173+
if ( ! empty( $this->plugin->components['sync']->get_signature( $post_id ) ) ) {
174+
$enabled = true;
175+
}
176+
171177
return $enabled;
172178
}
173179

@@ -211,7 +217,7 @@ public function prep_on_demand_upload( $cloudinary_id, $attachment_id ) {
211217
$attachment_id = intval( $attachment_id );
212218
if ( $attachment_id && false === $cloudinary_id ) {
213219
// Check that this has not already been prepared for upload.
214-
if ( ! $this->is_pending( $attachment_id ) && apply_filters( 'cloudinary_on_demand_sync_enabled', $this->enabled ) ) {
220+
if ( ! $this->is_pending( $attachment_id ) && apply_filters( 'cloudinary_on_demand_sync_enabled', $this->enabled, $attachment_id ) ) {
215221
$max_size = ( wp_attachment_is_image( $attachment_id ) ? 'max_image_size' : 'max_video_size' );
216222
$file = get_attached_file( $attachment_id );
217223
// Get the file size to make sure it can exist in cloudinary.

0 commit comments

Comments
 (0)