class-kirki-section.php (1788B)
1 <?php 2 /** 3 * Handles sections created 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_Section' ) ) { 14 15 /** 16 * Each section is a separate instrance of the Kirki_Section object. 17 */ 18 class Kirki_Section { 19 20 /** 21 * An array of our section types. 22 * 23 * @access private 24 * @var array 25 */ 26 private $section_types = array( 27 'kirki-default' => 'Kirki_Sections_Default_Section', 28 'kirki-expanded' => 'Kirki_Sections_Expanded_Section', 29 'kirki-hover' => 'Kirki_Sections_Hover_Section', 30 ); 31 32 /** 33 * The object constructor. 34 * 35 * @access public 36 * @param array $args The section parameters. 37 */ 38 public function __construct( $args ) { 39 40 $this->section_types = apply_filters( 'kirki/section_types', $this->section_types ); 41 $this->add_section( $args ); 42 43 } 44 45 /** 46 * Adds the section using the WordPress Customizer API. 47 * 48 * @access public 49 * @param array $args The section parameters. 50 */ 51 public function add_section( $args ) { 52 53 global $wp_customize; 54 55 if ( ! isset( $args['type'] ) || ! array_key_exists( $args['type'], $this->section_types ) ) { 56 $args['type'] = 'kirki-default'; 57 } 58 $section_classname = $this->section_types[ $args['type'] ]; 59 60 if ( isset( $args['icon'] ) && ! empty( $args['icon'] ) ) { 61 $args['title'] = '<span class="dashicons ' . esc_attr( $args['icon'] ) . '"></span> ' . esc_html( $args['title'] ); 62 } 63 64 // Add the section. 65 $wp_customize->add_section( new $section_classname( $wp_customize, sanitize_key( $args['id'] ), $args ) ); 66 67 } 68 } 69 }