|
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 http://opensource.org/licenses/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
|
|
|
// Register the new section types. |
|
42
|
|
|
add_filter( 'kirki_section_types', array( $this, 'set_section_types' ) ); |
|
43
|
|
|
// Register the new panel types. |
|
44
|
|
|
add_filter( 'kirki_panel_types', array( $this, 'set_panel_types' ) ); |
|
45
|
|
|
// Include the section-type files. |
|
46
|
|
|
add_action( 'customize_register', array( $this, 'include_sections_and_panels' ) ); |
|
47
|
|
|
// Enqueue styles & scripts. |
|
48
|
|
|
add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scrips' ), 999 ); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Gets an instance of this object. |
|
53
|
|
|
* Prevents duplicate instances which avoid artefacts and improves performance. |
|
54
|
|
|
* |
|
55
|
|
|
* @static |
|
56
|
|
|
* @access public |
|
57
|
|
|
* @since 3.0.0 |
|
58
|
|
|
* @return object |
|
59
|
|
|
*/ |
|
60
|
|
|
public static function get_instance() { |
|
61
|
|
|
if ( ! self::$instance ) { |
|
62
|
|
|
self::$instance = new self(); |
|
63
|
|
|
} |
|
64
|
|
|
return self::$instance; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Add the custom section types. |
|
69
|
|
|
* |
|
70
|
|
|
* @access public |
|
71
|
|
|
* @since 3.0.0 |
|
72
|
|
|
* @param array $section_types The registered section-types. |
|
73
|
|
|
* @return array |
|
74
|
|
|
*/ |
|
75
|
|
|
public function set_section_types( $section_types ) { |
|
76
|
|
|
|
|
77
|
|
|
$new_types = array( |
|
78
|
|
|
'kirki-default' => 'Kirki_Sections_Default_Section', |
|
79
|
|
|
'kirki-expanded' => 'Kirki_Sections_Expanded_Section', |
|
80
|
|
|
'kirki-nested' => 'Kirki_Sections_Nested_Section', |
|
81
|
|
|
); |
|
82
|
|
|
return array_merge( $section_types, $new_types ); |
|
83
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Add the custom panel types. |
|
88
|
|
|
* |
|
89
|
|
|
* @access public |
|
90
|
|
|
* @since 3.0.0 |
|
91
|
|
|
* @param array $panel_types The registered section-types. |
|
92
|
|
|
* @return array |
|
93
|
|
|
*/ |
|
94
|
|
|
public function set_panel_types( $panel_types ) { |
|
95
|
|
|
|
|
96
|
|
|
$new_types = array( |
|
97
|
|
|
'kirki-nested' => 'Kirki_Panels_Nested_Panel', |
|
98
|
|
|
); |
|
99
|
|
|
return array_merge( $panel_types, $new_types ); |
|
100
|
|
|
|
|
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
|
|
|
/** |
|
150
|
|
|
* Enqueues any necessary scripts and styles. |
|
151
|
|
|
* |
|
152
|
|
|
* @access public |
|
153
|
|
|
* @since 3.0.0 |
|
154
|
|
|
*/ |
|
155
|
|
|
public function enqueue_scrips() { |
|
156
|
|
|
|
|
157
|
|
|
wp_enqueue_style( 'kirki-custom-sections', trailingslashit( Kirki::$url ) . 'modules/custom-sections/sections.css', array(), KIRKI_VERSION ); |
|
158
|
|
|
wp_enqueue_script( 'kirki-custom-sections', trailingslashit( Kirki::$url ) . 'modules/custom-sections/sections.js', array( 'jquery', 'customize-base', 'customize-controls' ), KIRKI_VERSION ); |
|
159
|
|
|
|
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
} |
|
163
|
|
|
|