Problem seems to be reported here and there, but I can not found what I really need to fix this during the morning:
https://wordpress.org/support/topic/redirect-after-post?replies=2
https://wordpress.org/support/topic/redirect-doesnt-work-1
… nope, nothing. I found this:
http://wordpress.stackexchange.com/questions/76991/wp-redirect-not-working-after-submitting-form and second reply:
add_action( 'wp_loaded', 'wpa76991_process_form' );
function wpa76991_process_form(){
if( isset( $_POST['my_form_widget'] ) ):
// process form, and then
wp_redirect( get_permalink( $pid ) );
exit();
endif;
}
but it does not work, I ask myself why, and try to print the required url, that was in fact from menu_page_url(), but this is in administration menu, so, after some investigation I found out that the good hook is ‘admin_menu‘
So:
add_action( 'admin_init', 'myplugin_admin_form_process' );
function myplugin_admin_form_process()
{
if(!isset($_POST['form_id']) || $_POST['form_id'] != 'myplugin_admin_form') {
return;
}
if($_POST['action'] = '....') {
process_post();
wp_redirect(menu_page_url( 'myplugin-admin-main', false ));
exit();
}
}
and it worked