Skip to content

Commit df7894f

Browse files
authored
Merge pull request #117 from cloudinary/develop
Develop
2 parents 1e8d90f + 93dfbbd commit df7894f

File tree

8 files changed

+49
-18
lines changed

8 files changed

+49
-18
lines changed

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/cloudinary.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/src/components/_settings.scss

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@
212212
.settings-warning {
213213
display: inline-block;
214214
padding: 5px 7px;
215-
background-color: #ffea98;
216-
border-left: 4px solid #ffcc00;
217-
box-shadow: 0px 0px 5px 0px rgba(112,112,112,0.4);
215+
background-color: #e9faff;
216+
border: 1px solid #ccd0d4;
217+
border-left: 4px solid #00a0d2;
218+
box-shadow: 0 1px 1px rgba(0,0,0,.04);
218219
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,14 +685,22 @@ public function cloudinary_id( $attachment_id ) {
685685
}
686686

687687
/**
688-
* Filter the Cloudinary ID to allow extending it's availability.
688+
* Filter to validate the Cloudinary ID to allow extending it's availability.
689689
*
690690
* @param string|bool $cloudinary_id The public ID from Cloudinary, or false if not found.
691691
* @param int $attachment_id The id of the asset.
692692
*
693693
* @return string|bool
694694
*/
695-
$cloudinary_id = apply_filters( 'cloudinary_id', $cloudinary_id, $attachment_id );
695+
$cloudinary_id = apply_filters( 'validate_cloudinary_id', $cloudinary_id, $attachment_id );
696+
697+
/**
698+
* Action the Cloudinary ID to allow extending it's availability.
699+
*
700+
* @param string|bool $cloudinary_id The public ID from Cloudinary, or false if not found.
701+
* @param int $attachment_id The id of the asset.
702+
*/
703+
do_action( 'cloudinary_id', $cloudinary_id, $attachment_id );
696704
// Cache ID to prevent multiple lookups.
697705
if ( false !== $cloudinary_id ) {
698706
$this->cloudinary_ids[ $attachment_id ] = $cloudinary_id;

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-settings-page.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private function register_section( $tab_slug ) {
175175
*
176176
* @since 0.1
177177
*
178-
* @param string $tab The tab to register the section fields for.
178+
* @param array $tab The tab to register the section fields for.
179179
* @param string $setting_slug The slug of the setting to register section for.
180180
*/
181181
private function register_section_fields( $tab, $setting_slug ) {
@@ -226,8 +226,9 @@ public function render() {
226226
*
227227
* @param array $field The field to render.
228228
* @param string|null $value The value to render.
229+
* @param bool $show_description Whether to render the description.
229230
*/
230-
public function render_field( $field, $value = null ) {
231+
public function render_field( $field, $value = null, $show_description = true ) {
231232

232233
if ( null === $value ) {
233234
$value = $this->get_value( $field['slug'] );
@@ -308,7 +309,7 @@ public function render_field( $field, $value = null ) {
308309
<p class="description error-notice" id="<?php echo esc_attr( $setting_slug ); ?>-error"><?php echo wp_kses_post( $field['error_notice'] ); ?></p>
309310
<?php
310311
}
311-
if ( ! empty( $field['description'] ) ) {
312+
if ( ! empty( $field['description'] ) && $show_description ) {
312313
?>
313314
<p class="description" id="<?php echo esc_attr( $setting_slug ); ?>-description"><?php echo wp_kses_post( $field['description'] ); ?></p>
314315
<?php

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-upgrade.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,23 @@ class Upgrade {
2525
*/
2626
private $media;
2727

28+
/**
29+
* Holds the Sync instance.
30+
*
31+
* @since 0.1
32+
*
33+
* @var \Cloudinary\Sync Instance of the plugin.
34+
*/
35+
private $sync;
36+
2837
/**
2938
* Filter constructor.
3039
*
3140
* @param \Cloudinary\Media $media The plugin.
3241
*/
3342
public function __construct( \Cloudinary\Media $media ) {
3443
$this->media = $media;
44+
$this->sync = $media->plugin->components['sync'];
3545
$this->setup_hooks();
3646
}
3747

@@ -44,6 +54,7 @@ public function __construct( \Cloudinary\Media $media ) {
4454
* @return string|bool
4555
*/
4656
public function check_cloudinary_version( $cloudinary_id, $attachment_id ) {
57+
4758
if ( false === $cloudinary_id ) {
4859
// Backwards compat.
4960
$meta = wp_get_attachment_metadata( $attachment_id );
@@ -128,6 +139,9 @@ function ( $val ) use ( $media ) {
128139
$path = pathinfo( $public_id );
129140
$public_id = strstr( $public_id, '.' . $path['extension'], true );
130141
$this->media->update_post_meta( $attachment_id, Sync::META_KEYS['public_id'], $public_id );
142+
if ( ! defined( 'DOING_BULK_SYNC' ) ) {
143+
$this->sync->managers['upload']->add_to_sync( $attachment_id ); // Auto sync if upgrading outside of bulk sync.
144+
}
131145

132146
return $public_id;
133147
}
@@ -136,7 +150,7 @@ function ( $val ) use ( $media ) {
136150
* Setup hooks for the filters.
137151
*/
138152
public function setup_hooks() {
139-
add_filter( 'cloudinary_id', array( $this, 'check_cloudinary_version' ), 10, 2 ); // Priority 10, to allow prep_on_demand_upload.
153+
add_filter( 'validate_cloudinary_id', array( $this, 'check_cloudinary_version' ), 10, 2 ); // Priority 10, to allow prep_on_demand_upload.
140154

141155
// Add a redirection to the new plugin settings, from the old plugin.
142156
if ( is_admin() ) {

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ public function rest_push_attachments( \WP_REST_Request $request ) {
231231
public function resume_queue() {
232232
// Check if there is a Cloudinary ID in case this was synced on-demand before being processed by the queue.
233233
add_filter( 'cloudinary_on_demand_sync_enabled', '__return_false' ); // Disable the on-demand sync since we want the status.
234-
add_filter( 'cloudinary_id', '__return_false' ); // Disable the on-demand sync since we want the status.
234+
define( 'DOING_BULK_SYNC', true ); // Define bulk sync in action.
235235

236-
if ( false === $this->plugin->components['media']->cloudinary_id( $this->post_id ) ) {
236+
if ( ! $this->plugin->components['sync']->is_synced( $this->post_id ) ) {
237237
$stat = $this->push_attachments( array( $this->post_id ) );
238238
if ( ! empty( $stat['processed'] ) ) {
239239
$result = 'done';
@@ -357,6 +357,7 @@ public function prepare_upload( $post, $down_sync = false ) {
357357
// First check if this has a file and it can be uploaded.
358358
$file = get_attached_file( $post->ID );
359359
$file_size = 0;
360+
$downsync = false;
360361
if ( empty( $file ) ) {
361362
return new \WP_Error( 'attachment_no_file', __( 'Attachment did not have a file.', 'cloudinary' ) );
362363
} elseif ( ! file_exists( $file ) ) {
@@ -373,6 +374,7 @@ public function prepare_upload( $post, $down_sync = false ) {
373374
}
374375
$file = get_attached_file( $post->ID );
375376
$file_size = filesize( $file );
377+
$downsync = true;
376378
}
377379
}
378380
} else {
@@ -414,7 +416,7 @@ public function prepare_upload( $post, $down_sync = false ) {
414416
}
415417
// Check if this asset is a folder sync.
416418
$folder_sync = $media->get_post_meta( $post->ID, Sync::META_KEYS['folder_sync'], true );
417-
if ( ! empty( $folder_sync ) ) {
419+
if ( ! empty( $folder_sync ) && false === $downsync ) {
418420
$public_id_folder = $cld_folder; // Ensure the public ID folder is constant.
419421
} else {
420422
// Not folder synced, so set the folder to the folder that the asset originally came from.
@@ -490,7 +492,7 @@ public function prepare_upload( $post, $down_sync = false ) {
490492
$public_id = ltrim( $public_id_folder . $options['public_id'], '/' );
491493
$return = array(
492494
'file' => $file,
493-
'folder' => $cld_folder,
495+
'folder' => ltrim( $cld_folder, '/' ),
494496
'public_id' => $public_id,
495497
'breakpoints' => array(),
496498
'options' => $options,
@@ -542,7 +544,10 @@ public function push_attachments( $attachments ) {
542544
// Go over each attachment.
543545
foreach ( $attachments as $attachment ) {
544546
$attachment = get_post( $attachment );
545-
$upload = $this->prepare_upload( $attachment->ID, true );
547+
// Clear upload option cache for this item to allow down sync.
548+
$this->upload_options[ $attachment->ID ] = false;
549+
550+
$upload = $this->prepare_upload( $attachment->ID, true );
546551

547552
// Filter out any attachments with problematic options.
548553
if ( is_wp_error( $upload ) ) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public function __construct( \Cloudinary\Plugin $plugin, $enabled = false, $push
6565
private function register_hooks() {
6666
// Add action to upload.
6767
add_action( 'add_attachment', array( $this, 'push_on_upload' ), 10 );
68-
// Filter id for on-demand upload sync.
69-
add_filter( 'cloudinary_id', array( $this, 'prep_on_demand_upload' ), 9, 2 );
68+
// Action Cloudinary id for on-demand upload sync.
69+
add_action( 'cloudinary_id', array( $this, 'prep_on_demand_upload' ), 9, 2 );
7070
// Show sync status.
7171
add_filter( 'cloudinary_media_status', array( $this, 'filter_status' ), 10, 2 );
7272
// Hook for on demand upload push.

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/templates/taxonomy-transformation-fields.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
wp_enqueue_script( 'cld-player' );
99

1010
wp_add_inline_script( 'cloudinary', 'var CLD_GLOBAL_TRANSFORMATIONS = CLD_GLOBAL_TRANSFORMATIONS ? CLD_GLOBAL_TRANSFORMATIONS : {};', 'before' );
11+
$show_desc = true;
1112
?>
1213
<h2><?php esc_html_e( 'Global Transformations', 'cloudinary' ); ?></h2>
1314
<?php foreach ( $this->fields as $field_slug => $field ) : ?>
@@ -16,7 +17,8 @@
1617
<?php
1718
$field['slug'] = $field_slug;
1819
$field['label_for'] = 'field-' . $field['slug'];
19-
$this->media->plugin->components['settings']->render_field( $field );
20+
$this->media->plugin->components['settings']->render_field( $field, null, $show_desc );
21+
$show_desc = false;
2022
?>
2123
</div>
2224
<?php endforeach; ?>

0 commit comments

Comments
 (0)