Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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');
}
share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
Got it. Thanks. Testing it now. –  Scott B Jan 26 '11 at 0:19
    
@MathSmath: I've added it to functions.php and tested. Unfortunately, all thumbs are still getting created when using "Media > Add New". Any ideas for trace testing? echo "the post referrer: ".$_POST['_wp_http_referer']; (returns an integer incremented by +1 each time an upload occurs) –  Scott B Jan 26 '11 at 0:25
    
Perhaps another option would be to test for iframe? It appears in the post uploader, but apparently not in the media manager > add new uploader. –  Scott B Jan 26 '11 at 0:33
    
@Scott B Dammit! I was sure that'd work :) Not sure about the iframe thing. To trace, I'd try adding a wp_die(json_encode($_POST)) to the beginning of your "no thumbnails" function. It'll dump the contents of the post collection at the time the filter is run. It's possible that by the time Wordpress gets around to actually making the thumbnails, the original post collection is out of scope? In any event, you might see something in the available post collection you CAN use to identify the referrer. –  MathSmath Jan 26 '11 at 1:07
    
@MAthSmath: Got It! if(!stristr($_POST['type'], 'image')) {return array();}return $arr_sizes;} –  Scott B Jan 26 '11 at 2:46
show 1 more comment

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

That's the request parameter I see.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.