load-(plugin_page)
Fires when a plugin admin page is loaded (rarely used).
Allows specific actions to be performed when a particular plugin settings page loads in the WordPress admin area.
Replace (plugin_page) in the hook name with the specific page identifier, for example, load-myplugin.
(plugin_page) is the slug of the current plugin admin page — the value of $_GET['page']. It is the $menu_slug parameter value from add_menu_page() / add_submenu_page().
Usually, plugin pages created with add_menu_page() or add_submenu_page() should use another hook — load-(page_hook).
This hook fires instead of load-(page_hook) only if $page_hook is not defined — get_plugin_page_hook() returns a false value:
$page_hook = get_plugin_page_hook( $_GET['page'], $pagenow ); // or $page_hook = get_plugin_page_hook( $_GET['page'], $_GET['page'] );
See the similar load-(pagenow) hook.
This hook is used in rare cases for plugin pages. However, if the current admin page is a core page rather than a custom page, this hook does not fire. The similar load-(pagenow) hook fires instead, where $pagenow is a global variable containing the current PHP filename, for example, 'post-new.php' or 'admin.php'.
Usage
add_action( 'load-(plugin_page)', 'wp_kama_load_plugin_page_action' );
/**
* Function for `load-(plugin_page)` action-hook.
*
* @return void
*/
function wp_kama_load_plugin_page_action(){
// action...
}
Examples
#1 Load scripts only on the plugin settings page
This example loads a JavaScript file only on the plugin page.
add_action( 'load-myplugin', 'my_plugin_admin_assets' );
function my_plugin_admin_assets() {
add_action( 'admin_enqueue_scripts', function() {
wp_enqueue_script( 'my-plugin-js', plugin_dir_url( __FILE__ ) . 'assets/admin.js', [], '1.0', true );
} );
}Changelog
| Since 1.5.0 | Introduced. |
Where the hook is called
do_action( "load-{$plugin_page}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
Where the hook is used in WordPress
add_action( 'load-plugins.php', 'wp_plugin_update_rows', 20 ); // After wp_update_plugins() is called.
add_action( 'load-themes.php', 'wp_theme_update_rows', 20 ); // After wp_update_themes() is called.
add_action( "load-{$page}", array( $this, 'admin_load' ) );
add_action( "load-{$page}", array( $this, 'take_action' ), 49 );
add_action( "load-{$page}", array( $this, 'handle_upload' ), 49 );
add_action( 'load-post.php', 'wp_set_up_cross_origin_isolation' );
add_action( 'load-post-new.php', 'wp_set_up_cross_origin_isolation' );
add_action( 'load-site-editor.php', 'wp_set_up_cross_origin_isolation' );
add_action( 'load-widgets.php', 'wp_set_up_cross_origin_isolation' );
add_action( 'load-plugins.php', 'wp_update_plugins' );
add_action( 'load-update.php', 'wp_update_plugins' );
add_action( 'load-update-core.php', 'wp_update_plugins' );
add_action( 'load-themes.php', 'wp_update_themes' );
add_action( 'load-update.php', 'wp_update_themes' );
add_action( 'load-update-core.php', 'wp_update_themes' );