예제 #1
0
function mpp_action_hide_unpublished_media()
{
    if (!is_user_logged_in() || !mpp_is_gallery_management() || !bp_is_action_variable('delete-unpublished', 1)) {
        return;
    }
    $gallery_id = absint($_GET['gallery_id']);
    if (!$gallery_id) {
        return;
    }
    //verify nonce
    if (!wp_verify_nonce($_GET['_wpnonce'], 'delete-unpublished')) {
        //should we return or show error?
        return;
    }
    $referrer = mpp_get_gallery_edit_media_url($gallery_id);
    if (!mpp_gallery_has_unpublished_media($gallery_id)) {
        mpp_add_feedback(__('Nothing to hide.', 'mediapress'), 'error');
        bp_core_redirect($referrer);
    }
    //check if user has permission
    if (!mpp_user_can_publish_gallery_activity($gallery_id)) {
        mpp_add_feedback(__("You don't have sufficient permission.", 'mediapress'), 'error');
        bp_core_redirect($referrer);
    }
    mpp_gallery_delete_unpublished_media($gallery_id);
    mpp_add_feedback(__("Successfully hidden!", 'mediapress'));
    bp_core_redirect($referrer);
}
/**
 * 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);
}
예제 #3
0
/**
 * Handles Media deletion
 * 
 * @return type
 */
function mpp_action_delete_media()
{
    if (empty($_REQUEST['mpp-action']) || $_REQUEST['mpp-action'] != 'delete-media') {
        return;
    }
    if (!$_REQUEST['mpp-media-id']) {
        return;
    }
    $referer = wp_get_referer();
    if (!wp_verify_nonce($_REQUEST['mpp-nonce'], 'mpp-delete-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 = '';
    if (!empty($_REQUEST['mpp-media-id'])) {
        $media = mpp_get_media((int) $_REQUEST['mpp-media-id']);
    }
    //check for permission
    //we may want to allow passing of component from the form in future!
    if (!mpp_user_can_delete_media($media->id)) {
        mpp_add_feedback(__("You don't have permission to delete this!", 'mediapress'), 'error');
        if ($referer) {
            mpp_redirect($referer);
        }
        return;
    }
    //if we are here, delete media and redirect to the component base url
    mpp_delete_media($media->id);
    $redirect_url = mpp_get_gallery_permalink($media->gallery_id);
    mpp_add_feedback(__("Successfully deleted!", 'mediapress'), 'error');
    mpp_redirect($redirect_url);
}