/** * This little code saves around 55 queries * WordPress does not allow bulk term insert and the queries to insert terms are inefficient * MediaPress * @global WPDB $wpdb * @return type */ function mpp_install_terms() { $type_taxname = mpp_get_type_taxname(); $component_taxname = mpp_get_component_taxname(); $status_taxname = mpp_get_status_taxname(); //All our terms and their tax info $terms_info = array('_sitewide' => array('name' => __('Sitewide Galleries', 'mediapress'), 'description' => __('Sitewide Galleries', 'mediapress'), 'taxonomy' => $component_taxname), '_members' => array('name' => __('User', 'mediapress'), 'description' => __('User Galleries', 'mediapress'), 'taxonomy' => $component_taxname), '_groups' => array('name' => __('Groups', 'mediapress'), 'description' => __('Groups Galleries', 'mediapress'), 'taxonomy' => $component_taxname), '_public' => array('name' => __('Public', 'mediapress'), 'description' => __('Public Gallery Privacy Type', 'mediapress'), 'taxonomy' => $status_taxname), '_private' => array('name' => __('Private', 'mediapress'), 'description' => __('Private Gallery Privacy Type', 'mediapress'), 'taxonomy' => $status_taxname), '_loggedin' => array('name' => __('Logged In Users Only', 'mediapress'), 'description' => __('Logged In Users Only Privacy Type', 'mediapress'), 'taxonomy' => $status_taxname), '_groupsonly' => array('name' => __('Logged In Users Only', 'mediapress'), 'description' => __('Logged In Users Only Privacy Type', 'mediapress'), 'taxonomy' => $status_taxname), '_friendsonly' => array('name' => __('Friends Only', 'mediapress'), 'description' => __('Friends Only Privacy Type', 'mediapress'), 'taxonomy' => $status_taxname), '_followersonly' => array('name' => __('Followers Only', 'mediapress'), 'description' => __('Followers Only Privacy Type', 'mediapress'), 'taxonomy' => $status_taxname), '_followingonly' => array('name' => __('Persons I Follow', 'mediapress'), 'description' => __('Following Only Privacy Type', 'mediapress'), 'taxonomy' => $status_taxname), '_photo' => array('name' => __('Photo', 'mediapress'), 'description' => __('taxonomy for image media type', 'mediapress'), 'taxonomy' => $type_taxname), '_video' => array('name' => __('Video', 'mediapress'), 'description' => __('taxonomy for video media type', 'mediapress'), 'taxonomy' => $type_taxname), '_audio' => array('name' => __('Audio', 'mediapress'), 'description' => __('taxonomy for audio media type', 'mediapress'), 'taxonomy' => $type_taxname), '_doc' => array('name' => __('Documents', 'mediapress'), 'description' => __('taxonomy for documents media type', 'mediapress'), 'taxonomy' => $type_taxname)); //get the term slugs $terms = array_keys($terms_info); //we don't need it but let us keep it $terms = array_map('esc_sql', $terms); //building a list of strings that can be used in the SQL IN clause $list = '("' . join('","', $terms) . '")'; global $wpdb; //get all terms from our list that already exists in database $query = "SELECT slug FROM {$wpdb->terms} WHERE slug IN {$list}"; $existing = $wpdb->get_col($query); $non_existing_terms = array_diff($terms, $existing); if (empty($non_existing_terms)) { return; //no need to do anything as all of our terms already exists } //if we are here, we have a list of term slugs that do nt exist in database and we need to insert them $term_group_id = 0; //let us build the bulk insert query $terms_insert_query = "INSERT INTO {$wpdb->terms} ( name, slug, term_group) VALUES "; $values = array(); foreach ($non_existing_terms as $insertable_term) { $current_term = $terms_info[$insertable_term]; $values[] = $wpdb->prepare('( %s, %s, %d)', $current_term['name'], $insertable_term, $term_group_id); } $values = join(',', $values) . ';'; $terms_insert_query = $terms_insert_query . $values; //insert $wpdb->query($terms_insert_query); //now, we look into wp_terms table for these terms and get the term_id $list_nonexisting = '("' . join('","', $non_existing_terms) . '")'; $query = "SELECT term_id, slug FROM {$wpdb->terms} WHERE slug IN {$list_nonexisting}"; $terms_found = $wpdb->get_results($query); if (empty($terms_found)) { return; //not likely but in case our earlier insert was unsuccesful } //let us do a bulk insert into term_taxonomy table $terms_tax_insert_query = "INSERT INTO {$wpdb->term_taxonomy} ( term_id, taxonomy, description, parent, count ) VALUES "; $values = array(); foreach ($terms_found as $found_term) { $values[] = $wpdb->prepare('( %d, %s, %s, %d, %d )', $found_term->term_id, $terms_info[$found_term->slug]['taxonomy'], $terms_info[$found_term->slug]['description'], 0, 0); } $values = join(',', $values) . ';'; $terms_tax_insert_query = $terms_tax_insert_query . $values; $wpdb->query($terms_tax_insert_query); //that's all folks, we are all good now :) }
public function register_taxonomies() { //register type //register status // register component $this->register_taxonomy(mpp_get_type_taxname(), array('label' => _x('Media Type', 'Gallery Media Type', 'mediapress'), 'labels' => _x('Media Types', 'Gallery Media Type Plural Name', 'mediapress'), 'hierarchical' => false)); $this->register_taxonomy(mpp_get_component_taxname(), array('label' => _x('Component', 'Gallery Associated Type', 'mediapress'), 'labels' => _x('Components', 'Gallery Associated Component Plural Name', 'mediapress'), 'hierarchical' => false)); $this->register_taxonomy(mpp_get_status_taxname(), array('label' => _x('Gallery Status', 'Gallery privacy/status Type', 'mediapress'), 'labels' => _x('Galery Statuses', 'Gallery Privacy Plural Name', 'mediapress'), 'hierarchical' => false)); register_taxonomy_for_object_type(mpp_get_type_taxname(), mpp_get_gallery_post_type()); register_taxonomy_for_object_type(mpp_get_component_taxname(), mpp_get_gallery_post_type()); register_taxonomy_for_object_type(mpp_get_status_taxname(), mpp_get_gallery_post_type()); register_taxonomy_for_object_type(mpp_get_type_taxname(), mpp_get_media_post_type()); register_taxonomy_for_object_type(mpp_get_component_taxname(), mpp_get_media_post_type()); register_taxonomy_for_object_type(mpp_get_status_taxname(), mpp_get_media_post_type()); }
function mpp_filter_archive_page_galleries($query) { if (is_admin()) { return; } if (!$query->is_main_query() || !$query->is_post_type_archive(mpp_get_gallery_post_type())) { return; } //confirmed that we are on gallery archive page $active_components = mpp_get_active_components(); $active_types = mpp_get_active_types(); $status = 'public'; $tax_query = $query->get('tax_query'); if (empty($tax_query)) { $tax_query = array(); } //it will be always true if ($status) { $status = mpp_string_to_array($status); //future proofing $status_keys = array_map('mpp_underscore_it', $status); $tax_query[] = array('taxonomy' => mpp_get_status_taxname(), 'field' => 'slug', 'terms' => $status_keys, 'operator' => 'IN'); } //should we only show sitewide galleries here? will update based on feedback if (!empty($active_components)) { $component_keys = array_keys($active_components); $component_keys = array_map('mpp_underscore_it', $component_keys); $tax_query[] = array('taxonomy' => mpp_get_component_taxname(), 'field' => 'slug', 'terms' => $component_keys, 'operator' => 'IN'); } if (!empty($active_types)) { $type_keys = array_keys($active_types); $type_keys = array_map('mpp_underscore_it', $type_keys); $tax_query[] = array('taxonomy' => mpp_get_type_taxname(), 'field' => 'slug', 'terms' => $type_keys, 'operator' => 'IN'); } if (count($tax_query) > 1) { $tax_query['relation'] = 'AND'; } $query->set('tax_query', $tax_query); $query->set('update_post_term_cache', true); $query->set('update_post_meta_cache', true); $query->set('cache_results', true); }
/** * 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); } }
/** * Register a new Associated/Supported component * * @param type $args */ function mpp_register_component($args) { $default = array('key' => '', 'label' => '', 'labels' => array(), 'description' => ''); $args = wp_parse_args($args, $default); //extract( $args ); $key = $args['key']; if (empty($key) || empty($args['label'])) { _doing_it_wrong(__FUNCTION__, __('You must provide valid key and label for associated component.', 'mediapress'), '1.0'); } $mediapress = mediapress(); //if it was not already registered if (!isset($mediapress->components[$key])) { $term_slug = mpp_underscore_it($key); $taxonomy = mpp_get_component_taxname(); //if the terms does not exists, add it if (!mpp_term_exists($term_slug, $taxonomy)) { wp_insert_term($args['label'], $taxonomy, array('slug' => $term_slug, 'description' => $args['description'])); } $component_object = new MPP_Component(array('key' => $key, 'label' => $args['label'], 'labels' => $args['labels'])); $mediapress->components[$key] = $component_object; } }
public function __construct($args) { parent::__construct($args, mpp_get_component_taxname()); $this->features = new MPP_Features(); }
/** * Map gallery parameters to wp_query native parameters * * @param type $args * @return string */ public function build_params($args) { $defaults = array('type' => array_keys(mpp_get_active_types()), 'id' => false, 'in' => false, 'exclude' => false, 'slug' => false, 'status' => array_keys(mpp_get_active_statuses()), 'component' => array_keys(mpp_get_active_components()), 'component_id' => false, 'per_page' => mpp_get_option('galleries_per_page'), 'offset' => false, 'page' => false, 'nopaging' => false, 'order' => 'DESC', 'orderby' => 'date', 'user_id' => false, 'include_users' => false, 'exclude_users' => false, 'user_name' => false, 'scope' => false, 'search_terms' => '', 'year' => false, 'month' => false, 'week' => '', 'day' => '', 'hour' => '', 'minute' => '', 'second' => '', 'yearmonth' => false, 'fields' => false); //build params for WP_Query $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); //build the wp_query args $wp_query_args = array('post_type' => mpp_get_gallery_post_type(), 'post_status' => 'any', 'p' => $id, 'post__in' => $in, 'post__not_in' => $exclude, 'name' => $slug, 'posts_per_page' => $per_page, 'paged' => $page, 'offset' => $offset, 'nopaging' => $nopaging, 'author' => $user_id, 'author_name' => $user_name, 'author__in' => $include_users, 'author__not_in' => $exclude_users, 'year' => $year, 'monthnum' => $month, 'w' => $week, 'day' => $day, 'hour' => $hour, 'minute' => $minute, 'second' => $second, 'm' => $yearmonth, 'order' => $order, 'orderby' => $orderby, 's' => $search_terms, 'fields' => $fields, '_mpp_mapped_query' => true); $tax_query = array(); $gmeta_query = array(); //meta if (isset($meta_key) && $meta_key) { $wp_query_args['meta_key'] = $meta_key; } if (isset($meta_value)) { $wp_query_args['meta_value'] = $meta_value; } if (isset($meta_query)) { $gmeta_query = $meta_query; } //TODO: SCOPE // //we will need to build tax query/meta query //type, audio video etc //if type is given and it is valid gallery type //Pass one or more types //should we restrict to active types only here? I guss no, Insteacd the calling scope should take care of that if (!empty($type) && mpp_are_registered_types($type)) { $type = mpp_string_to_array($type); $type = array_map('mpp_underscore_it', $type); $tax_query[] = array('taxonomy' => mpp_get_type_taxname(), 'field' => 'slug', 'terms' => $type, 'operator' => 'IN'); } //privacy //pass ne or more privacy level if (!empty($status) && mpp_are_registered_statuses($status)) { $status = mpp_string_to_array($status); $status = array_map('mpp_underscore_it', $status); $tax_query[] = array('taxonomy' => mpp_get_status_taxname(), 'field' => 'slug', 'terms' => $status, 'operator' => 'IN'); } if (!empty($component) && mpp_are_registered_components($component)) { $component = mpp_string_to_array($component); $component = array_map('mpp_underscore_it', $component); $tax_query[] = array('taxonomy' => mpp_get_component_taxname(), 'field' => 'slug', 'terms' => $component, 'operator' => 'IN'); } //done with the tax query if (count($tax_query) > 1) { $tax_query['relation'] = 'AND'; } $wp_query_args['tax_query'] = $tax_query; // print_nice($wp_query_args); //meta query //now, for component if (!empty($component_id)) { $meta_compare = '='; if (is_array($component_id)) { $meta_compare = 'IN'; } $gmeta_query[] = array('key' => '_mpp_component_id', 'value' => $component_id, 'compare' => $meta_compare, 'type' => 'UNSIGNED'); } //reset meta query if (!empty($gmeta_query)) { $wp_query_args['meta_query'] = $gmeta_query; } // print_r($wp_query_args); return $wp_query_args; }
/** * Translates our terminology to internal taxonomy( for e.f component translates to mpp-component and so on ) * @param string $name * @return type */ function mpp_translate_to_taxonomy($name) { $tax_name = ''; /** * @todo Think about the possiblity to name the functions dynamicallly like mpp_get_{$name}_taxname() for flexibility */ if ($name == 'component') { $tax_name = mpp_get_component_taxname(); } elseif ($name == 'type') { $tax_name = mpp_get_type_taxname(); } elseif ($name == 'status') { $tax_name = mpp_get_status_taxname(); } return $tax_name; }
/** * Get term_id for the term that represents the current component associated with a post object(could be gallery|attachment) * * @param mixed|int| MPP_Gallery|MPP_Media object * @return int component type ID(term id for the type associated with this post) */ function mpp_get_object_component_term_id($object) { return _mpp_get_object_term_id($object, mpp_get_component_taxname()); }
function mpp_update_media($args = null) { //updating media can not change the Id & SRC, so if (!isset($args['id'])) { return false; } $default = array('user_id' => get_current_user_id(), 'gallery_id' => false, 'post_parent' => false, 'is_orphan' => false, 'is_uploaded' => '', 'is_remote' => '', 'is_imorted' => '', 'is_embedded' => '', 'embed_url' => '', 'embed_html' => '', 'component_id' => '', 'component' => '', 'context' => '', 'status' => '', 'type' => '', 'storage_method' => '', 'mime_type' => '', 'description' => '', 'sort_order' => 0); $args = wp_parse_args($args, $default); extract($args); //print_r($args ); //return ; if (!$title) { return false; } $post_data = get_post($id, ARRAY_A); if (!$gallery_id) { $gallery_id = $post_data['post_parent']; } if ($title) { $post_data['post_title'] = $title; } if ($description) { $post_data['post_content'] = $description; } if ($gallery_id) { $post_data['post_parent'] = $gallery_id; } //check if the gallery is sorted and the sorting order is not set explicitly //we update it if (!$sort_order && !$post_data['menu_order'] && mpp_is_gallery_sorted($gallery_id)) { //current max sort order +1 $sort_order = (int) mpp_get_max_media_order($gallery_id) + 1; } if ($sort_order) { $post_data['menu_order'] = absin($sort_order); } // Save the data $id = wp_insert_attachment($post_data, false, $gallery_id); if (!is_wp_error($id)) { //set component if ($component) { wp_set_object_terms($id, mpp_underscore_it($component), mpp_get_component_taxname()); } //set _component_id meta key user_id/gallery_id/group id etc if ($component_id) { mpp_update_media_meta($id, '_mpp_component_id', $component_id); } //set upload context if ($context) { mpp_update_media_meta($id, '_mpp_context', $context); } //set media privacy if ($status) { wp_set_object_terms($id, mpp_underscore_it($status), mpp_get_status_taxname()); } //set media type internally as audio/video etc if ($type) { wp_set_object_terms($id, mpp_underscore_it($type), mpp_get_type_taxname()); } // if ($storage_method) { mpp_update_media_meta($id, '_mpp_storage_method', $storage_method); } // //add all extraz here if ($is_orphan) { mpp_update_media_meta($id, '_mpp_is_orphan', $is_orphan); } else { mpp_delete_media_meta($id, '_mpp_is_orphan'); } do_action('mpp_media_updated', $id, $gallery_id); return $id; } return false; // there was an error }
/** * * @param type $taxonomy the name of actual WordPress taxonomy we use for various mpp related things * * @return MPP_Taxonomy[] */ function mpp_get_terms_data($taxonomy) { $data = array(); if (empty($taxonomy)) { return $data; } switch ($taxonomy) { case mpp_get_status_taxname(): $data = mediapress()->statuses; break; case mpp_get_type_taxname(): $data = mediapress()->types; break; case mpp_get_component_taxname(): $data = mediapress()->components; break; } return $data; }
public function build_params($args) { $defaults = array('type' => array_keys(mpp_get_active_types()), 'id' => false, 'in' => false, 'exclude' => false, 'slug' => false, 'status' => array_keys(mpp_get_active_statuses()), 'component' => array_keys(mpp_get_active_components()), 'component_id' => false, 'gallery_id' => false, 'galleries' => false, 'galleries_exclude' => false, 'storage' => '', 'per_page' => mpp_get_option('media_per_page'), 'offset' => false, 'page' => false, 'nopaging' => false, 'order' => 'DESC', 'orderby' => false, 'user_id' => false, 'user_name' => false, 'scope' => false, 'search_terms' => '', 'year' => false, 'month' => false, 'week' => '', 'day' => '', 'hour' => '', 'minute' => '', 'second' => '', 'yearmonth' => '', 'meta_query' => false, 'fields' => false); //build params for WP_Query /** * If are querying for a single gallery * and the gallery media were sorted by the user, show the media s in the sort order insted of the default date */ if (isset($args['gallery_id']) && mpp_is_gallery_sorted($args['gallery_id'])) { $defaults['orderby'] = 'menu_order'; } $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); //build the wp_query args $wp_query_args = array('post_type' => mpp_get_media_post_type(), 'post_status' => 'any', 'p' => $id, 'post__in' => $in, 'post__not_in' => $exclude, 'name' => $slug, 'post_parent' => $gallery_id, 'post_parent__in' => !empty($galleries) ? (array) $galleries : 0, 'post_parent__not_in' => !empty($galleries_exclude) ? (array) $galleries_exclude : 0, 'posts_per_page' => $per_page, 'paged' => $page, 'offset' => $offset, 'nopaging' => $nopaging, 'author' => $user_id, 'author_name' => $user_name, 'year' => $year, 'monthnum' => $month, 'w' => $week, 'day' => $day, 'hour' => $hour, 'minute' => $minute, 'second' => $second, 'm' => $yearmonth, 'order' => $order, 'orderby' => $orderby, 's' => $search_terms, 'fields' => $fields, '_mpp_mapped_query' => true); //TODO: SCOPE // //we will need to build tax query/meta query //taxonomy query to filter by component|status|privacy $tax_query = array(); //meta query $gmeta_query = array(); if (isset($meta_key) && $meta_key) { $wp_query_args['meta_key'] = $meta_key; } if (isset($meta_key) && $meta_key && isset($meta_value)) { $wp_query_args['meta_value'] = $meta_value; } //if meta query was specified, let us keep it and we will add our conditions if (!empty($meta_query)) { $gmeta_query = $meta_query; } //we will need to build tax query/meta query //type, audio video etc //if type is given and it is valid gallery type //Pass one or more types if ($gallery_id) { //if gallery id is given, avoid worrying about type $type = ''; $component = ''; } if (!empty($type) && mpp_are_registered_types($type)) { $type = mpp_string_to_array($type); //we store the terms with _name such as private becomes _private, members become _members to avoid conflicting terms $type = array_map('mpp_underscore_it', $type); $tax_query[] = array('taxonomy' => mpp_get_type_taxname(), 'field' => 'slug', 'terms' => $type, 'operator' => 'IN'); } //privacy //pass one or more privacy level if (!empty($status) && mpp_are_registered_statuses($status)) { $status = mpp_string_to_array($status); $status = array_map('mpp_underscore_it', $status); $tax_query[] = array('taxonomy' => mpp_get_status_taxname(), 'field' => 'slug', 'terms' => $status, 'operator' => 'IN'); } if (!empty($component) && mpp_are_registered_components($component)) { $component = mpp_string_to_array($component); $component = array_map('mpp_underscore_it', $component); $tax_query[] = array('taxonomy' => mpp_get_component_taxname(), 'field' => 'slug', 'terms' => $component, 'operator' => 'IN'); } //done with the tax query if (count($tax_query) > 1) { $tax_query['relation'] = 'AND'; } if (!empty($tax_query)) { $wp_query_args['tax_query'] = $tax_query; } //now, for component if (!empty($component_id)) { $meta_compare = '='; if (is_array($component_id)) { $meta_compare = 'IN'; } $gmeta_query[] = array('key' => '_mpp_component_id', 'value' => $component_id, 'compare' => $meta_compare, 'type' => 'UNSIGNED'); } //also make sure that it only looks for gallery media $gmeta_query[] = array('key' => '_mpp_is_mpp_media', 'value' => 1, 'compare' => '=', 'type' => 'UNSIGNED'); //should we avoid the orphaned media //Let us discuss with the community and get it here if (!mpp_get_option('show_orphaned_media')) { $gmeta_query[] = array('key' => '_mpp_is_orphan', 'compare' => 'NOT EXISTS'); } //Let us filter the media by storage method if (!empty($storage)) { $gmeta_query[] = array('key' => '_mpp_storage_method', 'value' => $storage, 'compare' => '='); } //and what to do when a user searches by the media source(say youtube|vimeo|xyz.. how do we do that?) //reset meta query if (!empty($gmeta_query)) { $wp_query_args['meta_query'] = $gmeta_query; } return $wp_query_args; //http://wordpress.stackexchange.com/questions/53783/cant-sort-get-posts-by-post-mime-type }
/** * Set/Update gallery component * * @param int|MPP_Gallery $gallery * @param string $type ( groups|groups|events etc) */ function mpp_update_gallery_component($gallery, $component) { $gallery = mpp_get_gallery($gallery); wp_set_object_terms($gallery->id, mpp_get_component_term_id($component), mpp_get_component_taxname()); }
function mpp_update_gallery($args) { if (!isset($args['id'])) { return new WP_Error(0, __('Must provide ID to update a gallery')); } $gallery = get_post($args['id']); //we need meaning full error handling in future if (!$gallery) { return new WP_Error(0, __('Gallery Does not exist!', 'mediapress')); } // $gdata = get_object_vars( $gallery ); $gallery_data = array('id' => $gallery->ID, 'title' => $gallery->post_title, 'description' => $gallery->post_content, 'slug' => $gallery->post_name, 'creator_id' => $gallery->post_author, 'order' => $gallery->menu_order, 'component_id' => mpp_get_gallery_meta($gallery_id, '_mpp_component_id')); $args = wp_parse_args($args, $gallery_data); extract($args); if (empty($id) || empty($title)) { return false; } //now let us check which fields need to be updated if ($creator_id) { $gallery->post_author = $creator_id; } if ($title) { $gallery->post_title = $title; } if ($description) { $gallery->post_content = $description; } if ($slug) { $gallery->post_name = $slug; } if ($order) { $gallery->menu_order = $order; } $post = get_object_vars($gallery); if ($component && mpp_is_active_component($component)) { $tax[mpp_get_component_taxname()] = mpp_underscore_it($component); } if ($type && mpp_is_active_type($type)) { $tax[mpp_get_type_taxname()] = mpp_underscore_it($type); } if ($status && mpp_is_active_status($status)) { $tax[mpp_get_status_taxname()] = mpp_underscore_it($status); } $post['tax_input'] = $tax; //$post['ID'] = $gallery->id; $gallery_id = wp_update_post($post); if (is_wp_error($gallery_id)) { return $gallery_id; } //error do_action('mpp_gallery_updated', $gallery_id); return $gallery_id; }