mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-06 15:47:05 +00:00
Add and edit widget when js is disabled, see #9511
git-svn-id: https://develop.svn.wordpress.org/trunk@11009 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
function wp_list_widgets( $show = 'all', $_search = false ) {
|
||||
global $wp_registered_widgets, $sidebars_widgets, $wp_registered_widget_controls;
|
||||
|
||||
if ( $_search ) {
|
||||
if ( $_search ) {
|
||||
// sanitize
|
||||
$search = preg_replace( '/[^\w\s]/', '', $_search );
|
||||
// array of terms
|
||||
@@ -68,7 +68,7 @@ function wp_list_widgets( $show = 'all', $_search = false ) {
|
||||
$already_shown[] = $widget['callback'];
|
||||
$no_widgets_shown = false;
|
||||
|
||||
$args = array( 'widget_id' => $widget['id'], 'widget_name' => $widget['name'], '_display' => 'template' );
|
||||
$args = array( 'widget_id' => $widget['id'], 'widget_name' => $widget['name'], '_display' => 'template' );
|
||||
|
||||
if ( isset($wp_registered_widget_controls[$widget['id']]['id_base']) && isset($widget['params'][0]['number']) ) {
|
||||
$id_base = $wp_registered_widget_controls[$widget['id']]['id_base'];
|
||||
@@ -82,10 +82,10 @@ function wp_list_widgets( $show = 'all', $_search = false ) {
|
||||
}
|
||||
|
||||
$args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
|
||||
call_user_func_array( 'wp_widget_control', $args );
|
||||
call_user_func_array( 'wp_widget_control', $args );
|
||||
}
|
||||
|
||||
if ( $no_widgets_shown )
|
||||
if ( $no_widgets_shown )
|
||||
echo '<li>' . __( 'No matching widgets' ) . "</li>\n";
|
||||
?>
|
||||
</ul>
|
||||
@@ -132,7 +132,7 @@ function wp_list_widget_controls_dynamic_sidebar( $params ) {
|
||||
$params[0]['before_title'] = "%BEG_OF_TITLE%"; // deprecated
|
||||
$params[0]['after_title'] = "%END_OF_TITLE%"; // deprecated
|
||||
if ( is_callable( $wp_registered_widgets[$widget_id]['callback'] ) ) {
|
||||
$wp_registered_widgets[$widget_id]['_callback'] = $wp_registered_widgets[$widget_id]['callback'];
|
||||
$wp_registered_widgets[$widget_id]['_callback'] = $wp_registered_widgets[$widget_id]['callback'];
|
||||
$wp_registered_widgets[$widget_id]['callback'] = 'wp_widget_control';
|
||||
}
|
||||
|
||||
@@ -164,27 +164,33 @@ function wp_widget_control( $sidebar_args ) {
|
||||
|
||||
$widget_id = $sidebar_args['widget_id'];
|
||||
$sidebar_id = isset($sidebar_args['id']) ? $sidebar_args['id'] : false;
|
||||
|
||||
$key = $sidebar_id ? array_search( $widget_id, $sidebars_widgets[$sidebar_id] ) : '-1'; // position of widget in sidebar
|
||||
$control = isset($wp_registered_widget_controls[$widget_id]) ? $wp_registered_widget_controls[$widget_id] : array();
|
||||
$widget = $wp_registered_widgets[$widget_id];
|
||||
|
||||
$key = $sidebar_id ? array_search( $widget_id, $sidebars_widgets[$sidebar_id] ) : 'no-key'; // position of widget in sidebar
|
||||
|
||||
$edit = isset($_GET['editwidget']); // editing without js
|
||||
$nonce = $edit ? wp_create_nonce("edit-widget_$widget_id") : '';
|
||||
$widget = $wp_registered_widgets[$widget_id];
|
||||
|
||||
$id_format = $widget['id'];
|
||||
|
||||
$widget_number = isset($control['params'][0]['number']) ? $control['params'][0]['number'] : '';
|
||||
$id_base = isset($control['id_base']) ? $control['id_base'] : $widget_id;
|
||||
$multi_number = isset($sidebar_args['_multi_num']) ? $sidebar_args['_multi_num'] : '';
|
||||
$add_new = isset($sidebar_args['_add']) ? $sidebar_args['_add'] : '';
|
||||
|
||||
$query_arg = array( 'editwidget' => $widget['id'] );
|
||||
if ( $add_new ) {
|
||||
$query_arg['addnew'] = 1;
|
||||
if ( $multi_number ) {
|
||||
$query_arg['num'] = $multi_number;
|
||||
$query_arg['base'] = $id_base;
|
||||
}
|
||||
} else {
|
||||
$query_arg['sidebar'] = $sidebar_id;
|
||||
$query_arg['key'] = $key;
|
||||
}
|
||||
|
||||
// We aren't showing a widget control, we're outputing a template for a mult-widget control
|
||||
if ( isset($sidebar_args['_display']) && 'template' == $sidebar_args['_display'] && $widget_number ) {
|
||||
// number == -1 implies a template where id numbers are replaced by a generic '__i__'
|
||||
$control['params'][0]['number'] = -1;
|
||||
// if given, id_base means widget id's should be constructed like {$id_base}-{$id_number}
|
||||
// with id_base widget id's are constructed like {$id_base}-{$id_number}
|
||||
if ( isset($control['id_base']) )
|
||||
$id_format = $control['id_base'] . '-__i__';
|
||||
}
|
||||
@@ -193,50 +199,49 @@ function wp_widget_control( $sidebar_args ) {
|
||||
unset($wp_registered_widgets[$widget_id]['_callback']);
|
||||
|
||||
$widget_title = wp_specialchars( strip_tags( $sidebar_args['widget_name'] ) );
|
||||
$has_form = 0;
|
||||
|
||||
echo $sidebar_args['before_widget']; ?>
|
||||
<div class="widget-top">
|
||||
<div class="widget-title-action">
|
||||
<?php if ( !$edit ) { ?>
|
||||
<a class="widget-action widget-control-edit" href="<?php echo clean_url( add_query_arg( array( 'edit' => $id_format, 'key' => $key ) ) ); ?>"></a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="widget-title"><h4><?php echo $widget_title ?></h4></div>
|
||||
</div>
|
||||
<div class="widget-top">
|
||||
<div class="widget-title-action">
|
||||
<a class="widget-action widget-control-edit" href="<?php echo clean_url( add_query_arg( $query_arg ) ); ?>"></a>
|
||||
</div>
|
||||
<div class="widget-title"><h4><?php echo $widget_title ?></h4></div>
|
||||
</div>
|
||||
|
||||
<div class="widget-inside">
|
||||
<form action="" method="post">
|
||||
<div class="widget-control">
|
||||
<div class="widget-inside">
|
||||
<form action="" method="post">
|
||||
<div class="widget-control">
|
||||
<?php
|
||||
if ( isset($control['callback']) )
|
||||
call_user_func_array( $control['callback'], $control['params'] );
|
||||
else
|
||||
echo "\t\t<p>" . __('There are no options for this widget.') . "</p>\n"; ?>
|
||||
if ( isset($control['callback']) )
|
||||
$has_form = call_user_func_array( $control['callback'], $control['params'] );
|
||||
else
|
||||
echo "\t\t<p>" . __('There are no options for this widget.') . "</p>\n"; ?>
|
||||
|
||||
<input type="hidden" name="widget-id" class="widget-id" value="<?php echo $id_format; ?>" />
|
||||
<input type="hidden" name="id_base" class="id_base" value="<?php echo $id_base; ?>" />
|
||||
<input type="hidden" name="widget-width" class="widget-width" value="<?php echo $control['width']; ?>" />
|
||||
<input type="hidden" name="widget-height" class="widget-height" value="<?php echo $control['height']; ?>" />
|
||||
<input type="hidden" name="widget_number" class="widget_number" value="<?php echo $widget_number; ?>" />
|
||||
<input type="hidden" name="multi_number" class="multi_number" value="<?php echo $multi_number; ?>" />
|
||||
<input type="hidden" name="add_new" class="add_new" value="<?php echo $add_new; ?>" />
|
||||
<input type="hidden" name="widget-id" class="widget-id" value="<?php echo $id_format; ?>" />
|
||||
<input type="hidden" name="id_base" class="id_base" value="<?php echo $id_base; ?>" />
|
||||
<input type="hidden" name="widget-width" class="widget-width" value="<?php echo $control['width']; ?>" />
|
||||
<input type="hidden" name="widget-height" class="widget-height" value="<?php echo $control['height']; ?>" />
|
||||
<input type="hidden" name="widget_number" class="widget_number" value="<?php echo $widget_number; ?>" />
|
||||
<input type="hidden" name="multi_number" class="multi_number" value="<?php echo $multi_number; ?>" />
|
||||
<input type="hidden" name="add_new" class="add_new" value="<?php echo $add_new; ?>" />
|
||||
|
||||
<div class="widget-control-actions">
|
||||
<a class="button widget-control-remove alignleft" href="<?php echo $edit ? clean_url( add_query_arg( array( 'remove' => $id_format, 'key' => $key, '_wpnonce' => $nonce ) ) ) : '#remove'; ?>"><?php _e('Remove'); ?></a>
|
||||
<?php if ( !empty($control) ) { ?>
|
||||
<input type="submit" name="savewidget" class="button-primary widget-control-save alignright" value="<?php _e('Save'); ?>" />
|
||||
<div class="widget-control-actions">
|
||||
<a class="button widget-control-remove alignleft" href="<?php echo $edit ? clean_url( add_query_arg( array( 'remove' => $id_format, 'key' => $key, '_wpnonce' => $nonce ) ) ) : '#remove'; ?>"><?php _e('Remove'); ?></a>
|
||||
<?php if ( false !== $has_form ) { ?>
|
||||
<input type="submit" name="savewidget" class="button-primary widget-control-save alignright" value="<?php _e('Save'); ?>" />
|
||||
<?php } ?>
|
||||
<br class="clear" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="widget-description">
|
||||
<br class="clear" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="widget-description">
|
||||
<?php echo ( $widget_description = wp_widget_description($widget_id) ) ? "$widget_description\n" : "$widget_title\n"; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
echo $sidebar_args['after_widget'];
|
||||
|
||||
return $sidebar_args;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user