函数
wp_register_sidebar_widget ( $id, $name, $output_callback, $options = array(), $params )
- 参数
-
-
(int|string)
$id
Widget ID.- Required: 是
-
(string)
$name
Widget display title.- Required: 是
-
(callable)
$output_callback
Run when widget is called.- Required: 是
-
(array)
$options
{ Optional. An array of supplementary widget options for the instance. @type string $classname Class name for the widget’s HTML container. Default is a shortened version of the output callback name. @type string $description Widget description for display in the widget administration panel and/or theme. @type bool $show_instance_in_rest Whether to show the widget’s instance settings in the REST API. Only available for WP_Widget based widgets. }- Required: 否
- Default: array()
-
(mixed)
$params
Optional additional parameters to pass to the callback function when it’s called.- Required: 是
-
(int|string)
- 定义位置
-
-
wp-includes/widgets.php
, line 386
-
wp-includes/widgets.php
- 引入
- 2.2.0
- 弃用
- –
Register an instance of a widget.
The default widget option is ‘classname’ that can be overridden.
The function can also be used to un-register widgets when `$output_callback`
parameter is an empty string.
function wp_register_sidebar_widget( $id, $name, $output_callback, $options = array(), ...$params ) { global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates, $_wp_deprecated_widgets_callbacks; $id = strtolower( $id ); if ( empty( $output_callback ) ) { unset( $wp_registered_widgets[ $id ] ); return; } $id_base = _get_widget_id_base( $id ); if ( in_array( $output_callback, $_wp_deprecated_widgets_callbacks, true ) && ! is_callable( $output_callback ) ) { unset( $wp_registered_widget_controls[ $id ] ); unset( $wp_registered_widget_updates[ $id_base ] ); return; } $defaults = array( 'classname' => $output_callback ); $options = wp_parse_args( $options, $defaults ); $widget = array( 'name' => $name, 'id' => $id, 'callback' => $output_callback, 'params' => $params, ); $widget = array_merge( $widget, $options ); if ( is_callable( $output_callback ) && ( ! isset( $wp_registered_widgets[ $id ] ) || did_action( 'widgets_init' ) ) ) { /** * Fires once for each registered widget. * * @since 3.0.0 * * @param array $widget An array of default widget arguments. */ do_action( 'wp_register_sidebar_widget', $widget ); $wp_registered_widgets[ $id ] = $widget; } }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。