钩子文档

load-{$page_hook}

💡 云策文档标注

概述

load-{$page_hook} 是一个 WordPress 动态 Hook,在特定插件屏幕加载前触发。它主要用于插件页面,当屏幕注册时提供回调函数。

关键要点

  • Hook 名称是动态的,基于 $page_hook 变量,由页面类型、分隔符和插件基本名称组成。
  • 页面类型取决于插件页面注册方式:子菜单页面(如设置)为 'settings',否则为 'toplevel'。
  • Hook 名称示例:'load-settings_page_pluginbasename',其中 'settings' 是页面类型,'_page_' 是分隔符,'pluginbasename' 是插件基本名称(不含文件扩展名)。
  • 相关函数:get_plugin_page_hook() 可用于获取 $page_hook。

注意事项

  • Hook 名称遵循 WordPress 命名约定,但使用了连字符而非下划线,需注意兼容性。
  • 此 Hook 自 WordPress 2.1.0 版本引入。

📄 原文内容

Fires before a particular screen is loaded.

Description

The load-* hook fires in a number of contexts. This hook is for plugin screens where a callback is provided when the screen is registered.

The dynamic portion of the hook name, $page_hook, refers to a mixture of plugin page information including:

  1. The page type. If the plugin page is registered as a submenu page, such as for Settings, the page type would be ‘settings’. Otherwise the type is ‘toplevel’.
  2. A separator of ‘_page_’.
  3. The plugin basename minus the file extension.

Together, the three parts form the $page_hook. Citing the example above, the hook name used would be ‘load-settings_page_pluginbasename’.

See also

Source

do_action( "load-{$page_hook}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores

Changelog

Version Description
2.1.0 Introduced.