load-(plugin_page)action-hookWP 1.5.0

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

In file: /wp-admin/admin.php
load-(plugin_page)
wp-admin/admin.php 289
do_action( "load-{$plugin_page}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores

Where the hook is used in WordPress

wp-admin/includes/admin-filters.php 130
add_action( 'load-plugins.php', 'wp_plugin_update_rows', 20 ); // After wp_update_plugins() is called.
wp-admin/includes/admin-filters.php 131
add_action( 'load-themes.php', 'wp_theme_update_rows', 20 ); // After wp_update_themes() is called.
wp-admin/includes/class-custom-background.php 81
add_action( "load-{$page}", array( $this, 'admin_load' ) );
wp-admin/includes/class-custom-background.php 82
add_action( "load-{$page}", array( $this, 'take_action' ), 49 );
wp-admin/includes/class-custom-background.php 83
add_action( "load-{$page}", array( $this, 'handle_upload' ), 49 );
wp-includes/default-filters.php 699
add_action( 'load-post.php', 'wp_set_up_cross_origin_isolation' );
wp-includes/default-filters.php 700
add_action( 'load-post-new.php', 'wp_set_up_cross_origin_isolation' );
wp-includes/default-filters.php 701
add_action( 'load-site-editor.php', 'wp_set_up_cross_origin_isolation' );
wp-includes/default-filters.php 702
add_action( 'load-widgets.php', 'wp_set_up_cross_origin_isolation' );
wp-includes/update.php 1194
add_action( 'load-plugins.php', 'wp_update_plugins' );
wp-includes/update.php 1195
add_action( 'load-update.php', 'wp_update_plugins' );
wp-includes/update.php 1196
add_action( 'load-update-core.php', 'wp_update_plugins' );
wp-includes/update.php 1200
add_action( 'load-themes.php', 'wp_update_themes' );
wp-includes/update.php 1201
add_action( 'load-update.php', 'wp_update_themes' );
wp-includes/update.php 1202
add_action( 'load-update-core.php', 'wp_update_themes' );