/**
  * Redirect attachment link to single media page
  */
 public function redirect_attachment()
 {
     if (is_attachment() && mpp_is_valid_media(get_queried_object_id())) {
         $redirect_url = mpp_get_media_url(get_queried_object());
         mpp_redirect($redirect_url, 301);
     }
 }
/**
 * 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);
}
function mpp_action_hide_unpublished_media()
{
    if (!mediapress()->is_bp_active() || !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');
        mpp_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');
        mpp_redirect($referrer);
    }
    mpp_gallery_delete_unpublished_media($gallery_id);
    mpp_add_feedback(__("Successfully hidden!", 'mediapress'));
    mpp_redirect($referrer);
}
Example #4
0
/**
 * Handles Gallery Cover deletion
 * 
 * @return type
 */
function mpp_action_delete_gallery_cover()
{
    if (!mpp_is_gallery_cover_delete()) {
        return;
    }
    if (!$_REQUEST['gallery_id']) {
        return;
    }
    $gallery = mpp_get_gallery(absint($_REQUEST['gallery_id']));
    $referer = $redirect_url = mpp_get_gallery_settings_url($gallery);
    if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'delete-cover')) {
        //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_gallery($gallery)) {
        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_gallery_cover_id($gallery->id);
    mpp_delete_gallery_cover_id($gallery->id);
    //if( $gallery->type != 'photo' ) {
    //delete the uploaded cover too
    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);
}
Example #5
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);
}