/** * Handles gallery details updation * * @return type */ function mpp_action_edit_gallery() { //allow gallery to be created from anywhere if (empty($_POST['mpp-action']) || $_POST['mpp-action'] != 'edit-gallery') { return; } $referer = wp_get_referer(); //if we are here, It is gallery create action if (!wp_verify_nonce($_POST['mpp-nonce'], 'mpp-edit-gallery')) { //add error message and return back to the old page mpp_add_feedback(__('Action not authorized!', 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } $gallery_id = absint($_POST['mpp-gallery-id']); if (!$gallery_id) { return; } //check for permission //we may want to allow passing of component from the form in future! if (!mpp_user_can_edit_gallery($gallery_id)) { mpp_add_feedback(__("You don't have permission to edit this gallery!", 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } //if we are here, validate the data and let us see if we can create $title = $_POST['mpp-gallery-title']; $description = $_POST['mpp-gallery-description']; $status = $_POST['mpp-gallery-status']; $errors = array(); if (!mpp_is_active_status($status)) { $errors['status'] = __('Invalid Gallery status!', 'mediapress'); } if (empty($title)) { $errors['title'] = __('Title can not be empty', 'mediapress'); } //give opportunity to other plugins to add their own validation errors $validation_errors = apply_filters('mpp-edit-gallery-field-validation', $errors, $_POST); if (!empty($validation_errors)) { //let us add the validation error and return back to the earlier page $message = join('\\r\\n', $validation_errors); mpp_add_feedback($message, 'error'); if ($referer) { mpp_redirect($referer); } return; } //let us create gallery $gallery_id = mpp_update_gallery(array('title' => $title, 'description' => $description, 'status' => $status, 'creator_id' => get_current_user_id(), 'id' => $gallery_id)); if (!$gallery_id) { mpp_add_feedback(__('Unable to update gallery!', 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } //if we are here, the gallery was created successfully, //let us redirect to the gallery_slug/manage/upload page $redirect_url = mpp_get_gallery_settings_url($gallery_id); mpp_add_feedback(__('Gallery updated successfully!', 'mediapress')); mpp_redirect($redirect_url); }
/** * 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; }
public function update_gallery_details() { //verify nonce if (!wp_verify_nonce($_POST['_wpnonce'], 'mpp-manage-gallery')) { wp_send_json(array('message' => __('Invalid action.', 'mediapress'), 'error' => 1)); exit(0); } $gallery_id = absint($_POST['mpp-gallery-id']); if (!$gallery_id) { return; } //check for permission //we may want to allow passing of component from the form in future! if (!mpp_user_can_edit_gallery($gallery_id)) { wp_send_json(array('message' => __("You don't have permission to update.", 'mediapress'), 'error' => 1)); exit(0); } $description = $_POST['mpp-gallery-description']; $errors = array(); //give opportunity to other plugins to add their own validation errors $validation_errors = apply_filters('mpp-edit-gallery-field-validation', $errors, $_POST); if (!empty($validation_errors)) { //let us add the validation error and return back to the earlier page $message = join('\\r\\n', $validation_errors); wp_send_json(array('message' => $message, 'error' => 1)); exit(0); } //let us create gallery $gallery_id = mpp_update_gallery(array('description' => $description, 'id' => $gallery_id)); if (!$gallery_id) { wp_send_json(array('message' => __('Unable to update gallery!', 'mediapress'), 'error' => 1)); exit(0); } wp_send_json(array('message' => __('Gallery updated successfully!', 'mediapress'), 'success' => 1)); exit(0); }