Completed
Push — develop ( 4fb759...1e023b )
by Aristeides
08:44
created

Kirki_Modules_Collapsible::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Allows fields to collapse.
4
 *
5
 * @package     Kirki
6
 * @category    Modules
7
 * @author      Aristeides Stathopoulos
8
 * @copyright   Copyright (c) 2016, Aristeides Stathopoulos
9
 * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
10
 * @since       3.0.0
11
 */
12
13
// Exit if accessed directly.
14
if ( ! defined( 'ABSPATH' ) ) {
15
	exit;
16
}
17
18
/**
19
 * Adds styles to the customizer.
20
 */
21
class Kirki_Modules_Collapsible {
22
23
	/**
24
	 * Constructor.
25
	 *
26
	 * @access public
27
	 * @since 3.0.0
28
	 */
29
	public function __construct() {
30
31
		add_action( 'customize_controls_print_scripts', array( $this, 'customize_controls_print_scripts' ) );
32
33
	}
34
35
	/**
36
	 * Enqueues the script responsible for branding the customizer
37
	 * and also adds variables to it using the wp_localize_script function.
38
	 * The actual branding is handled via JS.
39
	 *
40
	 * @access public
41
	 * @since 3.0.0
42
	 */
43
	public function customize_controls_print_scripts() {
44
45
		wp_enqueue_script( 'kirki-collapsible', trailingslashit( Kirki::$url ) . 'modules/collapsible/collapsible.js', array( 'customize-preview' ), false, true );
46
		wp_enqueue_style( 'kirki-collapsible', trailingslashit( Kirki::$url ) . 'modules/collapsible/collapsible.css' );
47
48
		$collapsible_fields = array();
49
		$fields = Kirki::$fields;
50
		foreach ( $fields as $field ) {
51
			if ( isset( $field['collapsible'] ) && true === $field['collapsible'] && isset( $field['settings'] ) && isset( $field['label'] ) ) {
52
				$collapsible_fields[ $field['settings'] ] = $field['label'];
53
			}
54
		}
55
		$collapsible_fields = array_unique( $collapsible_fields );
56
		wp_localize_script( 'kirki-collapsible', 'collapsible', $collapsible_fields );
57
58
	}
59
}
60