PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.1.1
Kirki – Freeform Page Builder, Website Builder & Customizer v6.1.1
6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / customizer / packages / controls / dimension / src / Control / Dimension.php
kirki / customizer / packages / controls / dimension / src / Control Last commit date
Dimension.php 3 months ago
Dimension.php
144 lines
1 <?php
2 /**
3 * Customizer Control: dimension
4 *
5 * @package kirki-framework/control-dimension
6 * @copyright Copyright (c) 2023, Themeum
7 * @license https://opensource.org/licenses/MIT
8 * @since 1.0
9 */
10
11 namespace Kirki\Control;
12
13 use Kirki\Control\Base;
14 use Kirki\URL;
15
16 // Exit if accessed directly.
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21 /**
22 * A text control with validation for CSS units.
23 *
24 * @since 1.0
25 */
26 class Dimension extends Base {
27
28 /**
29 * The control type.
30 *
31 * @access public
32 * @since 1.0
33 * @var string
34 */
35 public $type = 'kirki-dimension';
36
37 /**
38 * The version. Used in scripts & styles for cache-busting.
39 *
40 * @static
41 * @access public
42 * @since 1.0
43 * @var string
44 */
45 public static $control_ver = '1.0';
46
47 /**
48 * Enqueue control related scripts/styles.
49 *
50 * @access public
51 * @since 1.0
52 * @return void
53 */
54
55
56 /**
57 * Get the URL for the control folder.
58 *
59 * This is a static method because there are more controls in the Kirki framework
60 * that use colorpickers, and they all need to enqueue the same assets.
61 *
62 * @static
63 * @access public
64 * @since 1.0
65 * @return string
66 */
67 public static function get_control_path_url() {
68 return URL::get_from_path( dirname( __DIR__ ) );
69 }
70
71 /**
72 * Refresh the parameters passed to the JavaScript via JSON.
73 *
74 * @access public
75 * @since 1.0
76 * @see WP_Customize_Control::to_json()
77 * @return void
78 */
79 public function to_json() {
80
81 $input_class = 'kirki-control-input';
82
83 if ( isset( $this->input_attrs['class'] ) ) {
84 $input_class .= ' ' . $this->input_attrs['class'];
85 unset( $this->input_attrs['class'] );
86 }
87
88 // Get the basics from the parent class.
89 parent::to_json();
90
91 // Input class name.
92 $this->json['inputClass'] = $input_class;
93
94 // Label position.
95 $this->json['labelPosition'] = 'top';
96
97 if ( isset( $this->choices['label_position'] ) && 'bottom' === $this->choices['label_position'] ) {
98 $this->json['labelPosition'] = 'bottom';
99 }
100
101 // Input id.
102 $this->json['inputId'] = '_customize-input-' . $this->id;
103
104 }
105
106 /**
107 * An Underscore (JS) template for this control's content (but not its container).
108 *
109 * Class variables for this control class are available in the `data` JS object;
110 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
111 *
112 * @see WP_Customize_Control::print_template()
113 *
114 * @access protected
115 * @since 1.0
116 * @return void
117 */
118 protected function content_template() {
119 ?>
120
121 <div class="kirki-control-form <# if ('bottom' === data.labelPosition) { #>has-label-bottom<# } #>">
122 <# if ( 'top' === data.labelPosition ) { #>
123 <label class="kirki-control-label" for="{{ data.inputId }}">
124 <# if ( data.label ) { #><span class="customize-control-title">{{{ data.label }}}</span><# } #>
125 <# if ( data.description ) { #><span class="description customize-control-description">{{{ data.description }}}</span><# } #>
126 </label>
127 <# } #>
128
129 <div class="kirki-input-control">
130 <# var val = ( data.value && _.isString( data.value ) ) ? data.value.replace( '%%', '%' ) : ''; #>
131 <input id="{{ data.inputId }}" {{{ data.inputAttrs }}} type="text" value="{{ val }}" class="{{ data.inputClass }}" />
132 </div>
133
134 <# if ( 'bottom' === data.labelPosition ) { #>
135 <label class="kirki-control-label" for="{{ data.inputId }}">
136 <# if ( data.label ) { #>{{{ data.label }}} <# } #>
137 </label>
138 <# } #>
139 </div>
140
141 <?php
142 }
143 }
144