Fix multi-widget addition with JS disabled. Props mdawaffe. see #6239

git-svn-id: https://develop.svn.wordpress.org/trunk@7362 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2008-03-17 23:25:05 +00:00
parent 88a2fee4ef
commit 21539c80a4
3 changed files with 83 additions and 14 deletions
+24 -10
View File
@@ -2,7 +2,7 @@
// $_search is unsanitized
function wp_list_widgets( $show = 'all', $_search = false ) {
global $wp_registered_widgets, $sidebars_widgets;
global $wp_registered_widgets, $sidebars_widgets, $wp_registered_widget_controls;
if ( $_search ) {
// sanitize
$search = preg_replace( '/[^\w\s]/', '', $_search );
@@ -52,17 +52,31 @@ function wp_list_widgets( $show = 'all', $_search = false ) {
$widget_control_template = ob_get_contents();
ob_end_clean();
$widget_id = $widget['id']; // save this for later in case we mess with $widget['id']
$is_multi = false !== strpos( $widget_control_template, '%i%' );
if ( !$sidebar || $is_multi ) {
if ( $is_multi )
$already_shown[] = $widget['callback']; // it's a multi-widget. We only need to show it in the list once.
$action = 'add';
$add_url = wp_nonce_url( add_query_arg( array(
$add_query = array(
'sidebar' => $sidebar,
'add' => $widget['id'],
'key' => false,
'edit' => false
) ), "add-widget_$widget[id]" );
);
if ( $is_multi ) {
// it's a multi-widget. We only need to show it in the list once.
$already_shown[] = $widget['callback'];
$num = array_pop( explode( '-', $widget['id'] ) );
$id_base = $wp_registered_widget_controls[$widget['id']]['id_base'];
// so that we always add a new one when clicking "add"
while ( isset($wp_registered_widgets["$id_base-$num"]) )
$num++;
$widget['id'] = "$id_base-$num";
$add_query['base'] = $id_base;
$add_query['key'] = $num;
$add_query['sidebar'] = $GLOBALS['sidebar'];
}
$add_query['add'] = $widget['id'];
$action = 'add';
$add_url = wp_nonce_url( add_query_arg( $add_query ), "add-widget_$widget[id]" );
} else {
$action = 'edit';
$edit_url = clean_url( add_query_arg( array(
@@ -110,7 +124,7 @@ function wp_list_widgets( $show = 'all', $_search = false ) {
<?php endif; ?>
<div class="widget-description">
<?php echo ( $widget_description = wp_widget_description( $widget['id'] ) ) ? $widget_description : '&nbsp;'; ?>
<?php echo ( $widget_description = wp_widget_description( $widget_id ) ) ? $widget_description : '&nbsp;'; ?>
</div>
<br class="clear" />
@@ -174,7 +188,7 @@ function wp_widget_control( $sidebar_args ) {
$key = $sidebar_id ? array_search( $widget_id, $sidebars_widgets[$sidebar_id] ) : 'no-key'; // position of widget in sidebar
$edit = $edit_widget > 0 && $key && $edit_widget == $key; // (bool) are we currently editing this widget
$edit = -1 < $edit_widget && is_numeric($key) && $edit_widget === $key; // (bool) are we currently editing this widget
$id_format = $widget['id'];
// We aren't showing a widget control, we're outputing a template for a mult-widget control
@@ -240,7 +254,7 @@ function wp_widget_control( $sidebar_args ) {
<?php endif; ?>
<a class="widget-action widget-control-remove delete alignright" href="<?php echo clean_url( add_query_arg( array( 'remove' => $id_format, 'key' => $key ), wp_nonce_url( null, "remove-widget_$widget[id]" ) ) ); ?>"><?php _e('Remove'); ?></a>
<a class="widget-action widget-control-remove delete alignright" href="<?php echo clean_url( wp_nonce_url( add_query_arg( array( 'remove' => $id_format, 'key' => $key ) ), "remove-widget_$widget[id]" ) ); ?>"><?php _e('Remove'); ?></a>
<br class="clear" />
</div>
</div>