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 have a plugin that restricts the categories users can view/edit in the admin. All works fine in WordPress 3.0.1, but as I started testing 3.1 I noticed that the category filter, which is AJAX, allows you to bypass the restrictions. I'm able to filter this out in 3.0.1 because it's submitted via URL parameters. My trouble is being able to $_GET the 'cat' parameter from the new AJAX request. I have tried testing for $_SERVER['HTTP_X_REQUESTED_WITH'], but it doesn't register.

I've asked this question on the wp-hackers mailing list, but no one can give me actual code that helps with my predicament.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

For excluding terms of a taxonomy the better way to do that would be to use the hook that was created for doing term exclusions.. list_terms_exclusions

Get the available categories using get_terms (get_categories calls get_terms anyway IIRC), and do your exclusions using a hook on list_terms_exclusions and your code should work as expected..

You can see the hook i'm referring to on line 1040. http://core.trac.wordpress.org/browser/trunk/wp-includes/taxonomy.php

NOTE: Your plugin does not have a sanitization callback function when it calls register_setting, your options won't get sanitized properly without one, i'd strongly advise you declare a callback function and sanitize the data as appropriate (especially if you're passing that saved data into queries).

share|improve this answer
    
I'm not trying to exclude terms from any taxonomy listings. –  Matthew Muro Nov 8 '10 at 19:19
    
Categories are terms(of the category taxonomy) and your plugin aims to exclude/filter categories, no? –  t31os Nov 8 '10 at 23:34
    
The goal of the plugin is to only query posts with selected categories on the Edit Posts screen. Yes, I am trying to exclude categories but not from any taxonomy lists. My code works as expected EXCEPT when AJAX is used and all I need to make it work is somehow get the 'cat' parameter that is being passed through admin-ajax.php. –  Matthew Muro Nov 9 '10 at 14:09
    
All the same, did you try the suggestion? I'd imagine the ajax calls still do term retrieval using the same functions, in theory the filter should work for the ajax requests to. I could be wrong, but should only take minutes to try.. –  t31os Nov 20 '10 at 13:45
    
Yeah, I tried the suggestion (once I figured out how to do it) and all works. You are right that it's a better way because it removes the selected terms from any term lists. I appreciate the help! –  Matthew Muro Nov 23 '10 at 17:15

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.