/**
  * When the post is saved, save the custom data contained in the meta box.
  *
  * @since 0.1.0
  * @param int $post_id The ID of the post being saved.
  */
 public function save($post_id)
 {
     if (!ev_user_can_save($post_id, 'ev_meta_box')) {
         return;
     }
     $elements = $this->elements();
     if (!empty($elements)) {
         $skip_field_types = ev_skip_on_saving_field_types();
         foreach ($elements as $index => $element) {
             if ($element['type'] === 'group') {
                 foreach ($element['fields'] as $field) {
                     if (!ev_is_skipped_on_saving($field['type'])) {
                         if (!isset($_POST[$field['handle']])) {
                             delete_post_meta($post_id, $field['handle']);
                         } else {
                             $this->_save_single_field($post_id, $field, $_POST[$field['handle']]);
                         }
                     }
                 }
             } else {
                 if (!ev_is_skipped_on_saving($element['type'])) {
                     if (!isset($_POST[$element['handle']])) {
                         delete_post_meta($post_id, $element['handle']);
                     } else {
                         $this->_save_single_field($post_id, $element, $_POST[$element['handle']]);
                     }
                 }
             }
         }
     }
 }
Example #2
0
/**
 * Check if a particular field type should be skipped upon saving a meta box or
 * a page.
 *
 * @since 0.1.0
 * @param string $type The field type.
 * @return boolean
 */
function ev_is_skipped_on_saving($type)
{
    $skip_field_types = ev_skip_on_saving_field_types();
    return in_array($type, $skip_field_types);
}