Admin_init not working in submenu page
I've a plugin divided into multiple pages and files based on classes.
The base file (linked from plugin main file) contains code for menu and submenu pages and provides wordpress with their respective files in a subfolder.
The problem is, that the admin_init
hook isn't working in the submenu page (trying to save values from a form submitted in submenu page).
The main page looks like (the admin_init
hook works fine if used in this file class itself):
class MyPlugin {
public function __construct(){
add_action( 'admin_menu', array( $this, 'add_menu' ) );
}
public function add_menu() {
add_menu_page(
'My Plugin',
'My Plugin',
'manage_options',
MY_PLUGIN_DIR.'/inc/admin/class-my-plugin-home.php',
'',
'dashicons-yes',
89
);
add_submenu_page(
MY_PLUGIN_DIR.'/inc/admin/class-my-plugin-home.php',
'Submenu page',
'Submenu page',
'manage_options',
MY_PLUGIN_DIR.'/inc/admin/class-my-plugin-submenu.php',
''
);
}
}
While the submenuclass-my-plugin-submenu.php file looks like:
function checkit(){
echo "This code is not working or showing (just for example)";
}
add_action( 'admin_init', 'checkit' );
Edit:
Previously not working and now the working version (thanks to Sally CJ) can be found here: https://github.com/nabtron/wp-admin-init-test-plugin
Topic admin-init Wordpress
Category Web