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) 2016, 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
|
|
|
* Constructor. |
26
|
|
|
* |
27
|
|
|
* @access public |
28
|
|
|
* @since 3.0.0 |
29
|
|
|
*/ |
30
|
|
|
public function __construct() { |
31
|
|
|
|
32
|
|
|
// Register the new section types. |
33
|
|
|
add_filter( 'kirki/section_types', array( $this, 'set_section_types' ) ); |
34
|
|
|
|
35
|
|
|
// Register the new panel types. |
36
|
|
|
add_filter( 'kirki/panel_types', array( $this, 'set_panel_types' ) ); |
37
|
|
|
|
38
|
|
|
// Include the section-type files. |
39
|
|
|
add_action( 'customize_register', array( $this, 'include_sections_and_panels' ) ); |
40
|
|
|
|
41
|
|
|
// Enqueue styles & scripts. |
42
|
|
|
add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scrips' ), 999 ); |
43
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Add the custom section types. |
48
|
|
|
* |
49
|
|
|
* @access public |
50
|
|
|
* @since 3.0.0 |
51
|
|
|
* @param array $section_types The registered section-types. |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
|
|
public function set_section_types( $section_types ) { |
55
|
|
|
|
56
|
|
|
$new_types = array( |
57
|
|
|
'kirki-default' => 'Kirki_Sections_Default_Section', |
58
|
|
|
'kirki-expanded' => 'Kirki_Sections_Expanded_Section', |
59
|
|
|
'kirki-nested' => 'Kirki_Sections_Nested_Section', |
60
|
|
|
); |
61
|
|
|
return array_merge( $section_types, $new_types ); |
62
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Add the custom panel types. |
67
|
|
|
* |
68
|
|
|
* @access public |
69
|
|
|
* @since 3.0.0 |
70
|
|
|
* @param array $panel_types The registered section-types. |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
public function set_panel_types( $panel_types ) { |
74
|
|
|
|
75
|
|
|
$new_types = array( |
76
|
|
|
'kirki-nested-panel' => 'Kirki_Sections_Nested_Panel', |
77
|
|
|
); |
78
|
|
|
return array_merge( $panel_types, $new_types ); |
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Include the custom-section classes. |
84
|
|
|
* |
85
|
|
|
* @access public |
86
|
|
|
* @since 3.0.0 |
87
|
|
|
*/ |
88
|
|
|
public function include_sections_and_panels() { |
89
|
|
|
|
90
|
|
|
// Sections. |
91
|
|
|
$folder_path = dirname( __FILE__ ) . '/sections/'; |
92
|
|
|
$section_types = apply_filters( 'kirki/section_types', array() ); |
93
|
|
|
|
94
|
|
|
foreach ( $section_types as $id => $class ) { |
95
|
|
|
if ( ! class_exists( $class ) ) { |
96
|
|
|
$path = wp_normalize_path( $folder_path . 'class-kirki-sections-' . $id . '-section.php' ); |
97
|
|
|
if ( file_exists( $path ) ) { |
98
|
|
|
include_once $path; |
99
|
|
|
continue; |
100
|
|
|
} |
101
|
|
|
$path = str_replace( 'class-kirki-sections-kirki-', 'class-kirki-sections-', $path ); |
102
|
|
|
if ( file_exists( $path ) ) { |
103
|
|
|
include_once $path; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
// Panels. |
109
|
|
|
$folder_path = dirname( __FILE__ ) . '/panels/'; |
110
|
|
|
$panel_types = apply_filters( 'kirki/panel_types', array() ); |
111
|
|
|
|
112
|
|
|
foreach ( $panel_types as $id => $class ) { |
113
|
|
|
if ( ! class_exists( $class ) ) { |
114
|
|
|
$path = wp_normalize_path( $folder_path . 'class-kirki-panels-' . $id . '-panel.php' ); |
115
|
|
|
if ( file_exists( $path ) ) { |
116
|
|
|
include_once $path; |
117
|
|
|
continue; |
118
|
|
|
} |
119
|
|
|
$path = str_replace( 'class-kirki-panels-kirki-', 'class-kirki-panels-', $path ); |
120
|
|
|
if ( file_exists( $path ) ) { |
121
|
|
|
include_once $path; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Enqueues any necessary scripts and styles. |
130
|
|
|
* |
131
|
|
|
* @access public |
132
|
|
|
* @since 3.0.0 |
133
|
|
|
*/ |
134
|
|
|
public function enqueue_scrips() { |
135
|
|
|
|
136
|
|
|
wp_enqueue_style( 'kirki-custom-sections', trailingslashit( Kirki::$url ) . 'modules/custom-sections/sections.css' ); |
137
|
|
|
wp_enqueue_script( 'kirki-custom-sections', trailingslashit( Kirki::$url ) . 'modules/custom-sections/sections.js', array( 'jquery', 'customize-base', 'customize-controls' ) ); |
138
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
} |
142
|
|
|
|