Example #1
0
 /**
  * Save data from meta box
  * @param int $post_id Post ID
  */
 public function save_post($post_id)
 {
     if (!$this->validate()) {
         return;
     }
     $this->saved = true;
     // Make sure meta is added to the post, not a revision
     if ($the_post = wp_is_post_revision($post_id)) {
         $post_id = $the_post;
     }
     // Before save action
     do_action('rwmb_before_save_post', $post_id);
     do_action("rwmb_{$this->meta_box['id']}_before_save_post", $post_id);
     foreach ($this->fields as $field) {
         $single = $field['clone'] || !$field['multiple'];
         $old = get_post_meta($post_id, $field['id'], $single);
         $new = isset($_POST[$field['id']]) ? $_POST[$field['id']] : ($single ? '' : array());
         // Allow field class change the value
         if ($field['clone']) {
             $new = RWMB_Clone::value($new, $old, $post_id, $field);
         } else {
             $new = RWMB_Field::call($field, 'value', $new, $old, $post_id);
             $new = RWMB_Field::filter('sanitize', $new, $field);
         }
         $new = RWMB_Field::filter('value', $new, $field, $old);
         // Call defined method to save meta value, if there's no methods, call common one
         RWMB_Field::call($field, 'save', $new, $old, $post_id);
     }
     // After save action
     do_action('rwmb_after_save_post', $post_id);
     do_action("rwmb_{$this->meta_box['id']}_after_save_post", $post_id);
 }
Example #2
0
 /**
  * Show end HTML markup for fields
  *
  * @param mixed $meta
  * @param array $field
  *
  * @return string
  */
 public static function end_html($meta, $field)
 {
     return RWMB_Clone::add_clone_button($field) . self::call('element_description', $field) . '</div>';
 }