AutoSetting.php (1143B)
1 <?php 2 3 namespace Materialis\Customizer\Settings; 4 5 class AutoSetting extends \Materialis\Customizer\BaseSetting 6 { 7 8 const TYPE = 'cp_auto_setting'; 9 const SETTING_PATTERN = '/CP_AUTO_SETTING\[(.*)\]/s'; 10 11 public function init() 12 { 13 $this->type = self::TYPE; 14 $this->transport = 'postMessage'; 15 } 16 17 public function getRealMod() 18 { 19 $matches = array(); 20 21 if (preg_match(AutoSetting::SETTING_PATTERN, $this->id, $matches)) { 22 $mod = $matches[1]; 23 24 return $mod; 25 } 26 27 return ''; 28 } 29 30 public function update($value) 31 { 32 $mod = $this->getRealMod(); 33 $mod = trim($mod); 34 $this->id = $mod; 35 $this->type = 'theme_mod'; 36 37 return parent::update($value); 38 } 39 40 41 public function value() 42 { 43 // $undefined = new stdClass(); 44 if ($this->is_previewed) { 45 $value = $this->post_value(); 46 } else { 47 $mod = $this->getRealMod(); 48 $value = get_theme_mod($mod, false); 49 } 50 51 return $value; 52 } 53 }