3
* WordPress Widgets Administration API
6
* @subpackage Administration
10
* Display list of the available widgets.
14
function wp_list_widgets() {
15
global $wp_registered_widgets, $wp_registered_widget_controls;
17
$sort = $wp_registered_widgets;
18
usort( $sort, '_sort_name_callback' );
21
foreach ( $sort as $widget ) {
22
if ( in_array( $widget['callback'], $done, true ) ) // We already showed this multi-widget
25
$sidebar = is_active_widget( $widget['callback'], $widget['id'], false, false );
26
$done[] = $widget['callback'];
28
if ( ! isset( $widget['params'][0] ) )
29
$widget['params'][0] = array();
31
$args = array( 'widget_id' => $widget['id'], 'widget_name' => $widget['name'], '_display' => 'template' );
33
if ( isset($wp_registered_widget_controls[$widget['id']]['id_base']) && isset($widget['params'][0]['number']) ) {
34
$id_base = $wp_registered_widget_controls[$widget['id']]['id_base'];
35
$args['_temp_id'] = "$id_base-__i__";
36
$args['_multi_num'] = next_widget_id_number($id_base);
37
$args['_add'] = 'multi';
39
$args['_add'] = 'single';
44
$args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
45
call_user_func_array( 'wp_widget_control', $args );
50
* Callback to sort array by a 'name' key.
55
function _sort_name_callback( $a, $b ) {
56
return strnatcasecmp( $a['name'], $b['name'] );
60
* Show the widgets and their settings for a sidebar.
61
* Used in the admin widget config screen.
65
* @param string $sidebar id slug of the sidebar
66
* @param string optional $sidebar_name Include the HTML for the sidebar name
68
function wp_list_widget_controls( $sidebar, $sidebar_name = '' ) {
69
add_filter( 'dynamic_sidebar_params', 'wp_list_widget_controls_dynamic_sidebar' );
71
$description = wp_sidebar_description( $sidebar );
73
echo '<div id="' . esc_attr( $sidebar ) . '" class="widgets-sortables">';
75
if ( $sidebar_name ) {
77
<div class="sidebar-name">
78
<div class="sidebar-name-arrow"><br /></div>
79
<h3><?php echo esc_html( $sidebar_name ); ?> <span class="spinner"></span></h3>
84
echo '<div class="sidebar-description">';
86
if ( ! empty( $description ) ) {
87
echo '<p class="description">' . $description . '</p>';
92
dynamic_sidebar( $sidebar );
98
* {@internal Missing Short Description}}
102
* @param array $params
105
function wp_list_widget_controls_dynamic_sidebar( $params ) {
106
global $wp_registered_widgets;
110
$widget_id = $params[0]['widget_id'];
111
$id = isset($params[0]['_temp_id']) ? $params[0]['_temp_id'] : $widget_id;
112
$hidden = isset($params[0]['_hide']) ? ' style="display:none;"' : '';
114
$params[0]['before_widget'] = "<div id='widget-{$i}_{$id}' class='widget'$hidden>";
115
$params[0]['after_widget'] = "</div>";
116
$params[0]['before_title'] = "%BEG_OF_TITLE%"; // deprecated
117
$params[0]['after_title'] = "%END_OF_TITLE%"; // deprecated
118
if ( is_callable( $wp_registered_widgets[$widget_id]['callback'] ) ) {
119
$wp_registered_widgets[$widget_id]['_callback'] = $wp_registered_widgets[$widget_id]['callback'];
120
$wp_registered_widgets[$widget_id]['callback'] = 'wp_widget_control';
126
function next_widget_id_number($id_base) {
127
global $wp_registered_widgets;
130
foreach ( $wp_registered_widgets as $widget_id => $widget ) {
131
if ( preg_match( '/' . $id_base . '-([0-9]+)$/', $widget_id, $matches ) )
132
$number = max($number, $matches[1]);
140
* Meta widget used to display the control form for a widget.
142
* Called from dynamic_sidebar().
146
* @param array $sidebar_args
149
function wp_widget_control( $sidebar_args ) {
150
global $wp_registered_widgets, $wp_registered_widget_controls, $sidebars_widgets;
152
$widget_id = $sidebar_args['widget_id'];
153
$sidebar_id = isset($sidebar_args['id']) ? $sidebar_args['id'] : false;
154
$key = $sidebar_id ? array_search( $widget_id, $sidebars_widgets[$sidebar_id] ) : '-1'; // position of widget in sidebar
155
$control = isset($wp_registered_widget_controls[$widget_id]) ? $wp_registered_widget_controls[$widget_id] : array();
156
$widget = $wp_registered_widgets[$widget_id];
158
$id_format = $widget['id'];
159
$widget_number = isset($control['params'][0]['number']) ? $control['params'][0]['number'] : '';
160
$id_base = isset($control['id_base']) ? $control['id_base'] : $widget_id;
161
$multi_number = isset($sidebar_args['_multi_num']) ? $sidebar_args['_multi_num'] : '';
162
$add_new = isset($sidebar_args['_add']) ? $sidebar_args['_add'] : '';
164
$query_arg = array( 'editwidget' => $widget['id'] );
166
$query_arg['addnew'] = 1;
167
if ( $multi_number ) {
168
$query_arg['num'] = $multi_number;
169
$query_arg['base'] = $id_base;
172
$query_arg['sidebar'] = $sidebar_id;
173
$query_arg['key'] = $key;
177
* We aren't showing a widget control, we're outputting a template
178
* for a multi-widget control.
180
if ( isset($sidebar_args['_display']) && 'template' == $sidebar_args['_display'] && $widget_number ) {
181
// number == -1 implies a template where id numbers are replaced by a generic '__i__'
182
$control['params'][0]['number'] = -1;
183
// With id_base widget id's are constructed like {$id_base}-{$id_number}.
184
if ( isset($control['id_base']) )
185
$id_format = $control['id_base'] . '-__i__';
188
$wp_registered_widgets[$widget_id]['callback'] = $wp_registered_widgets[$widget_id]['_callback'];
189
unset($wp_registered_widgets[$widget_id]['_callback']);
191
$widget_title = esc_html( strip_tags( $sidebar_args['widget_name'] ) );
192
$has_form = 'noform';
194
echo $sidebar_args['before_widget']; ?>
195
<div class="widget-top">
196
<div class="widget-title-action">
197
<a class="widget-action hide-if-no-js" href="#available-widgets"></a>
198
<a class="widget-control-edit hide-if-js" href="<?php echo esc_url( add_query_arg( $query_arg ) ); ?>">
199
<span class="edit"><?php _ex( 'Edit', 'widget' ); ?></span>
200
<span class="add"><?php _ex( 'Add', 'widget' ); ?></span>
201
<span class="screen-reader-text"><?php echo $widget_title; ?></span>
204
<div class="widget-title"><h4><?php echo $widget_title ?><span class="in-widget-title"></span></h4></div>
207
<div class="widget-inside">
208
<form action="" method="post">
209
<div class="widget-content">
211
if ( isset($control['callback']) )
212
$has_form = call_user_func_array( $control['callback'], $control['params'] );
214
echo "\t\t<p>" . __('There are no options for this widget.') . "</p>\n"; ?>
216
<input type="hidden" name="widget-id" class="widget-id" value="<?php echo esc_attr($id_format); ?>" />
217
<input type="hidden" name="id_base" class="id_base" value="<?php echo esc_attr($id_base); ?>" />
218
<input type="hidden" name="widget-width" class="widget-width" value="<?php if (isset( $control['width'] )) echo esc_attr($control['width']); ?>" />
219
<input type="hidden" name="widget-height" class="widget-height" value="<?php if (isset( $control['height'] )) echo esc_attr($control['height']); ?>" />
220
<input type="hidden" name="widget_number" class="widget_number" value="<?php echo esc_attr($widget_number); ?>" />
221
<input type="hidden" name="multi_number" class="multi_number" value="<?php echo esc_attr($multi_number); ?>" />
222
<input type="hidden" name="add_new" class="add_new" value="<?php echo esc_attr($add_new); ?>" />
224
<div class="widget-control-actions">
225
<div class="alignleft">
226
<a class="widget-control-remove" href="#remove"><?php _e('Delete'); ?></a> |
227
<a class="widget-control-close" href="#close"><?php _e('Close'); ?></a>
229
<div class="alignright<?php if ( 'noform' === $has_form ) echo ' widget-control-noform'; ?>">
230
<?php submit_button( __( 'Save' ), 'button-primary widget-control-save right', 'savewidget', false, array( 'id' => 'widget-' . esc_attr( $id_format ) . '-savewidget' ) ); ?>
231
<span class="spinner"></span>
238
<div class="widget-description">
239
<?php echo ( $widget_description = wp_widget_description($widget_id) ) ? "$widget_description\n" : "$widget_title\n"; ?>
242
echo $sidebar_args['after_widget'];
244
return $sidebar_args;