1. 首页
  2. WordPress钩子手册

admin_menu

do_action( ‘admin_menu’, string $context )

动作钩子::在管理菜单加载之前触发。
Action Hook: Fires before the administration menu loads in the admin.

目录锚点:#参数#源码#笔记


参数(Parameters)

参数 类型 说明
$context (string) 空上下文。

源码(Source)

更新版本 源码位置 使用 被使用
1.5.0 wp-admin/includes/menu.php:155 0 0

笔记(Notes)

如果要更改菜单标签,可以挂接此操作并更改全局$menu$子菜单值,

add_action( 'admin_menu', 'change_media_label' );
function change_media_label(){
  global $menu, $submenu;
  debug_msg($menu);
  $menu[10][0] = 'Photos/Videos';
  $submenu['upload.php'][5][0] = 'All Photos/Videos';
  $submenu['upload.php'][10][0] = 'Upload new';
}
add_action('admin_menu', 'wpautop_control_menu');
 
function wpautop_control_menu() {
  add_submenu_page('options-general.php', 'wpautop-control', 'wpautop control', 'manage_options', 'wpautop-control-menu', 'wpautop_control_options');
}

//call the 'add_menu_page' function with 'admin_menu' action hook
add_action( 'admin_menu', array( $this, 'wpdocs_add_menu_page' ), 99 );
 
/**
 * Add page to admin menu
 */
public function wpdocs_add_menu_page() {
    add_menu_page(
        esc_html__( 'WooCommerce B2B Sales Agents', 'woocommerce-b2b-sales-agents' ),
        esc_html__( 'WooCommerce B2B Sales Agents', 'woocommerce-b2b-sales-agents'),
        'manage_woocommerce',
        'wcb2bsa-commissions',
        null,
        'dashicons-businessman',
        55.5
    );
    add_submenu_page(
        'wcb2bsa-commissions',
        esc_html__( 'Commissions', 'woocommerce-b2b-sales-agents' ),
        esc_html__( 'Commissions', 'woocommerce-b2b-sales-agents' ),
        'manage_woocommerce',
        'wcb2bsa-commissions',
        array( $this, 'wpdocs_add_menu_page_callback' )
    );
}
 
/**
 * Add page to admin menu callback
 */
public function wpdocs_add_menu_page_callback() {
    include WCB2BSA_ABSPATH . 'includes/views/html-admin--page-commissions.php';
}

admin_menu 为WP2原创文章,链接:https://www.wp2.cn/hook/admin_menu/