Esempio n. 1
0
 public static function camelBackKeys($arr, $default = null)
 {
     if (!self::isAssoc($arr)) {
         return $default;
     }
     $buffer = array();
     foreach ($arr as $key => $value) {
         $camelBackKey = tad_Str::camelBack($key);
         $buffer[$camelBackKey] = $value;
     }
     return $buffer;
 }
 public function register($wp_customize)
 {
     // set the arguments for the section
     $arguments = array('title' => $this->sectionTitle, 'priority' => $this->priority, 'capability' => 'edit_theme_options');
     if (!is_null($this->description)) {
         $arguments['description'] = $this->functions->__($this->description, $this->domain);
     }
     // do not add empty sections
     if (!count($this->settings)) {
         return;
     }
     // add this section
     $wp_customize->add_section($this->sectionId, $arguments);
     // add each setting
     foreach ($this->settings as $id => $arguments) {
         // some defaults are used here
         $settingArguments = array('default' => $arguments['default'], 'type' => 'option', 'capability' => 'edit_theme_options');
         // will add setting for 'some plugin' in
         // 'some_plugin[some_option]'
         $settingFullId = $this->sectionId . '[' . $id . ']';
         $wp_customize->add_setting($settingFullId, $settingArguments);
         // add the control with 'some_plugin_some_option' id
         $type = $arguments['controlType'];
         $label = $arguments['label'];
         $controlArguments = array('label' => $this->functions->__($label, $this->domain), 'section' => $this->sectionId, 'settings' => $settingFullId, 'type' => $type);
         if (isset($arguments['choices'])) {
             $controlArguments['choices'] = $arguments['choices'];
         }
         if (is_array($this->customControls) and array_key_exists($type, $this->customControls)) {
             // 'type' will be the slug the custom control is memorized with
             // an autoloader is supposed to be in place
             // or an exception will happily be thrown
             $controlClass = $this->customControls[$type];
             $wp_customize->add_control(new $controlClass($wp_customize, $id, $controlArguments));
         } elseif (in_array($type, $this->classControlTypes)) {
             $className = 'WP_Customize_' . tad_Str::ucfirstUnderscore($type) . '_Control';
             $wp_customize->add_control(new $className($wp_customize, $id, $controlArguments));
         } else {
             $wp_customize->add_control($this->sectionId . '_' . $id, $controlArguments);
         }
     }
 }