Question

I want to wrap the filter below in a conditional that tests whether the user is uploading an image from the Media Manager (Admin > Media > Add New) and not from the post editor image upload routine.

Is it possible to tell? $pagenow in both cases appears to be the same...

//no extra thumbs
global $pagenow;
if($pagenow=="media-new.php"){
add_filter('intermediate_image_sizes_advanced','ce4_no_thumbs');
}
function ce4_no_thumbs($sizes){return array();}

Update: It does appear that there is a post_id on the querystring when upload is accessed from within a post and not when it is accessed via "media manager > add new", however, the following test passes in either case...

if ( is_admin() && !isset($_GET['post_id']) ) {
    /*This should not fire if user is uploading an image into a post, 
      since post_id is on the querystring. However, in my test
      its still getting through.*/

add_filter('intermediate_image_sizes_advanced','ce4_no_thumbs');
}
Was it helpful?

Solution

I answered this for you in the comments of your previous question.

...you can use the filter that @Backie suggested above (intermediate_image_sizes_advanced), and in the hooked function check for a field in the post collection named _wp_http_referer. It tells you where the upload request came from.

If _wp_http_referer contains "media-new.php", you can return an empty array (which will temporarily stop thumbnail generation, but won't actually change any thumbnail settings). Otherwise, return the $sizes array untouched.

Try:

function wpsx_7756_no_thumbnails($arr_sizes){

    if(stristr($_POST['_wp_http_referer'], 'media-new.php')) {
        return array();
    }

    return $arr_sizes;

}

add_filter('intermediate_image_sizes_advanced','wpsx_7756_no_thumbnails');

Let me know if this works.

Keep in mind that adding the filter while you're on the upload form won't do what you want--the form posts to a separate page that handles the upload, and it won't respect your filter.

OTHER TIPS

Can you try $_GET['post'] instead of using $_GET['post_id'] ?

That's the request parameter I see.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top