WP_Customize_Cropped_Image_Control
云策文档标注
概述
WP_Customize_Cropped_Image_Control 是 WordPress 自定义器中的一个控件类,用于处理裁剪图像的上传和设置。它继承自 WP_Customize_Image_Control,提供对图像裁剪尺寸和灵活性的控制。
关键要点
- 继承自 WP_Customize_Image_Control,专为裁剪图像设计
- 支持设置建议的裁剪宽度和高度,默认值为 150
- 提供灵活宽度和高度选项,通过 flex_width 和 flex_height 属性控制
- 包含 enqueue 方法用于加载相关脚本和样式
- 包含 to_json 方法用于将参数传递给 JavaScript
代码示例
$wp_customizer->add_control(
new WP_Customize_Cropped_Image_Control(
$wp_customizer,
'demo_image_settings',
array(
'label' => __( 'Upload a File', 'Text Domain' ),
'section' => 'customizer section name',
'height'=>100, // cropper Height
'width'=>100, // Cropper Width
'flex_width'=>true, //Flexible Width
'flex_height'=>true, // Flexible Heiht
)
)
);注意事项
- 使用 'height' 和 'width' 参数固定裁剪尺寸
- 设置 'flex_width' 和 'flex_height' 为 true 以实现灵活裁剪
- 确保正确引用自定义器对象和节名称
原文内容
Customize Cropped Image Control class.
Description
See also
Methods
| Name | Description |
|---|---|
| WP_Customize_Cropped_Image_Control::enqueue | Enqueue control related scripts/styles. |
| WP_Customize_Cropped_Image_Control::to_json | Refresh the parameters passed to the JavaScript via JSON. |
Source
class WP_Customize_Cropped_Image_Control extends WP_Customize_Image_Control {
/**
* Control type.
*
* @since 4.3.0
* @var string
*/
public $type = 'cropped_image';
/**
* Suggested width for cropped image.
*
* @since 4.3.0
* @var int
*/
public $width = 150;
/**
* Suggested height for cropped image.
*
* @since 4.3.0
* @var int
*/
public $height = 150;
/**
* Whether the width is flexible.
*
* @since 4.3.0
* @var bool
*/
public $flex_width = false;
/**
* Whether the height is flexible.
*
* @since 4.3.0
* @var bool
*/
public $flex_height = false;
/**
* Enqueue control related scripts/styles.
*
* @since 4.3.0
*/
public function enqueue() {
wp_enqueue_script( 'customize-views' );
parent::enqueue();
}
/**
* Refresh the parameters passed to the JavaScript via JSON.
*
* @since 4.3.0
*
* @see WP_Customize_Control::to_json()
*/
public function to_json() {
parent::to_json();
$this->json['width'] = absint( $this->width );
$this->json['height'] = absint( $this->height );
$this->json['flex_width'] = absint( $this->flex_width );
$this->json['flex_height'] = absint( $this->flex_height );
}
}
Changelog
| Version | Description |
|---|---|
| 4.3.0 | Introduced. |
Skip to note 2 content
salam91
You can Fixed the Height and width area by using
'height'=>100and'width'=>100respectively. Useflex_width=> trueto get flexible width in cropper. you can also useflex_height=>trueto get flexible height in cropper. A details examples is shown bellow$wp_customizer->add_control( new WP_Customize_Cropped_Image_Control( $wp_customizer, 'demo_image_settings', array( 'label' => __( 'Upload a File', 'Text Domain' ), 'section' => 'customizer section name', 'height'=>100, // cropper Height 'width'=>100, // Cropper Width 'flex_width'=>true, //Flexible Width 'flex_height'=>true, // Flexible Heiht ) ) );