Completed
Push — develop ( d8be36...adf00f )
by Aristeides
02:34
created

Kirki_Control_Dimension::l10n()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Customizer Control: dimension
4
 *
5
 * @package     Kirki
6
 * @subpackage  Controls
7
 * @copyright   Copyright (c) 2016, Aristeides Stathopoulos
8
 * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
9
 * @since       2.0
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * A text control with validation for CSS units.
19
 */
20
class Kirki_Control_Dimension extends WP_Customize_Control {
21
22
	/**
23
	 * The control type.
24
	 *
25
	 * @access public
26
	 * @var string
27
	 */
28
	public $type = 'kirki-dimension';
29
30
	/**
31
	 * Used to automatically generate all CSS output.
32
	 *
33
	 * @access public
34
	 * @var array
35
	 */
36
	public $output = array();
37
38
	/**
39
	 * Data type
40
	 *
41
	 * @access public
42
	 * @var string
43
	 */
44
	public $option_type = 'theme_mod';
45
46
	/**
47
	 * The kirki_config we're using for this control
48
	 *
49
	 * @access public
50
	 * @var string
51
	 */
52
	public $kirki_config = 'global';
53
54
	/**
55
	 * The translation strings.
56
	 *
57
	 * @access protected
58
	 * @since 2.3.5
59
	 * @var array
60
	 */
61
	protected $l10n = array();
62
63
	/**
64
	 * Enqueue control related scripts/styles.
65
	 *
66
	 * @access public
67
	 */
68
	public function enqueue() {
69
70
		wp_enqueue_script( 'kirki-dimension', trailingslashit( Kirki::$url ) . 'controls/dimension/dimension.js', array( 'jquery', 'customize-base' ), false, true );
71
		wp_localize_script( 'kirki-dimension', 'kirkiL10n', $this->l10n() );
72
		wp_enqueue_style( 'kirki-dimension-css', trailingslashit( Kirki::$url ) . 'controls/dimension/dimension.css', null );
73
74
	}
75
76
	/**
77
	 * Refresh the parameters passed to the JavaScript via JSON.
78
	 *
79
	 * @see WP_Customize_Control::to_json()
80
	 */
81
	public function to_json() {
82
		parent::to_json();
83
84
		$this->json['default'] = $this->setting->default;
85
		if ( isset( $this->default ) ) {
86
			$this->json['default'] = $this->default;
87
		}
88
		$this->json['output']      = $this->output;
89
		$this->json['value']       = $this->value();
90
		$this->json['choices']     = $this->choices;
91
		$this->json['link']        = $this->get_link();
92
		$this->json['id']          = $this->id;
93
		$this->json['l10n']        = $this->l10n;
94
		$this->json['kirkiConfig'] = $this->kirki_config;
95
96
		if ( 'user_meta' === $this->option_type ) {
97
			$this->json['value'] = get_user_meta( get_current_user_id(), $this->id, true );
98
		}
99
100
		$this->json['inputAttrs'] = '';
101
		foreach ( $this->input_attrs as $attr => $value ) {
102
			$this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" ';
103
		}
104
105
	}
106
107
	/**
108
	 * An Underscore (JS) template for this control's content (but not its container).
109
	 *
110
	 * Class variables for this control class are available in the `data` JS object;
111
	 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
112
	 *
113
	 * @see WP_Customize_Control::print_template()
114
	 *
115
	 * @access protected
116
	 */
117
	protected function content_template() {
118
		?>
119
		<label class="customizer-text">
120
			<# if ( data.label ) { #>
121
				<span class="customize-control-title">{{{ data.label }}}</span>
122
			<# } #>
123
			<# if ( data.description ) { #>
124
				<span class="description customize-control-description">{{{ data.description }}}</span>
125
			<# } #>
126
			<div class="input-wrapper">
127
				<input {{{ data.inputAttrs }}} type="text" value="{{ data.value }}"/>
128
			</div>
129
		</label>
130
		<?php
131
	}
132
133
	/**
134
	 * Returns an array of translation strings.
135
	 *
136
	 * @access protected
137
	 * @since 2.4.0
138
	 * @param string|false $id The string-ID.
139
	 * @return string
140
	 */
141
	protected function l10n( $id = false ) {
142
		$translation_strings = array(
143
			'invalid-value' => esc_attr__( 'Invalid Value', 'kirki' ),
144
		);
145
		return apply_filters( 'kirki/' . $this->kirki_config . '/l10n', $translation_strings );
146
	}
147
}
148