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 need to redirect the page based on the query vars in my plugin admin menu. I don't know where I can hook in to read the query vars or the GET vars order to decide if the page needs to be redirected.

share|improve this question
    
You are in the backend, but I got confused when you mentioned checking permalinks there? Can you elaborate? Thanks –  birgire Apr 2 at 3:40
    
Sorry, I updated it. I meant the GET vars. –  George Kendros Apr 2 at 12:46

1 Answer 1

up vote 2 down vote accepted

You can check the $current_screen on the current_screen action, and redirect after checking some GET conditions:

function wpd_current_screen( $current_screen ) {
    if ( 'toplevel_page_your_menu_item_id' == $current_screen->base ) {
        // check some condition and
        wp_redirect( admin_url() );
        exit;
    }
}
add_action( 'current_screen', 'wpd_current_screen' );
share|improve this answer
    
This fires early enough but I don't seem able to access the GET variables (or the query vars since I guess it would be too early to access GET). Reading your answer I realize my initial question was clear enough - I wanted to access the 'page' variable as well as an additional GET variable (which I set with add_query_arg). I'm guessing there's no way to get that. –  George Kendros Apr 2 at 12:44
    
I played around with it a bit more and I was able to use this hook as desired. Instead of reading anything inside $current_screen (which won't work because there are additional variables I need) I'm running add_query_arg() and adding an arbitrary variable. add_query_arg() returns the relative url with all variables so I can parse out the stuff I need. This is obviously a dirty method (adding arbitrary query args just to return the URL) so hopefully I can find a more elegant solution to that part. But the end result is the same, I'm able to parse out my variables early enough for a redirect. –  George Kendros Apr 2 at 15:22

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.