1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Custom Sections. |
4
|
|
|
* |
5
|
|
|
* @package Kirki |
6
|
|
|
* @category Modules |
7
|
|
|
* @subpackage Custom Sections Module |
8
|
|
|
* @author Aristeides Stathopoulos |
9
|
|
|
* @copyright Copyright (c) 2017, Aristeides Stathopoulos |
10
|
|
|
* @license https://opensource.org/licenses/MIT |
11
|
|
|
* @since 3.0.0 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
// Exit if accessed directly. |
15
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
16
|
|
|
exit; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Adds styles to the customizer. |
21
|
|
|
*/ |
22
|
|
|
class Kirki_Modules_Custom_Sections { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The object instance. |
26
|
|
|
* |
27
|
|
|
* @static |
28
|
|
|
* @access private |
29
|
|
|
* @since 3.0.0 |
30
|
|
|
* @var object |
31
|
|
|
*/ |
32
|
|
|
private static $instance; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Constructor. |
36
|
|
|
* |
37
|
|
|
* @access protected |
38
|
|
|
* @since 3.0.0 |
39
|
|
|
*/ |
40
|
|
|
protected function __construct() { |
41
|
|
|
|
42
|
|
|
// Register the new section types. |
43
|
|
|
add_filter( 'kirki_section_types', array( $this, 'set_section_types' ) ); |
44
|
|
|
|
45
|
|
|
// Register the new panel types. |
46
|
|
|
add_filter( 'kirki_panel_types', array( $this, 'set_panel_types' ) ); |
47
|
|
|
|
48
|
|
|
// Include the section-type files. |
49
|
|
|
add_action( 'customize_register', array( $this, 'include_sections_and_panels' ) ); |
50
|
|
|
|
51
|
|
|
// Enqueue styles & scripts. |
52
|
|
|
add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scrips' ), 999 ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Gets an instance of this object. |
57
|
|
|
* Prevents duplicate instances which avoid artefacts and improves performance. |
58
|
|
|
* |
59
|
|
|
* @static |
60
|
|
|
* @access public |
61
|
|
|
* @since 3.0.0 |
62
|
|
|
* @return object |
63
|
|
|
*/ |
64
|
|
|
public static function get_instance() { |
65
|
|
|
if ( ! self::$instance ) { |
66
|
|
|
self::$instance = new self(); |
67
|
|
|
} |
68
|
|
|
return self::$instance; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Add the custom section types. |
73
|
|
|
* |
74
|
|
|
* @access public |
75
|
|
|
* @since 3.0.0 |
76
|
|
|
* @param array $section_types The registered section-types. |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
|
|
public function set_section_types( $section_types ) { |
80
|
|
|
$new_types = array( |
81
|
|
|
'kirki-default' => 'Kirki_Sections_Default_Section', |
82
|
|
|
'kirki-expanded' => 'Kirki_Sections_Expanded_Section', |
83
|
|
|
'kirki-nested' => 'Kirki_Sections_Nested_Section', |
84
|
|
|
); |
85
|
|
|
return array_merge( $section_types, $new_types ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Add the custom panel types. |
90
|
|
|
* |
91
|
|
|
* @access public |
92
|
|
|
* @since 3.0.0 |
93
|
|
|
* @param array $panel_types The registered section-types. |
94
|
|
|
* @return array |
95
|
|
|
*/ |
96
|
|
|
public function set_panel_types( $panel_types ) { |
97
|
|
|
$new_types = array( |
98
|
|
|
'kirki-nested' => 'Kirki_Panels_Nested_Panel', |
99
|
|
|
); |
100
|
|
|
return array_merge( $panel_types, $new_types ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Include the custom-section classes. |
105
|
|
|
* |
106
|
|
|
* @access public |
107
|
|
|
* @since 3.0.0 |
108
|
|
|
*/ |
109
|
|
|
public function include_sections_and_panels() { |
110
|
|
|
|
111
|
|
|
// Sections. |
112
|
|
|
$folder_path = dirname( __FILE__ ) . '/sections/'; |
113
|
|
|
$section_types = apply_filters( 'kirki_section_types', array() ); |
114
|
|
|
|
115
|
|
|
foreach ( $section_types as $id => $class ) { |
116
|
|
|
if ( ! class_exists( $class ) ) { |
117
|
|
|
$path = wp_normalize_path( $folder_path . 'class-kirki-sections-' . $id . '-section.php' ); |
118
|
|
|
if ( file_exists( $path ) ) { |
119
|
|
|
include_once $path; |
120
|
|
|
continue; |
121
|
|
|
} |
122
|
|
|
$path = str_replace( 'class-kirki-sections-kirki-', 'class-kirki-sections-', $path ); |
123
|
|
|
if ( file_exists( $path ) ) { |
124
|
|
|
include_once $path; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
// Panels. |
130
|
|
|
$folder_path = dirname( __FILE__ ) . '/panels/'; |
131
|
|
|
$panel_types = apply_filters( 'kirki_panel_types', array() ); |
132
|
|
|
|
133
|
|
|
foreach ( $panel_types as $id => $class ) { |
134
|
|
|
if ( ! class_exists( $class ) ) { |
135
|
|
|
$path = wp_normalize_path( $folder_path . 'class-kirki-panels-' . $id . '-panel.php' ); |
136
|
|
|
if ( file_exists( $path ) ) { |
137
|
|
|
include_once $path; |
138
|
|
|
continue; |
139
|
|
|
} |
140
|
|
|
$path = str_replace( 'class-kirki-panels-kirki-', 'class-kirki-panels-', $path ); |
141
|
|
|
if ( file_exists( $path ) ) { |
142
|
|
|
include_once $path; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Enqueues any necessary scripts and styles. |
150
|
|
|
* |
151
|
|
|
* @access public |
152
|
|
|
* @since 3.0.0 |
153
|
|
|
*/ |
154
|
|
|
public function enqueue_scrips() { |
155
|
|
|
wp_enqueue_style( 'kirki-custom-sections', trailingslashit( Kirki::$url ) . 'modules/custom-sections/sections.css', array(), KIRKI_VERSION ); |
156
|
|
|
wp_enqueue_script( 'kirki-custom-sections', trailingslashit( Kirki::$url ) . 'modules/custom-sections/sections.js', array( 'jquery', 'customize-base', 'customize-controls' ), KIRKI_VERSION, false ); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|