Completed
Pull Request — develop (#1313)
by Aristeides
04:59
created

Kirki_Control_FontAwesome::render_content()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Customizer Control: kirki-fontawesome.
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       1.0
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Select control.
19
 */
20
class Kirki_Control_FontAwesome extends WP_Customize_Control {
21
22
	/**
23
	 * The control type.
24
	 *
25
	 * @access public
26
	 * @var string
27
	 */
28
	public $type = 'kirki-fontawesome';
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
	 * Enqueue control related scripts/styles.
48
	 *
49
	 * @access public
50
	 */
51
	public function enqueue() {
52
		wp_enqueue_script( 'select2', trailingslashit( Kirki::$url ) . 'assets/vendor/select2/js/select2.full.js', array( 'jquery' ), false, true );
53
		wp_enqueue_style( 'select2', trailingslashit( Kirki::$url ) . 'assets/vendor/select2/css/select2.min.css', null );
54
		wp_enqueue_script( 'kirki-fontawesome', trailingslashit( Kirki::$url ) . 'controls/fontawesome/fontawesome.js', array( 'jquery', 'customize-base', 'select2', 'jquery-ui-sortable' ), false, true );
55
		wp_localize_script( 'kirki-fontawesome', 'fontAwesomeJSON', file_get_contents( Kirki::$path . '/controls/fontawesome/fontawesome.json' ) );
0 ignored issues
show
introduced by
file_get_contents is highly discouraged, please use wpcom_vip_file_get_contents() instead.
Loading history...
56
		wp_enqueue_style( 'kirki-fontawesome-css', trailingslashit( Kirki::$url ) . 'controls/fontawesome/fontawesome.css', null );
57
		wp_enqueue_style( 'kirki-fontawesome-font-css', trailingslashit( Kirki::$url ) . 'controls/fontawesome/font-awesome.css', null );
58
	}
59
60
	/**
61
	 * Refresh the parameters passed to the JavaScript via JSON.
62
	 *
63
	 * @see WP_Customize_Control::to_json()
64
	 */
65
	public function to_json() {
66
		parent::to_json();
67
68
		$this->json['default'] = $this->setting->default;
69
		if ( isset( $this->default ) ) {
70
			$this->json['default'] = $this->default;
71
		}
72
		$this->json['output']  = $this->output;
73
		$this->json['value']   = $this->value();
74
		$this->json['choices'] = $this->choices;
75
		$this->json['link']    = $this->get_link();
76
		$this->json['id']      = $this->id;
77
78
		if ( 'user_meta' === $this->option_type ) {
79
			$this->json['value'] = get_user_meta( get_current_user_id(), $this->id, true );
80
		}
81
82
		$this->json['inputAttrs'] = '';
83
		foreach ( $this->input_attrs as $attr => $value ) {
84
			$this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" ';
85
		}
86
	}
87
88
89
	/**
90
	 * An Underscore (JS) template for this control's content (but not its container).
91
	 *
92
	 * Class variables for this control class are available in the `data` JS object;
93
	 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
94
	 *
95
	 * @see WP_Customize_Control::print_template()
96
	 *
97
	 * @access protected
98
	 */
99
	protected function content_template() {
100
		?>
101
		<label>
102
			<# if ( data.label ) { #>
103
				<span class="customize-control-title">{{ data.label }}</span>
104
			<# } #>
105
			<# if ( data.description ) { #>
106
				<span class="description customize-control-description">{{{ data.description }}}</span>
107
			<# } #>
108
			<select {{{ data.inputAttrs }}} {{{ data.link }}}></select>
109
		</label>
110
		<?php
111
	}
112
113
114
	/**
115
	 * Render the control's content.
116
	 *
117
	 * Allows the content to be overridden without having to rewrite the wrapper in `$this::render()`.
118
	 *
119
	 * Supports basic input types `text`, `checkbox`, `textarea`, `radio`, `select` and `dropdown-pages`.
120
	 * Additional input types such as `email`, `url`, `number`, `hidden` and `date` are supported implicitly.
121
	 *
122
	 * Control content can alternately be rendered in JS. See WP_Customize_Control::print_template().
123
	 *
124
	 * @since 3.0.0
125
	 */
126
	protected function render_content() {}
127
}
128