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 with 3 submenu_pages. In one page is a formular (in one some text and in one a list of items). when I submit the form, there will be done some processing. after that I don't want to get back to the form-page, but WP shell redirect me to one of the other submenu_pages (in this case a list).

how can I achive this?

add_menu_page( 'page1 main page', '0', 'manage_options', 'mg-pi', 'mg_backend');    
add_submenu_page( 'mg-pi', 'list smthing', '0', 'manage_options', 'mg-pi-sub-list', 'mg_list');
add_submenu_page( 'mg-pi', 'create', '0', 'manage_options', 'mg-pi-sub-create', 'mg_new_item');   

so in mg_new_item() is the processing and then it shell redirect to mg_list(). but if I do the php call to mg_list() the url is still the one of mg_new_item().

I know I could do some header("Location: the-hardcoded-list-url"); but I am looking for the WordPress common way of doing it, with generic Url generation.

share|improve this question
    
possible duplicate of Wordpress PHP plugin - Settings page error –  s_ha_dum Aug 26 '13 at 15:14
    
I don't think it's a dublicate @s_ha_dum. But the answer might help sombody anyway. But my problem with it (that other answer) is, that it's not a redirect. If I use that solution, I will have to put the logical code of the formular to the list-code ... which I would like to avoid. Additionaly I want to consider: That other Answer also is not accepted so far, and as you can read in the comments there are still problems with that solition. –  helle Aug 26 '13 at 15:19
1  
You have not posted enough of your code for me to tell what you are doing, much less to try to debug and test. –  s_ha_dum Aug 26 '13 at 15:22
    
Also, the answer is not accepted but it does work. I do this all the time. You cannot always account for other people's confusion. –  s_ha_dum Aug 26 '13 at 15:23
    
There is nothing to debug so far. I am looking for a way to redirect to a sub-menu-page with a wordpress given function, where I get the Url maybe via the slug or something, like it is possible in theme templates as well... –  helle Aug 26 '13 at 15:32
add comment

2 Answers

Simply use add_query_arg(), remove_query_arg() and get_query_var().

On your page link, you use a simple query var like step=one.

$query_arg = add_query_arg( 'step', 'one', $_SERVER['REQUEST_URI'] );

Then, when the user processed the form, you just reload the page. Then simply check if

0 !== get_query_var( 'step' )
AND 'one' !== get_query_var( 'step' )

and process further. If you want to go back, just use remove_query_arg(), etc.

share|improve this answer
1  
+1 for a nice idea –  helle Aug 30 '13 at 9:41
add comment
up vote 0 down vote accepted

Well after some more research I fond what I was actually looking for. Not for a workaround but for a wordpress compatible way.

There is a function called: menu_page_url which expects the defined slug. and there is wp_redirect

so we have 2 wordpress functions to call. In this case:

$foo = menu_page_url("mg-pi-sub-list");
wp_redirect($foo);

that's it. And the good thing, I observe all Wordpress rules and the plugin will be compatible in future versions.

http://codex.wordpress.org/Function_Reference/wp_redirect http://codex.wordpress.org/Function_Reference/menu_page_url

UPDATE

and if you have troubles with your headers you can help you out with this parameter:

<form action="?page=your-sub_page-slug&noheaders=true">
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.