ru-se.com

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

BaseControl.php (1281B)


      1 <?php
      2 
      3 namespace Materialis\Customizer;
      4 
      5 class BaseControl extends \WP_Customize_Control
      6 {
      7     protected $cpData = null;
      8 
      9     public function __construct($manager, $id, $cpData = array())
     10     {
     11         $this->cpData = $cpData;
     12         $args         = (isset($this->cpData['wp_data'])) ? $this->cpData['wp_data'] : array();
     13         $args = \Materialis\Companion::translateArgs($args);
     14         $this->type = isset($args['type'])?$args['type']:$this->companion()->customizer()->removeNamespace("\\".get_class($this));
     15 
     16         parent::__construct($manager, $id, $args);
     17 
     18         $this->init();
     19     }
     20 
     21     protected function init()
     22     {
     23         return true;
     24     }
     25 
     26     final protected function companion()
     27     {
     28         return \Materialis\Companion::instance();
     29     }
     30 
     31 
     32     public function alterSourceData($data)
     33     {
     34         return $data;
     35     }
     36 
     37     public function getSourceData()
     38     {
     39         $result = array();
     40 
     41         if (isset($this->cpData['dataSource'])) {
     42             $result = $this->companion()->getCustomizerData($this->cpData['dataSource']);
     43 
     44             if (!$result) {
     45                 $result = array();
     46             }
     47         }
     48 
     49         $result = $this->alterSourceData($result);
     50 
     51         return $result;
     52     }
     53 }