/** * Action links like view/edit/dele/upload to show on indiavidula media * * @param type $media * @return type */ function mpp_get_media_action_links($media = null) { $links = array(); $media = mpp_get_media($media); //$links ['view'] = sprintf( '<a href="%1$s" title="view %2$s" class="mpp-view-media">%3$s</a>', mpp_get_media_permalink( $media ), esc_attr( $media->title ), __( 'view', 'mediapress' ) ); //upload? if (mpp_user_can_edit_media($media->id)) { $links['edit'] = sprintf('<a href="%s" alt="' . __('Edit %s', 'mediapress') . '">%s</a>', mpp_get_media_edit_url($media), mpp_get_media_title($media), __('edit', 'mediapress')); } //delete if (mpp_user_can_delete_media($media)) { $links['delete'] = sprintf('<a href="%s" alt="' . __('delete %s', 'mediapress') . '" class="confirm mpp-confirm mpp-delete mpp-delete-media">%s</a>', mpp_get_media_delete_url($media), mpp_get_media_title($media), __('delete', 'mediapress')); } return apply_filters('mpp_media_actions_links', join(' ', $links), $links, $media); }
/** * Handles Single media Edit details * * @return type */ function mpp_action_edit_media() { //allow media to be edited from anywhere if (empty($_POST['mpp-action']) || $_POST['mpp-action'] != 'edit-media') { return; } $referer = wp_get_referer(); //if we are here, It is media edit action if (!wp_verify_nonce($_POST['mpp-nonce'], 'mpp-edit-media')) { //add error message and return back to the old page mpp_add_feedback(__('Action not authorized!', 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } $media_id = absint($_POST['mpp-media-id']); if (!$media_id) { return; } //check for permission if (!mpp_user_can_edit_media($media_id)) { mpp_add_feedback(__("You don't have permission to edit this!", 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } //if we are here, validate the data and let us see if we can update $title = $_POST['mpp-media-title']; $description = $_POST['mpp-media-description']; $status = $_POST['mpp-media-status']; $errors = array(); //todo //In future, replace with media type functions if (!mpp_is_active_status($status)) { $errors['status'] = __('Invalid media 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-media-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 $media_id = mpp_update_media(array('title' => $title, 'description' => $description, 'status' => $status, 'creator_id' => get_current_user_id(), 'id' => $media_id)); if (!$media_id) { mpp_add_feedback(__('Unable to update!', '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_media_edit_url($media_id); mpp_add_feedback(__('Updated successfully!', 'mediapress')); mpp_redirect($redirect_url); }
/** * 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); } }
<?php // Exit if the file is accessed directly over web if (!defined('ABSPATH')) { exit; } if (mpp_user_can_edit_media(mpp_get_current_media_id())) { ?> <?php $media = mpp_get_current_media(); ?> <form method="post" action="" id="mpp-media-edit-form" class="mpp-form mpp-form-stacked mpp-media-edit-form"> <div class="mpp-g"> <?php do_action('mpp_before_edit_media_form_fields', $media->id); ?> <div class="mpp-u-1-2 mpp-media-thumbnail"> <?php do_action('mpp_before_edit_media_thumbnail_field', $media->id); ?> <div class="mpp-media-thumbnail-edit"> <img src="<?php mpp_media_src('thumbnail'); ?> " /> </div> <?php
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); }