ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class-kirki-controls-dropdown-pages-control.php (2566B)


      1 <?php
      2 /**
      3  * Customizer Control: dropdown-pages.
      4  *
      5  * @package     Kirki
      6  * @subpackage  Controls
      7  * @copyright   Copyright (c) 2016, Aristeides Stathopoulos
      8  * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
      9  * @since       2.2.8
     10  */
     11 
     12 // Exit if accessed directly.
     13 if ( ! defined( 'ABSPATH' ) ) {
     14 	exit;
     15 }
     16 
     17 if ( ! class_exists( 'Kirki_Controls_Dropdown_Pages_Control' ) ) {
     18 
     19 	/**
     20 	 * A copy of WordPress core's "dropdown-pages" control.
     21 	 * The template has been converted to use Underscore.js
     22 	 * and we added a tooltip.
     23 	 */
     24 	class Kirki_Controls_Dropdown_Pages_Control extends Kirki_Customize_Control {
     25 
     26 		/**
     27 		 * The control type.
     28 		 *
     29 		 * @access public
     30 		 * @var string
     31 		 */
     32 		public $type = 'kirki-dropdown-pages';
     33 
     34 		/**
     35 		 * Enqueue control related scripts/styles.
     36 		 *
     37 		 * @access public
     38 		 */
     39 		public function enqueue() {
     40 			wp_enqueue_script( 'kirki-dropdown-pages' );
     41 		}
     42 
     43 		/**
     44 		 * Refresh the parameters passed to the JavaScript via JSON.
     45 		 *
     46 		 * @access public
     47 		 */
     48 		public function to_json() {
     49 			parent::to_json();
     50 			$l10n = Kirki_l10n::get_strings( $this->kirki_config );
     51 			$dropdown = wp_dropdown_pages(
     52 				array(
     53 					'name'              => '_customize-dropdown-pages-' . esc_attr( $this->id ),
     54 					'echo'              => 0,
     55 					'show_option_none'  => esc_attr( $l10n['select-page'] ),
     56 					'option_none_value' => '0',
     57 					'selected'          => esc_attr( $this->value() ),
     58 				)
     59 			);
     60 
     61 			// Hackily add in the data link parameter.
     62 			$dropdown = str_replace( '<select', '<select ' . $this->get_link(), $dropdown );
     63 
     64 			$this->json['dropdown'] = $dropdown;
     65 		}
     66 
     67 		/**
     68 		 * An Underscore (JS) template for this control's content (but not its container).
     69 		 *
     70 		 * Class variables for this control class are available in the `data` JS object;
     71 		 * export custom variables by overriding {@see Kirki_Customize_Control::to_json()}.
     72 		 *
     73 		 * @see WP_Customize_Control::print_template()
     74 		 *
     75 		 * @access protected
     76 		 */
     77 		protected function content_template() {
     78 			?>
     79 			<# if ( data.tooltip ) { #>
     80 				<a href="#" class="tooltip hint--left" data-hint="{{ data.tooltip }}"><span class='dashicons dashicons-info'></span></a>
     81 			<# } #>
     82 			<label>
     83 				<# if ( data.label ) { #>
     84 					<span class="customize-control-title">{{{ data.label }}}</span>
     85 				<# } #>
     86 				<# if ( data.description ) { #>
     87 					<span class="description customize-control-description">{{{ data.description }}}</span>
     88 				<# } #>
     89 				<div class="customize-control-content">{{{ data.dropdown }}}</div>
     90 			</label>
     91 			<?php
     92 		}
     93 	}
     94 }