ru-se.com

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

class-kirki-customize-control.php (7554B)


      1 <?php
      2 /**
      3  * A wrapper class for WP_Customize_Control.
      4  * We'll be using this to define things that all Kirki fields must inherit.
      5  * Helps us keep a cleaner codebase and avoid code duplication.
      6  *
      7  * @package     Kirki
      8  * @subpackage  Controls
      9  * @copyright   Copyright (c) 2016, Aristeides Stathopoulos
     10  * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
     11  * @since       1.0
     12  */
     13 
     14 // Exit if accessed directly.
     15 if ( ! defined('ABSPATH')) {
     16     exit;
     17 }
     18 
     19 if ( ! class_exists('Kirki_Customize_Control')) {
     20 
     21     /**
     22      * The parent class for all Kirki controls.
     23      * Other controls should extend this object.
     24      */
     25     class Kirki_Customize_Control extends WP_Customize_Control
     26     {
     27 
     28         /**
     29          * Tooltips content.
     30          *
     31          * @access public
     32          * @var string
     33          */
     34         public $tooltip = '';
     35 
     36         /**
     37          * Used to automatically generate all postMessage scripts.
     38          *
     39          * @access public
     40          * @var array
     41          */
     42         public $js_vars = array();
     43 
     44         /**
     45          * Used to automatically generate all CSS output.
     46          *
     47          * @access public
     48          * @var array
     49          */
     50         public $output = array();
     51 
     52         /**
     53          * Data type
     54          *
     55          * @access public
     56          * @var string
     57          */
     58         public $option_type = 'theme_mod';
     59 
     60         /**
     61          * The kirki_config we're using for this control
     62          *
     63          * @access public
     64          * @var string
     65          */
     66         public $kirki_config = 'global';
     67 
     68         /**
     69          * The translation strings.
     70          *
     71          * @access protected
     72          * @since  2.3.5
     73          * @var array
     74          */
     75         protected $l10n = array();
     76 
     77         /**
     78          * Constructor.
     79          *
     80          * Supplied `$args` override class property defaults.
     81          *
     82          * If `$args['settings']` is not defined, use the $id as the setting ID.
     83          *
     84          * @since 2.3.5
     85          *
     86          * @param WP_Customize_Manager $manager         Customizer bootstrap instance.
     87          * @param string               $id              Control ID.
     88          * @param array                $args            {
     89          *                                              Optional. Arguments to override class property defaults.
     90          *
     91          * @type int                   $instance_number Order in which this instance was created in relation
     92          *                                                 to other instances.
     93          * @type WP_Customize_Manager  $manager         Customizer bootstrap instance.
     94          * @type string                $id              Control ID.
     95          * @type array                 $settings        All settings tied to the control. If undefined, `$id` will
     96          *                                                 be used.
     97          * @type string                $setting         The primary setting for the control (if there is one).
     98          *                                                 Default 'default'.
     99          * @type int                   $priority        Order priority to load the control. Default 10.
    100          * @type string                $section         Section the control belongs to. Default empty.
    101          * @type string                $label           Label for the control. Default empty.
    102          * @type string                $description     Description for the control. Default empty.
    103          * @type array                 $choices         List of choices for 'radio' or 'select' type controls, where
    104          *                                                 values are the keys, and labels are the values.
    105          *                                                 Default empty array.
    106          * @type array                 $input_attrs     List of custom input attributes for control output, where
    107          *                                                 attribute names are the keys and values are the values. Not
    108          *                                                 used for 'checkbox', 'radio', 'select', 'textarea', or
    109          *                                                 'dropdown-pages' control types. Default empty array.
    110          * @type array                 $json            Deprecated. Use WP_Customize_Control::json() instead.
    111          * @type string                $type            Control type. Core controls include 'text', 'checkbox',
    112          *                                                 'textarea', 'radio', 'select', and 'dropdown-pages'. Additional
    113          *                                                 input types such as 'email', 'url', 'number', 'hidden', and
    114          *                                                 'date' are supported implicitly. Default 'text'.
    115          * }
    116          */
    117         public function __construct($manager, $id, $args = array())
    118         {
    119 
    120             // Call the constructor from the parent class.
    121             parent::__construct($manager, $id, $args);
    122 
    123             // Add translation strings.
    124             $this->l10n = Kirki_l10n::get_strings($this->kirki_config);
    125 
    126         }
    127 
    128         /**
    129          * Refresh the parameters passed to the JavaScript via JSON.
    130          *
    131          * @see WP_Customize_Control::to_json()
    132          */
    133         public function to_json()
    134         {
    135             parent::to_json();
    136 
    137             if (isset($this->default)) {
    138                 $this->json['default'] = $this->default;
    139             } else {
    140                 $this->json['default'] = $this->setting->default;
    141             }
    142             $this->json['js_vars']     = $this->js_vars;
    143             $this->json['output']      = $this->output;
    144             $this->json['value']       = $this->value();
    145             $this->json['choices']     = $this->choices;
    146             $this->json['link']        = $this->get_link();
    147             $this->json['tooltip']     = $this->tooltip;
    148             $this->json['id']          = $this->id;
    149             $this->json['l10n']        = $this->l10n;
    150             $this->json['kirkiConfig'] = $this->kirki_config;
    151 
    152             $field = Kirki::$fields[$this->id];
    153 
    154             if (isset($field['active_callback_vars'])) {
    155                 $this->json['active_callback'] = $field['active_callback_vars'];
    156             }
    157 
    158             if (isset($field['update'])) {
    159                 $this->json['update'] = $field['update'];
    160             }
    161 
    162             if ('user_meta' === $this->option_type) {
    163                 $this->json['value'] = get_user_meta(get_current_user_id(), $this->id, true);
    164             }
    165 
    166             $this->json['inputAttrs'] = '';
    167             foreach ($this->input_attrs as $attr => $value) {
    168                 $this->json['inputAttrs'] .= $attr . '="' . esc_attr($value) . '" ';
    169             }
    170 
    171         }
    172 
    173         /**
    174          * Renders the control wrapper and calls $this->render_content() for the internals.
    175          */
    176         protected function render()
    177         {
    178             $id    = 'customize-control-' . str_replace(array('[', ']'), array('-', ''), $this->id);
    179             $class = 'customize-control customize-control-kirki customize-control-' . $this->type;
    180             ?>
    181         <li id="<?php echo esc_attr($id); ?>" class="<?php echo esc_attr($class); ?>">
    182             <?php $this->render_content(); ?>
    183             </li><?php
    184         }
    185 
    186         /**
    187          * Render the control's content.
    188          *
    189          * @see WP_Customize_Control::render_content()
    190          */
    191         protected function render_content()
    192         {
    193         }
    194 
    195         public static function load(){
    196 
    197         }
    198     }
    199 }