示例#1
0
 /**
  * Registers grouped settings
  * 
  * @return void
  */
 public function __handleSettingsRegistration()
 {
     // Get sections & callable
     $sections = $this->sections->getAll();
     $function = $this->getFunction();
     $names = [];
     // Fetch control elements name attribute from function
     if ($function) {
         $names += Utils::getControlNamesFromCallable($function, array($this->data, $this));
         if ($names) {
             $this->setOptions($names);
         }
     }
     // Fetch control elements name attribute from sections
     if ($sections) {
         $names += Utils::getControlNamesFromCallable([$this, '__collectSectionsFieldNames'], array($this->data, $this));
         if ($names) {
             $this->setOptions($names);
         }
     }
     $options = $this->options->getAll();
     if ($options) {
         foreach ($options as $option) {
             register_setting($this->getId(), $option);
         }
     }
     // Reset sections so that we do not have duplicates
     $this->sections->clear()->pushList($sections);
 }
示例#2
0
 /**
  * Gets field names from callback function
  * 
  */
 private function __setMetaFields()
 {
     // Only execute if there are no manually defined meta fields
     if (!$this->meta_fields->getAll()) {
         // Set callable arguments
         $args = array($this->data, new \WP_Post(new \stdClass()), $this);
         // Collect current sections
         $sections = $this->sections->getAll();
         if ($callback = $this->getCallback()) {
             // Collect field names from callable
             $names = Utils::getControlNamesFromCallable($callback, $args);
             $this->meta_fields->pushList($names);
         }
         if ($this->getAllSections()) {
             $names = Utils::getControlNamesFromCallable([$this, '__collectSectionsFieldNames'], $args);
             $this->meta_fields->pushList($names);
         }
         // Reset sections so that we do not have duplicates
         $this->sections->clear()->pushList($sections);
     }
 }