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.
Simply use
add_query_arg()
,remove_query_arg()
andget_query_var()
.On your page link, you use a simple query var like
step=one
.Then, when the user processed the form, you just reload the page. Then simply check if
and process further. If you want to go back, just use
remove_query_arg()
, etc.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:
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: