wp_add_dashboard_widget()添加一个后台的小工具/侧边栏

目录

描述

This function adds a new widget to the administration dashboard, using the WordPress Dashboard Widgets API.

wp_add_dashboard_widget() 描述

用法

wp_add_dashboard_widget() 用法

参数

$widget_id

(string) (必填) an identifying slug for your widget. This will be used as its css class and its key in the array of widgets.

默认值: None

$widget_name

(string) (必填) this is the name your widget will display in its heading.

默认值: None

$callback

(string) (必填) The name of a function you create that will display the actual contents of your widget.

默认值: None

$control_callback

(string) (可选) The name of a function you create that will handle submission of widget options (configuration) forms, and will also display the form elements.

默认值:

$callback_args

(array) (可选) Arguments to pass into your callback function. The callback will receive the $post object and whatever parameters are passed through this variable.

默认值:

wp_add_dashboard_widget() 参数

示例

Adding Dashboard Widgets

Here is a simple dashboard widget:

Running Dashboard Widgets

To run the function use this code:

Adding Widgets onto the side

The function doesn't allow you to choose where you want your widget to go and will automatically add it to the "core" which is the left side. However you are able to get it on the right side very easily.

You can use the add_meta_box() function instead of wp_add_dashboard_widget. Simply specify 'dashboard' in place of the $post_type. For example:

Using the Control Callback

With the control callback function we can create configurations just like the default feed widgets, WordPress Blog and Other WordPress News.

1) A default message appears asking for the configuration

1) A default message appears asking for the configuration

2) We select a page in the configuration screen

3) The page title and content are shown in the widget

wp_add_dashboard_widget() 示例

历史

添加于 版本: 2.7.0

wp_add_dashboard_widget() 历史

源文件

wp_add_dashboard_widget() 函数的代码位于 /wp-admin/includes/dashboard.php.

wp_add_dashboard_widget() 源文件

相关