ru-se.com

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

BasePanel.php (2306B)


      1 <?php
      2 
      3 namespace Materialis\Customizer;
      4 
      5 class BasePanel extends \WP_Customize_Panel
      6 {
      7     protected $cpData = null;
      8 
      9     public function __construct($manager, $id, $cpData = array())
     10     {
     11         $this->cpData = $cpData;
     12 
     13         $args       = (isset($this->cpData['wp_data'])) ? $this->cpData['wp_data'] : array();
     14         $args = \Materialis\Companion::translateArgs($args);
     15         $this->type = $this->companion()->customizer()->removeNamespace("\\".get_class($this));
     16 
     17         parent::__construct($manager, $id, $args);
     18 
     19         if (!$this->isClassic()) {
     20             $this->manager->register_panel_type("\\".get_class($this));
     21         }
     22 
     23 
     24         $this->init();
     25     }
     26 
     27     protected function init()
     28     {
     29         return true;
     30     }
     31 
     32     final protected function companion()
     33     {
     34         return \Materialis\Companion::instance();
     35     }
     36 
     37     public function active_callback()
     38     {
     39         return !$this->isDisabled();
     40     }
     41 
     42     public function addSections($data)
     43     {
     44         if ($this->isDisabled()) {
     45             return;
     46         }
     47 
     48 
     49         $customizerData = $this->companion()->customizer()->cpData['customizer'];
     50 
     51         if (!isset($customizerData['sections'])) {
     52             $customizerData['sections'] = array();
     53         }
     54 
     55         $customizerData['sections'] =  \Materialis\Utils\Utils::mergeArrays($data, $customizerData['sections']);
     56 
     57         $this->companion()->customizer()->cpData['customizer'] = $customizerData;
     58     }
     59 
     60     public function addSettings($data)
     61     {
     62         if ($this->isDisabled()) {
     63             return;
     64         }
     65 
     66         $customizerData = $this->companion()->customizer()->cpData['customizer'];
     67 
     68         if (!isset($customizerData['settings'])) {
     69             $customizerData['settings'] = array();
     70         }
     71 
     72         $customizerData['settings'] = \Materialis\Utils\Utils::mergeArrays($data, $customizerData['settings']);
     73 
     74         $this->companion()->customizer()->cpData['customizer'] = $customizerData;
     75     }
     76 
     77     public function isClassic()
     78     {
     79         return (isset($this->cpData['mode']) && $this->cpData['mode'] === "classic");
     80     }
     81 
     82     public function isDisabled()
     83     {
     84         return (isset($this->cpData['disabled']) && $this->cpData['disabled'] === true);
     85     }
     86 }