Sequence of admin_post and admin_menu
-
I use the hook
admin_menuto create a custom menu page that has a form. And it looks like the below:function wpdocs_register_my_custom_menu_page(){ add_menu_page( 'custom menu', 'custom menu', 'manage_options', 'custompage', 'my_custom_menu_page', plugins_url( 'myplugin/images/icon.png' ), 6 ); } function my_custom_menu_page () { require_once form.php; } add_action( 'admin_menu', 'wpdocs_register_my_custom_menu_page' );I have a function to process the submitted data attach to the
admin_post_{$action}hook which looks like the below:function process_form () { wp_redirect ( 'https://example.com' ); } add_action( 'admin_post_process_form', 'process_form' );The problem is that
wp_redirectis actuallyheader ( "Location: https://example.com" ), so if the sequence is admin_menu -> admin_post_process_form, it should cause an error because the output is sent ( the formrequire_once form.php;).Or actually the
admin_post_process_formwill not be “require” on the custom menu page?Because I have test to put the
header ( "Location: https://example.com" )on the custom menu page after the form, there is no error which is very weird ( already turn on all error ).
The topic ‘Sequence of admin_post and admin_menu’ is closed to new replies.