Skip to content

Commit af334ec

Browse files
authored
Merge pull request #341 from cloudinary/fix/on-off
set values on or off only
2 parents cd86e69 + 7b2c65b commit af334ec

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

php/class-media.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ public function default_image_transformations( $default ) {
773773

774774
$config = $this->settings->get_value( 'image_settings' );
775775

776-
if ( true === $config['image_optimization'] ) {
776+
if ( 'on' === $config['image_optimization'] ) {
777777
if ( 'auto' === $config['image_format'] ) {
778778
$default['fetch_format'] = 'auto';
779779
}
@@ -1145,7 +1145,7 @@ public function image_srcset( $sources, $size_array, $image_src, $image_meta, $a
11451145

11461146
$image_meta['overwrite_transformations'] = ! empty( $image_meta['overwrite_transformations'] ) ? $image_meta['overwrite_transformations'] : false;
11471147

1148-
if ( $this->settings->get_setting( 'enable_breakpoints' )->get_value() && wp_image_matches_ratio( $image_meta['width'], $image_meta['height'], $size_array[0], $size_array[1] ) ) {
1148+
if ( 'on' === $this->settings->get_setting( 'enable_breakpoints' )->get_value() && wp_image_matches_ratio( $image_meta['width'], $image_meta['height'], $size_array[0], $size_array[1] ) ) {
11491149
$meta = $this->get_post_meta( $attachment_id, Sync::META_KEYS['breakpoints'], true );
11501150
if ( ! empty( $meta ) ) {
11511151
// Since srcset is primary and src is a fallback, we need to set the first srcset with the main image.
@@ -1718,7 +1718,7 @@ public function get_breakpoint_options( $attachment_id ) {
17181718
$breakpoints = array();
17191719
$settings = $this->settings->get_setting( self::MEDIA_SETTINGS_SLUG )->get_value();
17201720

1721-
if ( ! empty( $settings['enable_breakpoints'] ) && wp_attachment_is_image( $attachment_id ) ) {
1721+
if ( 'on' === $settings['enable_breakpoints'] && wp_attachment_is_image( $attachment_id ) ) {
17221722
$meta = wp_get_attachment_metadata( $attachment_id );
17231723
// Get meta image size if non exists.
17241724
if ( empty( $meta ) ) {

php/media/class-video.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,10 @@ public function filter_video_block_pre_render( $block, $source_block ) {
442442
*/
443443
public function default_video_transformations( $default ) {
444444

445-
if ( ! empty( $this->config['video_limit_bitrate'] ) ) {
445+
if ( 'on' === $this->config['video_limit_bitrate'] ) {
446446
$default['bit_rate'] = $this->config['video_bitrate'] . 'k';
447447
}
448-
if ( ! empty( $this->config['video_optimization'] ) && true === $this->config['video_optimization'] ) {
448+
if ( 'on' === $this->config['video_optimization'] ) {
449449
if ( 'auto' === $this->config['video_format'] ) {
450450
$default['fetch_format'] = 'auto';
451451
}

php/sync/class-upload-sync.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public function explicit_update( $attachment_id ) {
330330
*/
331331
public function update_breakpoints( $attachment_id, $breakpoints ) {
332332

333-
if ( ! empty( $this->plugin->settings->get_value( 'enable_breakpoints' ) ) ) {
333+
if ( 'on' === $this->plugin->settings->get_value( 'enable_breakpoints' ) ) {
334334
if ( ! empty( $breakpoints['responsive_breakpoints'] ) ) { // Images only.
335335
$this->media->update_post_meta( $attachment_id, Sync::META_KEYS['breakpoints'], $breakpoints['responsive_breakpoints'][0]['breakpoints'] );
336336
} elseif ( wp_attachment_is_image( $attachment_id ) ) {

php/ui/component/class-on-off.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function false_value( $struct ) {
3333
$struct['element'] = 'input';
3434
$struct['attributes']['type'] = 'hidden';
3535
$struct['attributes']['name'] = $this->get_name();
36-
$struct['attributes']['value'] = false;
36+
$struct['attributes']['value'] = 'off';
3737
unset( $struct['attributes']['class'] );
3838
unset( $struct['attributes']['data-bound'] );
3939
$struct['render'] = true;
@@ -54,8 +54,8 @@ protected function input( $struct ) {
5454
$struct['attributes']['type'] = 'checkbox';
5555
$struct['attributes']['name'] = $this->get_name();
5656
$struct['attributes']['id'] = $this->setting->get_slug();
57-
$struct['attributes']['value'] = true;
58-
if ( $this->setting->get_value() ) {
57+
$struct['attributes']['value'] = 'on';
58+
if ( 'on' === $this->setting->get_value() ) {
5959
$struct['attributes']['checked'] = 'checked';
6060
}
6161
$struct['attributes']['class'] = 'cld-ui-input';
@@ -106,6 +106,6 @@ protected function slider( $struct ) {
106106
* @return bool
107107
*/
108108
public function sanitize_value( $value ) {
109-
return (bool) $value;
109+
return 'on' === $value ? 'on' : 'off';
110110
}
111111
}

ui-definitions/settings-image.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@
2525
'title' => __( 'Image optimization', 'cloudinary' ),
2626
'tooltip_text' => __( 'Images will be delivered using Cloudinary’s automatic format and quality algorithms for the best tradeoff between visual quality and file size. Use Advanced Optimization options to manually tune format and quality.', 'cloudinary' ),
2727
'description' => __( 'Optimize images on my site.', 'cloudinary' ),
28-
'default' => true,
28+
'default' => 'on',
2929
'attributes' => array(
3030
'data-context' => 'image',
3131
),
3232
),
33-
3433
),
3534
array(
3635
'type' => 'group',
@@ -92,6 +91,7 @@
9291
'title' => __( 'Image breakpoints', 'cloudinary' ),
9392
'tooltip_text' => __( 'Automatically generate multiple sizes based on the configured breakpoints to enable your images to responsively adjust to different screen sizes. Note that your Cloudinary usage will increase when enabling responsive images.', 'cloudinary' ),
9493
'description' => __( 'Enable responsive images.', 'cloudinary' ),
94+
'default' => 'off',
9595
),
9696
array(
9797
'type' => 'group',

ui-definitions/settings-video.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
'slug' => 'video_loop',
4747
'description' => __( ' Repeat video', 'cloudinary' ),
4848
'type' => 'on_off',
49-
'default' => false,
49+
'default' => 'off',
5050
),
5151
array(
5252
'slug' => 'video_autoplay_mode',
@@ -72,7 +72,7 @@
7272
'title' => __( 'Bitrate', 'cloudinary' ),
7373
'description' => __( 'Enable bitrate limiter', 'cloudinary' ),
7474
'tooltip_text' => __( 'If set, all videos will be delivered in the defined bitrate.', 'cloudinary' ),
75-
'default' => false,
75+
'default' => 'off',
7676
'attributes' => array(
7777
'data-context' => 'video',
7878
),
@@ -85,7 +85,7 @@
8585
'default' => '500',
8686
'suffix' => 'k',
8787
'condition' => array(
88-
'video_limit_bitrate' => true,
88+
'video_limit_bitrate' => 'on',
8989
),
9090
'attributes' => array(
9191
'data-context' => 'video',
@@ -102,7 +102,7 @@
102102
'title' => __( 'Video optimization', 'cloudinary' ),
103103
'tooltip_text' => __( 'Videos will be delivered using Cloudinary’s automatic format and quality algorithms for the best tradeoff between visual quality and file size. Use Advanced Optimization options to manually tune format and quality.', 'cloudinary' ),
104104
'description' => __( 'Optimize videos on my site.', 'cloudinary' ),
105-
'default' => true,
105+
'default' => 'on',
106106
'attributes' => array(
107107
'data-context' => 'video',
108108
),
@@ -113,7 +113,7 @@
113113
'title' => __( 'Advanced optimization', 'cloudinary' ),
114114
'collapsible' => 'open',
115115
'condition' => array(
116-
'video_optimization' => true,
116+
'video_optimization' => 'on',
117117
),
118118
array(
119119
'type' => 'select',

0 commit comments

Comments
 (0)