Beispiel #1
0
 /**
  * Register single page settings based on page contents
  * 
  * @return void
  */
 public function __handleSettingsRegistration()
 {
     // Get tabs
     $tabs = $this->getTabs();
     if (!$tabs) {
         // Get sections & callable
         $sections = $this->getAllSections();
         $function = $this->getFunction();
         $names = [];
         // Fetch control elements name attribute from function
         if ($function) {
             $names += Utils::getControlNamesFromCallable($function, array($this->data, $this));
         }
         // Fetch control elements name attribute from sections
         if ($this->getAllSections()) {
             $names += Utils::getControlNamesFromCallable([$this, '__collectSectionsFieldNames'], array($this->data, $this));
         }
         if ($names) {
             $this->options->pushList($names);
             foreach ($names as $name) {
                 register_setting($this->getId(), $name);
             }
         }
         // Reset sections so that we do not have duplicates
         $this->sections->clear()->pushList($sections);
     }
 }
Beispiel #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);
     }
 }