|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Automatic field-dependencies scripts calculation for Kirki controls. |
|
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 2.4.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_Field_Dependencies { |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @access public |
|
27
|
|
|
* @since 2.4.0 |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct() { |
|
30
|
|
|
add_action( 'customize_controls_enqueue_scripts', array( $this, 'field_dependencies' ) ); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Enqueues the field-dependencies script |
|
35
|
|
|
* and adds variables to it using the wp_localize_script function. |
|
36
|
|
|
* The rest is handled via JS. |
|
37
|
|
|
*/ |
|
38
|
|
|
public function field_dependencies() { |
|
39
|
|
|
|
|
40
|
|
|
wp_enqueue_script( 'kirki_field_dependencies', trailingslashit( Kirki::$url ) . 'modules/field-dependencies/field-dependencies.js', array( 'jquery', 'customize-base', 'customize-controls' ), false, true ); |
|
41
|
|
|
$field_dependencies = array(); |
|
42
|
|
|
$fields = Kirki::$fields; |
|
43
|
|
|
foreach ( $fields as $field ) { |
|
44
|
|
|
$process_field = false; |
|
45
|
|
|
if ( isset( $field['active_callback'] ) && is_array( $field['active_callback'] ) ) { |
|
46
|
|
|
if ( array( 'Kirki_Active_Callback', 'evaluate' ) === $field['active_callback'] ) { |
|
47
|
|
|
$process_field = true; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
if ( $process_field && isset( $field['required'] ) && ! empty( $field['required'] ) ) { |
|
51
|
|
|
$field_dependencies[ $field['id'] ] = $field['required']; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
wp_localize_script( 'kirki_field_dependencies', 'fieldDependencies', $field_dependencies ); |
|
55
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|