钩子文档

manage_users_extra_tablenav

💡 云策文档标注

概述

manage_users_extra_tablenav 是一个 WordPress 动作钩子,在用户列表表格的导航栏“actions” div 关闭后立即触发,允许开发者在顶部或底部添加自定义内容。

关键要点

  • 钩子名称:manage_users_extra_tablenav
  • 触发时机:用户列表表格导航栏的“actions” div 关闭后
  • 参数:$which,字符串类型,表示额外导航标记的位置,可选 'top' 或 'bottom'
  • 相关函数:WP_Users_List_Table::extra_tablenav(),用于批量更改用户角色
  • 引入版本:WordPress 4.9.0

代码示例

add_action( 'manage_users_extra_tablenav', function ( string $which ) {
    // 仅在顶部添加
    if ( 'top' !== $which ) {
        return;
    }

    echo '<a href="#" class="button">' . esc_html__( 'Add New User', 'text-domain' ) . '</a>';
} );

注意事项

此钩子可用于在用户管理页面(users.php)的顶部导航区域添加自定义元素,如创建新用户按钮。


📄 原文内容

Fires immediately following the closing “actions” div in the tablenav for the users list table.

Parameters

$whichstring
The location of the extra table nav markup: 'top' or 'bottom'.

Source

do_action( 'manage_users_extra_tablenav', $which );

Changelog

Version Description
4.9.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    You can add for example a button for creating new user or anything else in the topnav area (before the users table) in users.php page

    add_action( 'manage_users_extra_tablenav', function ( string $which ) {
    	// Add at top only
    	if ( 'top' !== $which ) {
    		return;
    	}
    
    	echo '<a href="' . esc_url( admin_url( 'user-new.php' ) ) . '" rel="nofollow ugc">' . esc_html__( 'Add New User', 'text-domain' ) . '</a>';
    } );