钩子文档

load-page.php

💡 云策文档标注

概述

本文档介绍了 WordPress 中 load-page.php 钩子的使用,该钩子在管理菜单页面加载时运行。通常不直接添加此动作,而是通过添加管理菜单的函数间接使用。

关键要点

  • load-page.php 钩子在管理菜单页面加载时触发,用于执行相关代码。
  • 通常不直接添加此钩子,而是通过 add_options_page 等函数返回的钩子名来使用。
  • 钩子名通常由 'load-' 前缀和页面标识符组成,例如 load-tools_page_testload。

代码示例

add_action( 'admin_menu', 'test_load');
function test_load() {
   $hook = add_management_page( 'Test', 'Test', 8, 'testload');
   print('load-'.$hook);exit;
   /*
       Result: load-tools_page_testload
   */
}
add_action( 'load-edit.php', 'post_listing_page' );
function post_listing_page() {
    //this is the wp admin edit.php post listing page!
}

📄 原文内容

More Information

Runs when an administration menu page is loaded. This action is not usually added directly — see Administration Menus for more details of how to add admin menus. If you do want to use it directly, the return value from add_options_page and similar functions gives you the (page) part of the action name.

Source

* Possible hook names include:

User Contributed Notes

  1. Skip to note 2 content

    Examples migrated from Codex:

    Example:

    add_action( 'admin_menu', 'test_load');
    function test_load() {
       $hook = add_management_page( 'Test', 'Test', 8, 'testload');
       print('load-'.$hook);exit;
       /*
           Result: load-tools_page_testload
       */
    }

    Example:

    add_action( 'load-edit.php', 'post_listing_page' );
    function post_listing_page() {
        //this is the wp admin edit.php post listing page!
    }