dynamic_sidebar_params
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
apply_filters( 'dynamic_sidebar_params', array $params )
Описание
Примечание: фильтр применяется как в публичной части сайта, так и в административной, включая сайдбар «Неактивные виджеты» на экране «Виджеты».
См. alsoregister_sidebar()
Оригинал (английский)
Note: The filter is evaluated on both the front end and back end, including for the Inactive Widgets sidebar on the Widgets screen.
Фильтруемое значение
argsarray An array of widget display arguments.namestringName of the sidebar the widget is assigned to.idstringID of the sidebar the widget is assigned to.descriptionstringThe sidebar description.classstringCSS class applied to the sidebar container.before_widgetstringHTML markup to prepend to each widget in the sidebar.after_widgetstringHTML markup to append to each widget in the sidebar.before_titlestringHTML markup to prepend to the widget title when displayed.after_titlestringHTML markup to append to the widget title when displayed.widget_idstringID of the widget.widget_namestringName of the widget.
widget_argsarray An array of multi-widget arguments.numberintNumber increment used for multiples of the same widget.
$params = apply_filters( 'dynamic_sidebar_params', $params );View all references View on Trac View on GitHub
Related
ChangelogUsed by Description wp_render_widget() wp-includes/widgets.phpCalls the render callback of a widget and returns the output.
dynamic_sidebar() wp-includes/widgets.phpDisplays dynamic sidebar.
User Contributed NotesVersion Description 2.5.0 Introduced. -
Skip to note 2 content
Razon Komar Pal
6 years ago
You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note
Firstly we create a custom widget field end of the each widgets control form.
if ( ! function_exists( 'wpdocs_display_custom_field_in_widget_form' ) ) { add_action( 'in_widget_form', 'wpdocs_display_custom_field_in_widget_form', 10, 3 ); /** * Append custom field end of the widgets control form * Fires at the end of the widget control form. */ function wpdocs_display_custom_field_in_widget_form( $widget, $return, $instance ) { $column = isset( $instance['column'] ) ? $instance['column'] : ''; ob_start(); ?> <p> <label for="<?php echo esc_attr( $widget->get_field_id( 'itclan_bs_grid_class' ) ) ?>"><?php _e( 'Column Label', 'text_domain' ) ?> <input class="widefat" value="<?php echo esc_attr( $column ) ?>" id="<?php echo esc_attr( $widget->get_field_id( 'column' ) ) ?>" name="<?php echo esc_attr( $widget->get_field_name( 'column' ) ) ?>" type="text" /> <small><?php _e( 'Some additional description.', 'text_domain' ) ?></small> </label> </p> <?php echo ob_get_clean(); } }Now, we filter widget’s settings before saving. It will save our custom field
columndata.if ( ! function_exists( 'wpdocs_update_custom_field_in_widget_form' ) ) { add_action( 'widget_update_callback', 'wpdocs_update_custom_field_in_widget_form', 10, 2 ); /** * Update widget fields * Filters a widget’s settings before saving. */ function wpdocs_update_custom_field_in_widget_form( $instance, $new_instance ) { $instance['column'] = !empty( $new_instance['column'] ) ? $new_instance['column'] : ''; return $instance; } }Finally, filter sidebar params for frontend. It will add class to
before_widgetfromcolumnfield
Log in to add feedbackif ( ! function_exists( 'wpdocs_filter_dynamic_sidebar_params' ) ) { add_action( 'dynamic_sidebar_params', 'wpdocs_filter_dynamic_sidebar_params' ); /** * Update widget fields * Filters the parameters passed to a widget’s display callback. */ function wpdocs_filter_dynamic_sidebar_params( $params ) { global $wp_registered_widgets; $widget_id = $params[0]['widget_id']; $widget_obj = $wp_registered_widgets[ $widget_id ]; $widget_opt = get_option( $widget_obj['callback'][0]->option_name ); $widget_num = $widget_obj['params'][0]['number']; $grid_class = isset( $widget_opt[ $widget_num ]['column'] ) ? $widget_opt[ $widget_num ]['column'] : ''; if ( preg_match( '/class="/', $params[0]['before_widget'] ) && $grid_class ) { $params[0]['before_widget'] = preg_replace( '/class="/', "class=\"{$grid_class} ", $params[0]['before_widget'], 1 ); } return $params; } }
You must log in before being able to contribute a note or feedback.
Параметры
$params
array
обязательный
argsarray An array of widget display arguments.namestringName of the sidebar the widget is assigned to.idstringID of the sidebar the widget is assigned to.descriptionstringThe sidebar description.classstringCSS class applied to the sidebar container.before_widgetstringHTML markup to prepend to each widget in the sidebar.after_widgetstringHTML markup to append to each widget in the sidebar.before_titlestringHTML markup to prepend to the widget title when displayed.after_titlestringHTML markup to append to the widget title when displayed.widget_idstringID of the widget.widget_namestringName of the widget.
widget_argsarray An array of multi-widget arguments.numberintNumber increment used for multiples of the same widget.
$params = apply_filters( 'dynamic_sidebar_params', $params );View all references View on Trac View on GitHub
Related
ChangelogUsed by Description wp_render_widget() wp-includes/widgets.phpCalls the render callback of a widget and returns the output.
dynamic_sidebar() wp-includes/widgets.phpDisplays dynamic sidebar.
User Contributed NotesVersion Description 2.5.0 Introduced. -
Skip to note 2 content
Razon Komar Pal
6 years ago
You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note
Firstly we create a custom widget field end of the each widgets control form.
if ( ! function_exists( 'wpdocs_display_custom_field_in_widget_form' ) ) { add_action( 'in_widget_form', 'wpdocs_display_custom_field_in_widget_form', 10, 3 ); /** * Append custom field end of the widgets control form * Fires at the end of the widget control form. */ function wpdocs_display_custom_field_in_widget_form( $widget, $return, $instance ) { $column = isset( $instance['column'] ) ? $instance['column'] : ''; ob_start(); ?> <p> <label for="<?php echo esc_attr( $widget->get_field_id( 'itclan_bs_grid_class' ) ) ?>"><?php _e( 'Column Label', 'text_domain' ) ?> <input class="widefat" value="<?php echo esc_attr( $column ) ?>" id="<?php echo esc_attr( $widget->get_field_id( 'column' ) ) ?>" name="<?php echo esc_attr( $widget->get_field_name( 'column' ) ) ?>" type="text" /> <small><?php _e( 'Some additional description.', 'text_domain' ) ?></small> </label> </p> <?php echo ob_get_clean(); } }Now, we filter widget’s settings before saving. It will save our custom field
columndata.if ( ! function_exists( 'wpdocs_update_custom_field_in_widget_form' ) ) { add_action( 'widget_update_callback', 'wpdocs_update_custom_field_in_widget_form', 10, 2 ); /** * Update widget fields * Filters a widget’s settings before saving. */ function wpdocs_update_custom_field_in_widget_form( $instance, $new_instance ) { $instance['column'] = !empty( $new_instance['column'] ) ? $new_instance['column'] : ''; return $instance; } }Finally, filter sidebar params for frontend. It will add class to
before_widgetfromcolumnfield
Log in to add feedbackif ( ! function_exists( 'wpdocs_filter_dynamic_sidebar_params' ) ) { add_action( 'dynamic_sidebar_params', 'wpdocs_filter_dynamic_sidebar_params' ); /** * Update widget fields * Filters the parameters passed to a widget’s display callback. */ function wpdocs_filter_dynamic_sidebar_params( $params ) { global $wp_registered_widgets; $widget_id = $params[0]['widget_id']; $widget_obj = $wp_registered_widgets[ $widget_id ]; $widget_opt = get_option( $widget_obj['callback'][0]->option_name ); $widget_num = $widget_obj['params'][0]['number']; $grid_class = isset( $widget_opt[ $widget_num ]['column'] ) ? $widget_opt[ $widget_num ]['column'] : ''; if ( preg_match( '/class="/', $params[0]['before_widget'] ) && $grid_class ) { $params[0]['before_widget'] = preg_replace( '/class="/', "class=\"{$grid_class} ", $params[0]['before_widget'], 1 ); } return $params; } }
You must log in before being able to contribute a note or feedback.
Исходный код
wp-includes/widgets.php:813
$params = apply_filters( 'dynamic_sidebar_params', $params );
История изменений
| Версия | Описание |
|---|---|
| 2.5.0 | Introduced. |

