示例#1
0
 /**
  * Runs validate, then save on $_POST data
  *
  * @param  int $post_ID The id of the object we're saving
  * @return void
  */
 public function validate_and_save($post_ID)
 {
     if (empty($this->fields)) {
         wp_die("Empty fields array");
     }
     // create an array that will be saved
     $validated = array();
     // duplicate metabox's fields to modify to match with $_POST array's keys
     $saved = array();
     foreach (array_keys($this->fields) as $key) {
         //verify meta_key/slug/taxonomy and assign keys
         $this->fields[$key]['old_key'] = Models::validate_keys($this->fields[$key]);
         $this->fields[$key]['key'] = $this->fields[$key]['old_key'];
         //create keys in array that are to be saved
         $validated[$this->fields[$key]['old_key']] = "";
         // retrieve saved data
         $saved[$this->fields[$key]['old_key']] = get_post_meta($post_ID, $this->fields[$key]['old_key'], $single = true);
         //start validation
         $this->validate($post_ID, $this->fields[$key], $validated[$this->fields[$key]['old_key']], $saved[$this->fields[$key]['old_key']]);
     }
     // delete old formatted data for phasing out backwards compatibility
     $this->delete_old_data($post_ID, $this->fields);
     Models::save($post_ID, $validated);
 }
示例#2
0
 public function ready_and_print_html($post, $fields)
 {
     $ID = get_the_ID();
     $fields = $fields['args'];
     $saved = array();
     foreach ($fields as $field) {
         $field['old_key'] = Models::validate_keys($field);
         $field['key'] = $field['old_key'];
         $saved[$field['old_key']] = get_post_meta($ID, $field['old_key'], $single = true);
         if (in_array($field['type'], array('link', 'multiselect', 'post_multiselect'))) {
             $existing = get_post_meta($ID, $field['key'], false);
             if ($existing and !is_array($existing[0])) {
                 $saved[$field['old_key']] = $existing;
             }
         }
         $this->process_defaults($ID, $field, $saved[$field['old_key']]);
         $this->HTML->draw($field);
     }
 }