WP_Customize_Cropped_Image_Control

Customize Cropped Image Control class.


Description Description

See also See also


Top ↑

Source Source

File: wp-includes/customize/class-wp-customize-cropped-image-control.php

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 );
	}

}


Top ↑

Methods Methods

  • enqueue — Enqueue control related scripts/styles.
  • to_json — Refresh the parameters passed to the JavaScript via JSON.

Top ↑

Changelog Changelog

Changelog
Version Description
4.3.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by salam91

    You can Fixed the Height and width area by using 'height'=>100 and 'width'=>100 respectively. Use flex_width=> true to get flexible width in cropper. you can also use flex_height=>true to 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
    			)
    		)
    	);

You must log in before being able to contribute a note or feedback.