Skip to content

Commit 1de8cde

Browse files
authored
Merge pull request #888 from cloudinary/improve/crops
Improve/crops
2 parents 582931f + f197fd9 commit 1de8cde

File tree

7 files changed

+92
-34
lines changed

7 files changed

+92
-34
lines changed

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.

php/class-delivery.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,18 +1241,18 @@ public function parse_element( $element ) {
12411241
$config = $this->plugin->settings->get_value( 'image_settings' );
12421242

12431243
/**
1244-
* Enable the crop size settings.
1244+
* Enable the Crop and Gravity control settings.
12451245
*
1246-
* @hook cloudinary_enabled_crop_sizes
1246+
* @hook cloudinary_enable_crop_and_gravity_control
12471247
* @since 3.1.3
12481248
* @default {false}
12491249
*
1250-
* @param $enabeld {bool} Are the crop sizes enabled?
1250+
* @param $enabeld {bool} Is the Crop and Gravity control enabled?
12511251
*
12521252
* @retrun {bool}
12531253
*/
1254-
$enabled_crop_sizes = apply_filters( 'cloudinary_enabled_crop_sizes', false );
1255-
$has_sized_transformation = $enabled_crop_sizes && ! empty( $config['crop_sizes'] );
1254+
$enabled_crop_gravity = apply_filters( 'cloudinary_enable_crop_and_gravity_control', false );
1255+
$has_sized_transformation = $enabled_crop_gravity && ! empty( $config['crop_sizes'] );
12561256

12571257
$tag_element = array(
12581258
'tag' => '',

php/class-media.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,23 +1007,23 @@ public function get_crop_transformations( $attachment_id, $size ) {
10071007
}
10081008

10091009
/**
1010-
* Enable the crop size settings.
1010+
* Enable the Crop and Gravity control settings.
10111011
*
1012-
* @hook cloudinary_enabled_crop_sizes
1012+
* @hook cloudinary_enable_crop_and_gravity_control
10131013
* @since 3.1.3
10141014
* @default {false}
10151015
*
1016-
* @param $enabeld {bool} Are the crop sizes enabled?
1016+
* @param $enabeld {bool} Is the Crop and Gravity control enabled?
10171017
*
10181018
* @retrun {bool}
10191019
*/
1020-
$enabled_crop_sizes = apply_filters( 'cloudinary_enabled_crop_sizes', false );
1020+
$enabled_crop_and_gravity = apply_filters( 'cloudinary_enable_crop_and_gravity_control', false );
10211021

10221022
// Check for custom crop.
1023-
if ( is_numeric( $attachment_id ) && $enabled_crop_sizes ) {
1023+
if ( is_numeric( $attachment_id ) && $enabled_crop_and_gravity ) {
10241024
$meta_sizes = $this->get_post_meta( $attachment_id, 'cloudinary_metaboxes_crop_meta', true );
1025-
if ( ! empty( $meta_sizes['single_crop_sizes']['single_sizes'] ) ) {
1026-
$custom_sizes = $meta_sizes['single_crop_sizes']['single_sizes'];
1025+
if ( ! empty( $meta_sizes['single_crop_and_gravity']['single_sizes'] ) ) {
1026+
$custom_sizes = $meta_sizes['single_crop_and_gravity']['single_sizes'];
10271027
if ( ! empty( $custom_sizes[ $size_dim ] ) ) {
10281028
if ( '--' === $custom_sizes[ $size_dim ] ) {
10291029
$size['transformation'] = '';

php/ui/component/class-crops.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Cloudinary\UI\Component;
99

10+
use Cloudinary\Settings\Setting;
1011
use Cloudinary\Utils;
1112
use function Cloudinary\get_plugin_instance;
1213

@@ -33,7 +34,7 @@ class Crops extends Select {
3334
*
3435
* @var string
3536
*/
36-
protected $blueprint = 'wrap|label|title|/title|prefix/|/label|input/|/wrap';
37+
protected $blueprint = 'wrap|hr/|label|title/|prefix/|/label|info_box/|input/|/wrap';
3738

3839
/**
3940
* Enqueue scripts this component may use.
@@ -42,6 +43,51 @@ public function enqueue_scripts() {
4243
wp_enqueue_media();
4344
}
4445

46+
/**
47+
* Filter the hr structure.
48+
*
49+
* @param array $struct The array structure.
50+
*
51+
* @return array
52+
*/
53+
protected function hr( $struct ) {
54+
55+
if ( 'image_settings' === $this->setting->get_parent()->get_slug() ) {
56+
$struct['element'] = 'hr';
57+
$struct['render'] = true;
58+
}
59+
60+
return $struct;
61+
}
62+
63+
/**
64+
* Filter the info box structure.
65+
*
66+
* @param array $struct The array structure.
67+
*
68+
* @return array
69+
*/
70+
protected function info_box( $struct ) {
71+
$panel_toggle = new Setting( 'info_box_crop_gravity' );
72+
$panel_toggle->set_param( 'title', __( 'What is Crop and Gravity control?', 'cloudinary' ) );
73+
$panel_toggle->set_param(
74+
'text',
75+
sprintf(
76+
// translators: %1$s: link to Crop doc, %2$s: link to Gravity doc.
77+
__( 'This feature allows you to fine tune the behaviour of the %1$s and %2$s per registered crop size of the delivered images.', 'cloudinary' ),
78+
'<a href="https://cloudinary.com/documentation/resizing_and_cropping#resize_and_crop_modes" target="_blank">' . __( 'Crop', 'cloudinary' ) . '</a>',
79+
'<a href="https://cloudinary.com/documentation/resizing_and_cropping#control_gravity" target="_blank">' . __( 'Gravity', 'cloudinary' ) . '</a>'
80+
)
81+
);
82+
$panel_toggle->set_param( 'icon', get_plugin_instance()->dir_url . 'css/images/crop.svg' );
83+
$title_toggle = new Info_Box( $panel_toggle );
84+
85+
$struct['element'] = 'div';
86+
$struct['content'] = $title_toggle->render();
87+
88+
return $struct;
89+
}
90+
4591
/**
4692
* Filter the select input parts structure.
4793
*
@@ -169,9 +215,14 @@ protected function make_input( $name, $value ) {
169215
'crop-size-inputs',
170216
);
171217

218+
$label = $this->get_part( 'label' );
219+
$label['attributes']['for'] = $name;
220+
$label['content'] = __( 'Disable', 'cloudinary' );
221+
172222
$check = $this->get_part( 'input' );
173223
$check['attributes']['type'] = 'checkbox';
174224
$check['attributes']['name'] = $name;
225+
$check['attributes']['id'] = $name;
175226
$check['attributes']['value'] = '--';
176227
$check['attributes']['class'][] = 'disable-toggle';
177228
$check['attributes']['title'] = __( 'Disable gravity and crops', 'cloudinary' );
@@ -186,6 +237,7 @@ protected function make_input( $name, $value ) {
186237
$input['attributes']['class'][] = 'regular-text';
187238

188239
$wrapper['children']['input'] = $input;
240+
$wrapper['children']['label'] = $label;
189241
$wrapper['children']['check'] = $check;
190242

191243
return $wrapper;

src/css/components/_ui.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,9 @@
3232
color: $color-white;
3333
font-size: 0.8em;
3434
}
35+
36+
#poststuff .cld-info-box h2 {
37+
padding: 0;
38+
margin: 0 0 6px;
39+
font-weight: 700;
40+
}

ui-definitions/settings-image.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
),
176176
array(
177177
'type' => 'info_box',
178-
'icon' => $this->dir_url . 'css/images/crop.svg',
178+
'icon' => $this->dir_url . 'css/images/transformation.svg',
179179
'title' => __( 'What are transformations?', 'cloudinary' ),
180180
'text' => __(
181181
'A set of parameters included in a Cloudinary URL to programmatically transform the visual appearance of the assets on your website.',
@@ -189,8 +189,8 @@
189189
array(
190190
'type' => 'on_off',
191191
'slug' => 'svg_support',
192-
'title' => __( 'SVG Support (beta)', 'cloudinary' ),
193-
'optimisation_title' => __( 'SVG Support (beta)', 'cloudinary' ),
192+
'title' => __( 'SVG Support', 'cloudinary' ),
193+
'optimisation_title' => __( 'SVG Support', 'cloudinary' ),
194194
'tooltip_text' => __(
195195
'Enable Cloudinary\'s beta SVG Support.',
196196
'cloudinary'
@@ -201,20 +201,20 @@
201201
array(
202202
'type' => 'crops',
203203
'slug' => 'crop_sizes',
204-
'title' => __( 'Crops Sizes', 'cloudinary' ),
205-
'enabled' => function () {
204+
'title' => __( 'Crop and Gravity control (beta)', 'cloudinary' ),
205+
'enabled' => static function () {
206206
/**
207-
* Enable the crop size settings.
207+
* Enable the Crop and Gravity control settings.
208208
*
209-
* @hook cloudinary_enabled_crop_sizes
209+
* @hook cloudinary_enable_crop_and_gravity_control
210210
* @since 3.1.3
211211
* @default {false}
212212
*
213-
* @param $enabeld {bool} Are the crop sizes enabled?
213+
* @param $enabeld {bool} Is the Crop and Gravity control enabled?
214214
*
215215
* @retrun {bool}
216216
*/
217-
return apply_filters( 'cloudinary_enabled_crop_sizes', false );
217+
return apply_filters( 'cloudinary_enable_crop_and_gravity_control', false );
218218
},
219219
),
220220
),

ui-definitions/settings-metaboxes.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,44 @@
66
*/
77

88
/**
9-
* Enable the crop size settings.
9+
* Enable the Crop and Gravity control settings.
1010
*
11-
* @hook cloudinary_enabled_crop_sizes
11+
* @hook cloudinary_enable_crop_and_gravity_control
1212
* @since 3.1.3
1313
* @default {false}
1414
*
15-
* @param $enabeld {bool} Are the crop sizes enabled?
15+
* @param $enabeld {bool} Is the Crop and Gravity control enabled?
1616
*
1717
* @retrun {bool}
1818
*/
19-
if ( ! apply_filters( 'cloudinary_enabled_crop_sizes', false ) ) {
19+
if ( ! apply_filters( 'cloudinary_enable_crop_and_gravity_control', false ) ) {
2020
return array();
2121
}
2222
$metaboxes = array(
2323
'crop_meta' => array(
24-
'title' => __( 'Cloudinary crop sizes', 'cloudinary' ),
24+
'title' => __( 'Cloudinary Crop and Gravity control', 'cloudinary' ),
2525
'screen' => 'attachment',
2626
'settings' => array(
2727
array(
28-
'slug' => 'single_crop_sizes',
28+
'slug' => 'single_crop_and_gravity',
2929
'type' => 'stand_alone',
3030
array(
3131
'type' => 'on_off',
32-
'slug' => 'enable_single_sizes',
33-
'title' => __( 'Sized transformations', 'cloudinary' ),
32+
'slug' => 'enable_crop_and_gravity',
33+
'title' => __( 'Crop and Gravity control (beta)', 'cloudinary' ),
3434
'tooltip_text' => __(
35-
'Enable transformations per registered image sizes.',
35+
'Enable Crop and Gravity control for registered image sizes.',
3636
'cloudinary'
3737
),
38-
'description' => __( 'Enable sized transformations.', 'cloudinary' ),
38+
'description' => __( 'Enable Crop and Gravity', 'cloudinary' ),
3939
'default' => 'off',
4040
),
4141
array(
4242
'type' => 'crops',
4343
'slug' => 'single_sizes',
4444
'mode' => 'full',
4545
'condition' => array(
46-
'enable_single_sizes' => true,
46+
'enable_crop_and_gravity' => true,
4747
),
4848
),
4949
),

0 commit comments

Comments
 (0)