/**
  * When a gallery is created/edit from dashboard, simulate the same behaviour as front end created galleries
  * 
  * @param type $post_id
  * @param type $post
  * @param type $update
  * @return type
  */
 public function update_gallery_details($post_id, $post, $update)
 {
     if (defined('DOING_AJAX') && DOING_AJAX || !is_admin()) {
         return;
     }
     $type = $this->get_editing_gallery_type();
     $gallery = mpp_get_gallery($post);
     if (empty($gallery->type) && $type) {
         wp_set_object_terms($post_id, mpp_underscore_it($type), mpp_get_type_taxname());
         $gallery->type = $type;
     }
     /**
      * On the front end, we are using the taxonomy term slugs as the value while on the backend we are using the term_id as the value
      * 
      * So, we are attaching this function only for the Dashboar created gallery
      * 
      * We do need to make it uniform in the futuer
      * 
      */
     //we need to set the object terms
     //we need to update the media count?
     //do we need to do anything else?
     //gallery-type
     //gallery-component
     //gallery status
     $type = empty($_POST['mpp-gallery-type']) ? '' : trim($_POST['mpp-gallery-type']);
     $status = empty($_POST['mpp-gallery-status']) ? '' : trim($_POST['mpp-gallery-status']);
     $component = empty($_POST['mpp-gallery-component']) ? '' : trim($_POST['mpp-gallery-component']);
     if ($type && mpp_is_registered_type($type)) {
         wp_set_object_terms($post_id, mpp_underscore_it($type), mpp_get_type_taxname());
     }
     if ($component && mpp_is_registered_component($component)) {
         wp_set_object_terms($post_id, mpp_underscore_it($component), mpp_get_component_taxname());
     }
     if ($status && mpp_is_registered_status($status)) {
         wp_set_object_terms($post_id, mpp_underscore_it($status), mpp_get_status_taxname());
     }
     //update media cout or recount?
     if (!empty($_POST['mpp-gallery-component-id'])) {
         mpp_update_gallery_meta($post_id, '_mpp_component_id', absint($_POST['mpp-gallery-component-id']));
     } else {
         //if component id is not given, check if it is members gallery, if so,
     }
     if (!$update) {
         do_action('mpp_gallery_created', $post_id);
     }
 }
/**
 * Create new Gallery
 * @param type $args
 * @return boolean
 */
function mpp_create_gallery($args = '')
{
    $default = array('id' => false, 'creator_id' => get_current_user_id(), 'title' => '', 'description' => '', 'slug' => '', 'status' => '', 'order' => false, 'component' => false, 'component_id' => false, 'type' => '', 'date_created' => '', 'date_updated' => '');
    //if the gallery id is set
    if (isset($args['id']) && !empty($args['id'])) {
        return mpp_update_gallery($args);
    }
    $args = wp_parse_args($args, $default);
    extract($args);
    $post_data = array('post_type' => mpp_get_gallery_post_type(), 'post_status' => 'publish', 'post_author' => $creator_id, 'post_title' => $title, 'post_content' => $description, 'post_name' => $slug);
    //if no component id is given, assume to be user gallery
    if (!$component_id) {
        $component_id = get_current_user_id();
    }
    //if a component is not given, assume it to be user gallery
    if (!$component) {
        $component = 'members';
    }
    if (!mpp_is_enabled($component, $component_id)) {
        return false;
        // not enabled for this, can not be created
    }
    if (!$type) {
        $type = 'photo';
    }
    $gallery_status = mpp_get_default_status();
    if (!empty($status)) {
        if (mpp_is_registered_status($status)) {
            $gallery_status = $status;
        }
    }
    //hierarchical tax should always pass ids
    $tax = array(mpp_get_component_taxname() => mpp_underscore_it($component), mpp_get_type_taxname() => mpp_underscore_it($type), mpp_get_status_taxname() => mpp_underscore_it($gallery_status));
    $post_data['tax_input'] = $tax;
    if (!empty($date_created)) {
        $post_data['post_date'] = $date_created;
    }
    if (!empty($date_updated)) {
        $post_data['post_modified'] = $date_updated;
    }
    $gallery_id = wp_insert_post($post_data);
    if (is_wp_error($gallery_id)) {
        return false;
        //unable to add gallery
    }
    //otherwise update the meta with component id
    mpp_update_gallery_meta($gallery_id, '_mpp_component_id', $component_id);
    //fire the gallery created action
    do_action('mpp_gallery_created', $gallery_id);
    return $gallery_id;
}