From 7384082205bf47eb2bd3cb3386f7dc8a9111eab7 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Tue, 19 Jan 2021 16:00:37 +0200 Subject: [PATCH 1/3] set values on or off only --- php/class-media.php | 2 +- php/ui/component/class-on-off.php | 8 ++++---- ui-definitions/settings-image.php | 3 +-- ui-definitions/settings-video.php | 6 +++--- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/php/class-media.php b/php/class-media.php index ad865acdc..c676f7f70 100644 --- a/php/class-media.php +++ b/php/class-media.php @@ -773,7 +773,7 @@ public function default_image_transformations( $default ) { $config = $this->settings->get_value( 'image_settings' ); - if ( true === $config['image_optimization'] ) { + if ( 'on' === $config['image_optimization'] ) { if ( 'auto' === $config['image_format'] ) { $default['fetch_format'] = 'auto'; } diff --git a/php/ui/component/class-on-off.php b/php/ui/component/class-on-off.php index 86e40d8cb..feba384c3 100644 --- a/php/ui/component/class-on-off.php +++ b/php/ui/component/class-on-off.php @@ -33,7 +33,7 @@ protected function false_value( $struct ) { $struct['element'] = 'input'; $struct['attributes']['type'] = 'hidden'; $struct['attributes']['name'] = $this->get_name(); - $struct['attributes']['value'] = false; + $struct['attributes']['value'] = 'off'; unset( $struct['attributes']['class'] ); unset( $struct['attributes']['data-bound'] ); $struct['render'] = true; @@ -54,8 +54,8 @@ protected function input( $struct ) { $struct['attributes']['type'] = 'checkbox'; $struct['attributes']['name'] = $this->get_name(); $struct['attributes']['id'] = $this->setting->get_slug(); - $struct['attributes']['value'] = true; - if ( $this->setting->get_value() ) { + $struct['attributes']['value'] = 'on'; + if ( 'true' === $this->setting->get_value() ) { $struct['attributes']['checked'] = 'checked'; } $struct['attributes']['class'] = 'cld-ui-input'; @@ -106,6 +106,6 @@ protected function slider( $struct ) { * @return bool */ public function sanitize_value( $value ) { - return (bool) $value; + return 'on' === $value ? 'on' : 'off'; } } diff --git a/ui-definitions/settings-image.php b/ui-definitions/settings-image.php index e22766c3e..75d3275c4 100644 --- a/ui-definitions/settings-image.php +++ b/ui-definitions/settings-image.php @@ -25,12 +25,11 @@ 'title' => __( 'Image optimization', 'cloudinary' ), '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' ), 'description' => __( 'Optimize images on my site.', 'cloudinary' ), - 'default' => true, + 'default' => 'on', 'attributes' => array( 'data-context' => 'image', ), ), - ), array( 'type' => 'group', diff --git a/ui-definitions/settings-video.php b/ui-definitions/settings-video.php index 882322406..4f417f2ee 100644 --- a/ui-definitions/settings-video.php +++ b/ui-definitions/settings-video.php @@ -46,7 +46,7 @@ 'slug' => 'video_loop', 'description' => __( ' Repeat video', 'cloudinary' ), 'type' => 'on_off', - 'default' => false, + 'default' => 'off', ), array( 'slug' => 'video_autoplay_mode', @@ -72,7 +72,7 @@ 'title' => __( 'Bitrate', 'cloudinary' ), 'description' => __( 'Enable bitrate limiter', 'cloudinary' ), 'tooltip_text' => __( 'If set, all videos will be delivered in the defined bitrate.', 'cloudinary' ), - 'default' => false, + 'default' => 'off', 'attributes' => array( 'data-context' => 'video', ), @@ -102,7 +102,7 @@ 'title' => __( 'Video optimization', 'cloudinary' ), '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' ), 'description' => __( 'Optimize videos on my site.', 'cloudinary' ), - 'default' => true, + 'default' => 'on', 'attributes' => array( 'data-context' => 'video', ), From 343539ea45db00156a4f041b65eee64282182270 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Tue, 19 Jan 2021 16:04:10 +0200 Subject: [PATCH 2/3] on for compare --- php/ui/component/class-on-off.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/ui/component/class-on-off.php b/php/ui/component/class-on-off.php index feba384c3..bdfa25f62 100644 --- a/php/ui/component/class-on-off.php +++ b/php/ui/component/class-on-off.php @@ -55,7 +55,7 @@ protected function input( $struct ) { $struct['attributes']['name'] = $this->get_name(); $struct['attributes']['id'] = $this->setting->get_slug(); $struct['attributes']['value'] = 'on'; - if ( 'true' === $this->setting->get_value() ) { + if ( 'on' === $this->setting->get_value() ) { $struct['attributes']['checked'] = 'checked'; } $struct['attributes']['class'] = 'cld-ui-input'; From 7b2c65b64cb09bbdadc7791cd021f3bb83af38b8 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Tue, 19 Jan 2021 16:35:58 +0200 Subject: [PATCH 3/3] ensure correct value - defaults --- php/class-media.php | 4 ++-- php/media/class-video.php | 4 ++-- php/sync/class-upload-sync.php | 2 +- ui-definitions/settings-image.php | 1 + ui-definitions/settings-video.php | 4 ++-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/php/class-media.php b/php/class-media.php index c676f7f70..153698a1c 100644 --- a/php/class-media.php +++ b/php/class-media.php @@ -1145,7 +1145,7 @@ public function image_srcset( $sources, $size_array, $image_src, $image_meta, $a $image_meta['overwrite_transformations'] = ! empty( $image_meta['overwrite_transformations'] ) ? $image_meta['overwrite_transformations'] : false; - 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] ) ) { + 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] ) ) { $meta = $this->get_post_meta( $attachment_id, Sync::META_KEYS['breakpoints'], true ); if ( ! empty( $meta ) ) { // 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 ) { $breakpoints = array(); $settings = $this->settings->get_setting( self::MEDIA_SETTINGS_SLUG )->get_value(); - if ( ! empty( $settings['enable_breakpoints'] ) && wp_attachment_is_image( $attachment_id ) ) { + if ( 'on' === $settings['enable_breakpoints'] && wp_attachment_is_image( $attachment_id ) ) { $meta = wp_get_attachment_metadata( $attachment_id ); // Get meta image size if non exists. if ( empty( $meta ) ) { diff --git a/php/media/class-video.php b/php/media/class-video.php index 9a5d40996..db0f1dcdb 100644 --- a/php/media/class-video.php +++ b/php/media/class-video.php @@ -442,10 +442,10 @@ public function filter_video_block_pre_render( $block, $source_block ) { */ public function default_video_transformations( $default ) { - if ( ! empty( $this->config['video_limit_bitrate'] ) ) { + if ( 'on' === $this->config['video_limit_bitrate'] ) { $default['bit_rate'] = $this->config['video_bitrate'] . 'k'; } - if ( ! empty( $this->config['video_optimization'] ) && true === $this->config['video_optimization'] ) { + if ( 'on' === $this->config['video_optimization'] ) { if ( 'auto' === $this->config['video_format'] ) { $default['fetch_format'] = 'auto'; } diff --git a/php/sync/class-upload-sync.php b/php/sync/class-upload-sync.php index bacfc8830..dd23ebec4 100644 --- a/php/sync/class-upload-sync.php +++ b/php/sync/class-upload-sync.php @@ -330,7 +330,7 @@ public function explicit_update( $attachment_id ) { */ public function update_breakpoints( $attachment_id, $breakpoints ) { - if ( ! empty( $this->plugin->settings->get_value( 'enable_breakpoints' ) ) ) { + if ( 'on' === $this->plugin->settings->get_value( 'enable_breakpoints' ) ) { if ( ! empty( $breakpoints['responsive_breakpoints'] ) ) { // Images only. $this->media->update_post_meta( $attachment_id, Sync::META_KEYS['breakpoints'], $breakpoints['responsive_breakpoints'][0]['breakpoints'] ); } elseif ( wp_attachment_is_image( $attachment_id ) ) { diff --git a/ui-definitions/settings-image.php b/ui-definitions/settings-image.php index 75d3275c4..a7cbed4ee 100644 --- a/ui-definitions/settings-image.php +++ b/ui-definitions/settings-image.php @@ -91,6 +91,7 @@ 'title' => __( 'Image breakpoints', 'cloudinary' ), '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' ), 'description' => __( 'Enable responsive images.', 'cloudinary' ), + 'default' => 'off', ), array( 'type' => 'group', diff --git a/ui-definitions/settings-video.php b/ui-definitions/settings-video.php index 4f417f2ee..674e0fe2a 100644 --- a/ui-definitions/settings-video.php +++ b/ui-definitions/settings-video.php @@ -85,7 +85,7 @@ 'default' => '500', 'suffix' => 'k', 'condition' => array( - 'video_limit_bitrate' => true, + 'video_limit_bitrate' => 'on', ), 'attributes' => array( 'data-context' => 'video', @@ -113,7 +113,7 @@ 'title' => __( 'Advanced optimization', 'cloudinary' ), 'collapsible' => 'open', 'condition' => array( - 'video_optimization' => true, + 'video_optimization' => 'on', ), array( 'type' => 'select',