/** * Get Media delete url * * @param type $media * @return string */ function mpp_get_media_delete_url($media = null) { $media = mpp_get_media($media); $link = mpp_get_media_edit_url($media) . 'delete/?mpp-action=delete-media&mpp-nonce=' . wp_create_nonce('mpp-delete-media') . '&mpp-media-id=' . $media->id; return $link; //needs improvenemt }
/** * 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); }
public function context_menu_edit() { if (!mpp_is_single_gallery()) { return; } if (mpp_is_gallery_management() || mpp_is_media_management()) { return; } if (!mpp_user_can_edit_gallery(mpp_get_current_gallery_id())) { return; } $links = ''; if (mpp_is_single_media()) { $url = mpp_get_media_edit_url(); $links .= sprintf('<li><a href="%1$s" title ="%2$s"> %3$s</a></li>', $url, _x('Edit media', 'Profile context menu rel', 'mediapress'), _x('Edit', 'Profile context menu media edit label', 'mediapress')); } else { $url = mpp_get_gallery_edit_media_url(mpp_get_current_gallery()); //bulk edit media url $links .= sprintf('<li><a href="%1$s" title ="%2$s"> %3$s</a></li>', $url, _x('Edit Gallery', 'Profile context menu rel attribute', 'mediapress'), _x('Edit', 'Profile contextual edit gallery menu label', 'mediapress')); $links .= sprintf('<li><a href="%1$s" title ="%2$s"> %3$s</a></li>', mpp_get_gallery_add_media_url(mpp_get_current_gallery()), _x('Add Media', 'Profile context menu rel attribute', 'mediapress'), _x('Add Media', 'Profile contextual add media menu label', 'mediapress')); } echo $links; }
/** * Handles Media Cover deletion * * */ function mpp_action_delete_media_cover() { if (!mpp_is_media_management()) { return; } if (!isset($_REQUEST['mpp-action']) || $_REQUEST['mpp-action'] != 'cover-delete' || empty($_REQUEST['media_id'])) { return; } $media = mpp_get_media(absint($_REQUEST['media_id'])); if (empty($media)) { return; } $referer = $redirect_url = mpp_get_media_edit_url($media); if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'cover-delete')) { //add error message and return back to the old page mpp_add_feedback(__('Action not authorized!', 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } //we may want to allow passing of component from the form in future! if (!mpp_user_can_delete_media($media)) { mpp_add_feedback(__("You don't have permission to delete this cover!", 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } //we always need to delete this $cover_id = mpp_get_media_cover_id($media->id); mpp_delete_media_cover_id($media->id); mpp_delete_media($cover_id); mpp_add_feedback(__('Cover deleted successfully!', 'mediapress')); //if we are here, delete gallery and redirect to the component base url mpp_redirect($redirect_url); }
public function context_menu_edit() { if (mpp_is_gallery_management() || mpp_is_media_management()) { return; } if (!mpp_is_single_gallery()) { return; } if (!mpp_user_can_edit_gallery(mpp_get_current_gallery_id())) { return; } if (mpp_is_single_media()) { $url = mpp_get_media_edit_url(); } else { $url = mpp_get_gallery_edit_media_url(mpp_get_current_gallery()); } //bulk edit media url printf('<li><a href="%1$s" title ="%2$s"> %3$s</a></li>', $url, __('Edit', 'mediapress'), __('Edit', 'mediapress')); }
function mpp_get_media_cover_delete_url($media = null) { $link = mpp_get_media_edit_url($media) . '?_wpnonce=' . wp_create_nonce('cover-delete') . '&mpp-action=cover-delete&media_id=' . $media->id; $link = apply_filters('mpp_get_media_cover_delete_url', $link, $media); return $link; }
/** * 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); }