class-kirki-panel.php (1597B)
1 <?php 2 /** 3 * Handles panels added via the Kirki API. 4 * 5 * @package Kirki 6 * @category Core 7 * @author Aristeides Stathopoulos 8 * @copyright Copyright (c) 2016, Aristeides Stathopoulos 9 * @license http://opensource.org/licenses/https://opensource.org/licenses/MIT 10 * @since 1.0 11 */ 12 13 if ( ! class_exists( 'Kirki_Panel' ) ) { 14 15 /** 16 * Each panel is a separate instance of the Kirki_Panel object. 17 */ 18 class Kirki_Panel { 19 20 /** 21 * An array of our panel types. 22 * 23 * @access private 24 * @var array 25 */ 26 private $panel_types = array( 27 'kirki-default' => 'Kirki_Panels_Default_Panel', 28 'kirki-expanded' => 'Kirki_Panels_Expanded_Panel', 29 ); 30 31 /** 32 * The class constructor. 33 * 34 * @access public 35 * @param array $args The panel arguments. 36 */ 37 public function __construct( $args ) { 38 39 $this->panel_types = apply_filters( 'kirki/panel_types', $this->panel_types ); 40 $this->add_panel( $args ); 41 42 } 43 44 /** 45 * Add the panel using the Customizer API. 46 * 47 * @param array $args The panel arguments. 48 */ 49 public function add_panel( $args ) { 50 global $wp_customize; 51 52 if ( ! isset( $args['type'] ) || ! array_key_exists( $args['type'], $this->panel_types ) ) { 53 $args['type'] = 'kirki-default'; 54 } 55 $panel_classname = $this->panel_types[ $args['type'] ]; 56 57 // If we've got an icon then call the object to create its script. 58 if ( isset( $args['icon'] ) ) { 59 Kirki_Scripts_Icons::generate_script( $args ); 60 } 61 62 $wp_customize->add_panel( new $panel_classname( $wp_customize, sanitize_key( $args['id'] ), $args ) ); 63 64 } 65 } 66 }