/** * Manage checkboxes on event save. * When an event is saved on the event screen and a checkbox is not checked, * no value is posted and therefore the event meta key is not updated. * * @params obj $post The events WP_POST object * @return void */ function manage_custom_fields_on_event_save($post) { $mdjm_event = new MDJM_Event($post->ID); $query = mdjm_get_custom_fields(); $custom_fields = $query->get_posts(); foreach ($custom_fields as $custom_field) { if ('checkbox' != get_post_meta($custom_field->ID, '_mdjm_field_type', true)) { continue; } $key = '_mdjm_event_' . str_replace('-', '_', $custom_field->post_name); if ($mdjm_event->get_meta($key) && empty($_POST[$key])) { $meta[$key] = ''; } } if (!empty($meta)) { mdjm_update_event_meta($mdjm_event->ID, $meta); } }