PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.0.13
Kirki – Freeform Page Builder, Website Builder & Customizer v6.0.13
6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / customizer / packages / modules / panels / src / Panel.php
kirki / customizer / packages / modules / panels / src Last commit date
Panel_Types 5 months ago Panel.php 2 months ago
Panel.php
138 lines
1 <?php
2 /**
3 * Creates a new panel.
4 *
5 * @package Kirki
6 * @subpackage Custom Sections Module
7 * @copyright Copyright (c) 2023, Themeum
8 * @license https://opensource.org/licenses/MIT
9 * @since 1.0
10 */
11
12 namespace Kirki;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 /**
19 * Panel.
20 */
21 class Panel {
22
23 /**
24 * The panel ID.
25 *
26 * @access protected
27 * @since 1.0
28 * @var string
29 */
30 protected $id;
31
32 /**
33 * The panel arguments.
34 *
35 * @access protected
36 * @since 1.0
37 * @var array
38 */
39 protected $args;
40
41 /**
42 * An array of our panel types.
43 *
44 * @access private
45 * @var array
46 */
47 private $panel_types = [
48 'default' => 'WP_Customize_Panel',
49 'kirki-nested' => '\Kirki\Panel_Types\Nested',
50 ];
51
52 /**
53 * Constructor.
54 *
55 * @access public
56 * @since 1.0
57 * @param string $id The panel ID.
58 * @param array $args The panel args.
59 */
60 public function __construct( $id, $args = [] ) {
61 $this->id = $id;
62 $this->args = $args;
63
64 $this->panel_types = apply_filters( 'kirki_panel_types', $this->panel_types );
65
66 if ( $this->args ) {
67 add_action( 'customize_register', [ $this, 'add_panel' ] );
68 }
69 add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_scrips' ] );
70 }
71
72 /**
73 * Add the panel using the Customizer API.
74 *
75 * @access public
76 * @since 1.0
77 * @param object $wp_customize The customizer object.
78 */
79 public function add_panel( $wp_customize ) {
80
81 // Figure out the type of this panel.
82 $this->args['type'] = isset( $this->args['type'] ) ? $this->args['type'] : 'default';
83 if ( isset( $this->args['panel'] ) && ! empty( $this->args['panel'] ) ) {
84 $this->args['type'] = 'kirki-nested';
85 }
86 $this->args['type'] = false === strpos( $this->args['type'], 'kirki-' ) ? 'kirki-' . $this->args['type'] : $this->args['type'];
87 $this->args['type'] = 'kirki-default' === $this->args['type'] ? 'default' : $this->args['type'];
88
89 // Get the class we'll be using to create this panel.
90 $panel_classname = $this->panel_types[ $this->args['type'] ];
91
92 // Fallback to the default panel type if the custom class doesn't exist.
93 $panel_classname = class_exists( $panel_classname ) ? $panel_classname : 'WP_Customize_Panel';
94
95 // Add the panel.
96 $wp_customize->add_panel(
97 new $panel_classname(
98 $wp_customize,
99 $this->id,
100 apply_filters( 'kirki_panel_args', $this->args, $this->id )
101 )
102 );
103
104 // Run an action after the panel has been added.
105 do_action( 'kirki_panel_added', $this->id, $this->args );
106 }
107
108 /**
109 * Removes the panel.
110 *
111 * @access public
112 * @since 1.0
113 * @return void
114 */
115 public function remove() {
116 add_action( 'customize_register', [ $this, 'remove_panel' ], 9999 );
117 }
118
119 /**
120 * Add the panel using the Customizer API.
121 *
122 * @access public
123 * @since 1.0
124 * @param object $wp_customize The customizer object.
125 */
126 public function remove_panel( $wp_customize ) {
127 $wp_customize->remove_panel( $this->id );
128 }
129
130 /**
131 * Enqueues any necessary scripts and styles.
132 *
133 * @access public
134 * @since 1.0
135 */
136 public function enqueue_scrips() {
137 }
138 }