/** * Handles Gallery Media Reordering * * * @return type */ function mpp_action_reorder_gallery_media() { if (empty($_POST['mpp-action']) || $_POST['mpp-action'] != 'reorder-gallery-media') { return; } $referer = wp_get_referer(); if (!wp_verify_nonce($_POST['mpp-nonce'], 'mpp-reorder-gallery-media')) { //add error message and return back to the old page mpp_add_feedback(__('Action not authorized!', 'mediapress'), 'error'); mpp_redirect($referer); } //should we check for the permission? not here $media_ids = $_POST['mpp-media-ids']; //array $media_ids = wp_parse_id_list($media_ids); $order = count($media_ids); foreach ($media_ids as $media_id) { if (!mpp_user_can_edit_media($media_id)) { //unauthorized attemt mpp_add_feedback(__("You don't have permission to update!", 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } //if we are here, let us update the order mpp_update_media_order($media_id, $order); $order--; } if ($media_id) { //mark the gallery assorted, we use it in MPP_Media_query to see what should be the default order $media = mpp_get_media($media_id); //mark the gallery as sorted mpp_mark_gallery_sorted($media->gallery_id); } mpp_add_feedback(__('Updated', 'mediapress')); if ($referer) { mpp_redirect($referer); } }
public function reorder_media() { //verify nonce if (!wp_verify_nonce($_POST['_wpnonce'], 'mpp-manage-gallery')) { wp_send_json(array('message' => __('Invalid action.', 'mediapress'), 'error' => 1)); exit(0); } //should we check for the permission? not here $media_ids = $_POST['mpp-media-ids']; //array $media_ids = wp_parse_id_list($media_ids); $media_ids = array_filter($media_ids); $order = count($media_ids); foreach ($media_ids as $media_id) { if (!mpp_user_can_edit_media($media_id)) { //unauthorized attemt wp_send_json(array('message' => __("You don't have permission to update!", 'mediapress'), 'error' => 1)); exit(0); } //if we are here, let us update the order mpp_update_media_order($media_id, $order); $order--; } if ($media_id) { //mark the gallery assorted, we use it in MPP_Media_query to see what should be the default order $media = mpp_get_media($media_id); //mark the gallery as sorted mpp_mark_gallery_sorted($media->gallery_id); } wp_send_json(array('message' => __("Updated", 'mediapress'), 'success' => 1)); exit(0); }