Fix saving and deleting of widgets settings for no-js and for some non-standard widgets, run the actions from the widgets screen when saving with ajax, see #9511
git-svn-id: http://svn.automattic.com/wordpress/trunk@11427 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
54998219dc
commit
0632395ad6
|
@ -1282,64 +1282,34 @@ case 'save-widget' :
|
||||||
|
|
||||||
unset( $_POST['savewidgets'], $_POST['action'] );
|
unset( $_POST['savewidgets'], $_POST['action'] );
|
||||||
|
|
||||||
|
do_action('load-widgets.php');
|
||||||
|
do_action('widgets.php');
|
||||||
|
do_action('sidebar_admin_setup');
|
||||||
|
|
||||||
$id_base = $_POST['id_base'];
|
$id_base = $_POST['id_base'];
|
||||||
$number = isset($_POST['widget_number']) ? $_POST['widget_number'] : '';
|
$widget_id = $_POST['widget-id'];
|
||||||
$sidebar_id = $_POST['sidebar'];
|
$sidebar_id = $_POST['sidebar'];
|
||||||
|
|
||||||
$sidebars = wp_get_sidebars_widgets();
|
$sidebars = wp_get_sidebars_widgets();
|
||||||
$sidebar = isset($sidebars[$sidebar_id]) ? $sidebars[$sidebar_id] : array();
|
$sidebar = isset($sidebars[$sidebar_id]) ? $sidebars[$sidebar_id] : array();
|
||||||
|
|
||||||
// delete
|
// delete
|
||||||
if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
|
if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
|
||||||
$del_id = $_POST['widget-id'];
|
|
||||||
$widget = isset($wp_registered_widgets[$del_id]) ? $wp_registered_widgets[$del_id] : false;
|
|
||||||
|
|
||||||
if ( !in_array($del_id, $sidebar, true) )
|
if ( !isset($wp_registered_widgets[$widget_id]) )
|
||||||
die('-1');
|
die('-1');
|
||||||
|
|
||||||
if ( $widget ) {
|
$sidebar = array_diff( $sidebar, array($widget_id) );
|
||||||
$option = str_replace( '-', '_', 'widget_' . $id_base );
|
$_POST = array('sidebar' => $sidebar_id, 'widget-' . $id_base => array(), 'the-widget-id' => $widget_id, 'delete_widget' => '1');
|
||||||
$data = get_option($option);
|
|
||||||
|
|
||||||
if ( isset($widget['params'][0]['number']) ) {
|
|
||||||
$number = $widget['params'][0]['number'];
|
|
||||||
if ( is_array($data) && isset($data[$number]) ) {
|
|
||||||
unset( $data[$number] );
|
|
||||||
update_option($option, $data);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ( $data ) {
|
|
||||||
$data = array();
|
|
||||||
update_option($option, $data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$sidebar = array_diff( $sidebar, array($del_id) );
|
|
||||||
$sidebars[$sidebar_id] = $sidebar;
|
|
||||||
wp_set_sidebars_widgets($sidebars);
|
|
||||||
|
|
||||||
echo "deleted:$del_id";
|
|
||||||
die();
|
|
||||||
}
|
}
|
||||||
|
$_POST['widget-id'] = $sidebar;
|
||||||
|
|
||||||
// save
|
|
||||||
foreach ( (array) $wp_registered_widget_updates as $name => $control ) {
|
foreach ( (array) $wp_registered_widget_updates as $name => $control ) {
|
||||||
|
|
||||||
if ( $name == $id_base ) {
|
if ( $name == $id_base ) {
|
||||||
if ( !is_callable( $control['callback'] ) )
|
if ( !is_callable( $control['callback'] ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( $number ) {
|
|
||||||
// don't delete other instances of the same multi-widget
|
|
||||||
foreach ( $sidebar as $_widget_id ) {
|
|
||||||
$_widget = $wp_registered_widgets[$_widget_id];
|
|
||||||
|
|
||||||
if ( isset($_widget['params']) &&
|
|
||||||
is_array($_widget['params'][0]) &&
|
|
||||||
array_key_exists('number', $_widget['params'][0]) )
|
|
||||||
unset($wp_registered_widgets[$_widget_id]['params'][0]['number']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
call_user_func_array( $control['callback'], $control['params'] );
|
call_user_func_array( $control['callback'], $control['params'] );
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
|
@ -1347,6 +1317,13 @@ case 'save-widget' :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
|
||||||
|
$sidebars[$sidebar_id] = $sidebar;
|
||||||
|
wp_set_sidebars_widgets($sidebars);
|
||||||
|
echo "deleted:$widget_id";
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
die('1');
|
die('1');
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
|
|
|
@ -240,7 +240,7 @@ div#sidebar-info {
|
||||||
display: block;
|
display: block;
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
line-height: 24px;
|
line-height: 26px;
|
||||||
padding: 0 8px 0 0;
|
padding: 0 8px 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +256,7 @@ a.widget-control-edit {
|
||||||
#available-widgets .widget-control-edit .add,
|
#available-widgets .widget-control-edit .add,
|
||||||
#widgets-right .widget-control-edit .edit,
|
#widgets-right .widget-control-edit .edit,
|
||||||
#wp_inactive_widgets .widget-control-edit .edit {
|
#wp_inactive_widgets .widget-control-edit .edit {
|
||||||
display: block;
|
display: inline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.editwidget {
|
.editwidget {
|
||||||
|
|
|
@ -47,8 +47,11 @@ function retrieve_widgets() {
|
||||||
|
|
||||||
unset( $sidebars_widgets['array_version'] );
|
unset( $sidebars_widgets['array_version'] );
|
||||||
|
|
||||||
$diff = array_diff( array_keys($sidebars_widgets), $sidebars );
|
$old = array_keys($sidebars_widgets);
|
||||||
if ( empty($diff) )
|
sort($old);
|
||||||
|
sort($sidebars);
|
||||||
|
|
||||||
|
if ( $old == $sidebars )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Move the known-good ones first
|
// Move the known-good ones first
|
||||||
|
@ -68,6 +71,7 @@ function retrieve_widgets() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// discard invalid, theme-specific widgets from sidebars
|
// discard invalid, theme-specific widgets from sidebars
|
||||||
|
$shown_widgets = array();
|
||||||
foreach ( $_sidebars_widgets as $sidebar => $widgets ) {
|
foreach ( $_sidebars_widgets as $sidebar => $widgets ) {
|
||||||
if ( !is_array($widgets) )
|
if ( !is_array($widgets) )
|
||||||
continue;
|
continue;
|
||||||
|
@ -78,39 +82,24 @@ function retrieve_widgets() {
|
||||||
$_widgets[] = $widget;
|
$_widgets[] = $widget;
|
||||||
}
|
}
|
||||||
$_sidebars_widgets[$sidebar] = $_widgets;
|
$_sidebars_widgets[$sidebar] = $_widgets;
|
||||||
|
$shown_widgets = array_merge($shown_widgets, $_widgets);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sidebars_widgets = $_sidebars_widgets;
|
$sidebars_widgets = $_sidebars_widgets;
|
||||||
unset($_sidebars_widgets, $_widgets);
|
unset($_sidebars_widgets, $_widgets);
|
||||||
|
|
||||||
// find hidden/lost multi-widget instances
|
// find hidden/lost multi-widget instances
|
||||||
$shown_widgets = array();
|
|
||||||
foreach ( $sidebars_widgets as $sidebar ) {
|
|
||||||
if ( is_array($sidebar) )
|
|
||||||
$shown_widgets = array_merge($shown_widgets, $sidebar);
|
|
||||||
}
|
|
||||||
|
|
||||||
$all_widgets = array();
|
|
||||||
foreach ( $wp_registered_widget_updates as $key => $val ) {
|
|
||||||
if ( isset($val['id_base']) )
|
|
||||||
$all_widgets[] = $val['id_base'];
|
|
||||||
else
|
|
||||||
$all_widgets[] = $key;
|
|
||||||
}
|
|
||||||
|
|
||||||
$all_widgets = array_unique($all_widgets);
|
|
||||||
|
|
||||||
$lost_widgets = array();
|
$lost_widgets = array();
|
||||||
foreach ( $all_widgets as $name ) {
|
foreach ( $wp_registered_widgets as $key => $val ) {
|
||||||
$data = get_option( str_replace('-', '_', "widget_$name") );
|
if ( in_array($key, $shown_widgets, true) )
|
||||||
if ( is_array($data) ) {
|
continue;
|
||||||
foreach ( $data as $num => $value ) {
|
|
||||||
if ( !is_numeric($num) ) // skip single widgets, some don't delete their settings
|
$number = preg_replace('/.+?-([0-9]+)$/', '$1', $key);
|
||||||
continue;
|
|
||||||
if ( is_array($value) && !in_array("$name-$num", $shown_widgets, true) )
|
if ( 2 > (int) $number )
|
||||||
$lost_widgets[] = "$name-$num";
|
continue;
|
||||||
}
|
|
||||||
}
|
$lost_widgets[] = $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sidebars_widgets['wp_inactive_widgets'] = array_merge($lost_widgets, (array) $sidebars_widgets['wp_inactive_widgets']);
|
$sidebars_widgets['wp_inactive_widgets'] = array_merge($lost_widgets, (array) $sidebars_widgets['wp_inactive_widgets']);
|
||||||
|
@ -142,74 +131,59 @@ if ( isset($_POST['savewidget']) || isset($_POST['removewidget']) ) {
|
||||||
$widget_id = $_POST['widget-id'];
|
$widget_id = $_POST['widget-id'];
|
||||||
check_admin_referer("save-delete-widget-$widget_id");
|
check_admin_referer("save-delete-widget-$widget_id");
|
||||||
|
|
||||||
$sidebar_id = $_POST['insidebar'];
|
$number = isset($_POST['multi_number']) ? (int) $_POST['multi_number'] : '';
|
||||||
|
if ( $number ) {
|
||||||
|
foreach ( $_POST as $key => $val ) {
|
||||||
|
if ( is_array($val) && preg_match('/__i__|%i%/', key($val)) ) {
|
||||||
|
$_POST[$key] = array( $number => array_shift($val) );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sidebar_id = $_POST['sidebar'];
|
||||||
$position = isset($_POST[$sidebar_id . '_position']) ? (int) $_POST[$sidebar_id . '_position'] - 1 : 0;
|
$position = isset($_POST[$sidebar_id . '_position']) ? (int) $_POST[$sidebar_id . '_position'] - 1 : 0;
|
||||||
$_POST['sidebar'] = $sidebar_id;
|
|
||||||
|
|
||||||
$id_base = $_POST['id_base'];
|
$id_base = $_POST['id_base'];
|
||||||
$number = isset($_POST['multi_number']) ? $_POST['multi_number'] : '';
|
|
||||||
$sidebar = isset($sidebars_widgets[$sidebar_id]) ? $sidebars_widgets[$sidebar_id] : array();
|
$sidebar = isset($sidebars_widgets[$sidebar_id]) ? $sidebars_widgets[$sidebar_id] : array();
|
||||||
|
|
||||||
// delete
|
// delete
|
||||||
if ( isset($_POST['removewidget']) && $_POST['removewidget'] ) {
|
if ( isset($_POST['removewidget']) && $_POST['removewidget'] ) {
|
||||||
$widget = isset($wp_registered_widgets[$widget_id]) ? $wp_registered_widgets[$widget_id] : false;
|
|
||||||
|
|
||||||
if ( !in_array($widget_id, $sidebar, true) || !$widget ) {
|
if ( !in_array($widget_id, $sidebar, true) ) {
|
||||||
wp_redirect('widgets.php?error=0');
|
wp_redirect('widgets.php?error=0');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$option = str_replace( '-', '_', 'widget_' . $id_base );
|
|
||||||
$data = get_option($option);
|
|
||||||
|
|
||||||
if ( isset($widget['params'][0]['number']) ) {
|
|
||||||
$number = $widget['params'][0]['number'];
|
|
||||||
if ( is_array($data) && isset($data[$number]) ) {
|
|
||||||
unset( $data[$number] );
|
|
||||||
update_option($option, $data);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ( $data ) {
|
|
||||||
$data = array();
|
|
||||||
update_option($option, $data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$sidebar = array_diff( $sidebar, array($widget_id) );
|
$sidebar = array_diff( $sidebar, array($widget_id) );
|
||||||
} else {
|
$_POST = array('sidebar' => $sidebar_id, 'widget-' . $id_base => array(), 'the-widget-id' => $widget_id, 'delete_widget' => '1');
|
||||||
// save
|
}
|
||||||
foreach ( (array) $wp_registered_widget_updates as $name => $control ) {
|
|
||||||
if ( $name != $id_base || !is_callable($control['callback']) )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if ( $number ) {
|
$_POST['widget-id'] = $sidebar;
|
||||||
// don't delete other instances of the same multi-widget
|
|
||||||
foreach ( $sidebar as $_widget_id ) {
|
|
||||||
if ( isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) )
|
|
||||||
unset($wp_registered_widgets[$_widget_id]['params'][0]['number']);
|
|
||||||
}
|
|
||||||
$widget_id = "$id_base-$number";
|
|
||||||
}
|
|
||||||
|
|
||||||
ob_start();
|
foreach ( (array) $wp_registered_widget_updates as $name => $control ) {
|
||||||
call_user_func_array( $control['callback'], $control['params'] );
|
if ( $name != $id_base || !is_callable($control['callback']) )
|
||||||
ob_end_clean();
|
continue;
|
||||||
|
|
||||||
// remove old position
|
ob_start();
|
||||||
$sidebar = array_diff( $sidebar, array($widget_id) );
|
call_user_func_array( $control['callback'], $control['params'] );
|
||||||
foreach ( $sidebars_widgets as $key => $sb ) {
|
ob_end_clean();
|
||||||
if ( is_array($sb) && in_array($widget_id, $sb, true) )
|
|
||||||
$sidebars_widgets[$key] = array_diff( $sb, array($widget_id) );
|
|
||||||
}
|
|
||||||
|
|
||||||
array_splice( $sidebar, $position, 0, $widget_id );
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$sidebars_widgets[$sidebar_id] = $sidebar;
|
$sidebars_widgets[$sidebar_id] = $sidebar;
|
||||||
wp_set_sidebars_widgets($sidebars_widgets);
|
|
||||||
|
|
||||||
|
// remove old position
|
||||||
|
if ( !isset($_POST['delete_widget']) ) {
|
||||||
|
foreach ( $sidebars_widgets as $key => $sb ) {
|
||||||
|
if ( is_array($sb) )
|
||||||
|
$sidebars_widgets[$key] = array_diff( $sb, array($widget_id) );
|
||||||
|
}
|
||||||
|
array_splice( $sidebars_widgets[$sidebar_id], $position, 0, $widget_id );
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_set_sidebars_widgets($sidebars_widgets);
|
||||||
wp_redirect('widgets.php?message=0');
|
wp_redirect('widgets.php?message=0');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -228,8 +202,8 @@ if ( isset($_GET['editwidget']) && $_GET['editwidget'] ) {
|
||||||
if ( $_GET['base'] === $control['id_base'] ) {
|
if ( $_GET['base'] === $control['id_base'] ) {
|
||||||
$control_callback = $control['callback'];
|
$control_callback = $control['callback'];
|
||||||
$multi_number = (int) $_GET['num'];
|
$multi_number = (int) $_GET['num'];
|
||||||
$control['params'][0]['number'] = $multi_number;
|
$control['params'][0]['number'] = -1;
|
||||||
$control['id'] = $control['id_base'] . '-' . $multi_number;
|
$widget_id = $control['id'] = $control['id_base'] . '-' . $multi_number;
|
||||||
$wp_registered_widget_controls[$control['id']] = $control;
|
$wp_registered_widget_controls[$control['id']] = $control;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -240,8 +214,13 @@ if ( isset($_GET['editwidget']) && $_GET['editwidget'] ) {
|
||||||
if ( isset($wp_registered_widget_controls[$widget_id]) && !isset($control) ) {
|
if ( isset($wp_registered_widget_controls[$widget_id]) && !isset($control) ) {
|
||||||
$control = $wp_registered_widget_controls[$widget_id];
|
$control = $wp_registered_widget_controls[$widget_id];
|
||||||
$control_callback = $control['callback'];
|
$control_callback = $control['callback'];
|
||||||
|
} elseif ( !isset($wp_registered_widget_controls[$widget_id]) && isset($wp_registered_widgets[$widget_id]) ) {
|
||||||
|
$name = esc_html( strip_tags($wp_registered_widgets[$widget_id]['name']) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !isset($name) )
|
||||||
|
$name = esc_html( strip_tags($control['name']) );
|
||||||
|
|
||||||
if ( !isset($sidebar) )
|
if ( !isset($sidebar) )
|
||||||
$sidebar = isset($_GET['sidebar']) ? $_GET['sidebar'] : 'wp_inactive_widgets';
|
$sidebar = isset($_GET['sidebar']) ? $_GET['sidebar'] : 'wp_inactive_widgets';
|
||||||
|
|
||||||
|
@ -251,73 +230,73 @@ if ( isset($_GET['editwidget']) && $_GET['editwidget'] ) {
|
||||||
$id_base = isset($control['id_base']) ? $control['id_base'] : $control['id'];
|
$id_base = isset($control['id_base']) ? $control['id_base'] : $control['id'];
|
||||||
|
|
||||||
// show the widget form
|
// show the widget form
|
||||||
if ( is_callable( $control_callback ) ) {
|
$width = ' style="width:' . max($control['width'], 350) . 'px"';
|
||||||
$width = ' style="width:' . max($control['width'], 350) . 'px"';
|
$key = isset($_GET['key']) ? (int) $_GET['key'] : 0;
|
||||||
$key = isset($_GET['key']) ? (int) $_GET['key'] : 0;
|
|
||||||
|
|
||||||
require_once( 'admin-header.php' ); ?>
|
require_once( 'admin-header.php' ); ?>
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
<?php screen_icon(); ?>
|
<?php screen_icon(); ?>
|
||||||
<h2><?php echo esc_html( $title ); ?></h2>
|
<h2><?php echo esc_html( $title ); ?></h2>
|
||||||
<div class="editwidget"<?php echo $width; ?>>
|
<div class="editwidget"<?php echo $width; ?>>
|
||||||
<h3><?php printf( __( 'Widget %s' ), esc_html( strip_tags($control['name']) ) ); ?></h3>
|
<h3><?php printf( __( 'Widget %s' ), $name ); ?></h3>
|
||||||
|
|
||||||
<form action="widgets.php" method="post">
|
<form action="widgets.php" method="post">
|
||||||
<div class="widget-inside">
|
<div class="widget-inside">
|
||||||
<?php call_user_func_array( $control_callback, $control['params'] ); ?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p class="describe"><?php _e('Select both the sidebar for this widget and the position of the widget in that sidebar.'); ?></p>
|
|
||||||
<div class="widget-position">
|
|
||||||
<table class="widefat"><thead><tr><th><?php _e('Sidebar'); ?></th><th><?php _e('Position'); ?></th></tr></thead><tbody>
|
|
||||||
<?php foreach ( $wp_registered_sidebars as $sbname => $sbvalue ) {
|
|
||||||
echo "\t\t<tr><td><label><input type='radio' name='insidebar' value='" . esc_attr($sbname) . "'" . checked( $sbname, $sidebar, false ) . " /> $sbvalue[name]</label></td><td>";
|
|
||||||
if ( 'wp_inactive_widgets' == $sbname ) {
|
|
||||||
echo ' ';
|
|
||||||
} else {
|
|
||||||
if ( !isset($sidebars_widgets[$sbname]) || !is_array($sidebars_widgets[$sbname]) ) {
|
|
||||||
$j = 1;
|
|
||||||
} else {
|
|
||||||
$j = count($sidebars_widgets[$sbname]);
|
|
||||||
if ( isset($_GET['addnew']) || !in_array($widget_id, $sidebars_widgets[$sbname], true) )
|
|
||||||
$j++;
|
|
||||||
}
|
|
||||||
$selected = '';
|
|
||||||
echo "\t\t<select name='{$sbname}_position'>\n";
|
|
||||||
echo "\t\t<option value=''>" . __('-- select --') . "</option>\n";
|
|
||||||
for ( $i = 1; $i <= $j; $i++ ) {
|
|
||||||
if ( in_array($widget_id, $sidebars_widgets[$sbname], true) )
|
|
||||||
$selected = selected( $i, $key + 1, false );
|
|
||||||
echo "\t\t<option value='$i'$selected> $i </option>\n";
|
|
||||||
}
|
|
||||||
echo "\t\t</select>\n";
|
|
||||||
}
|
|
||||||
echo "</td></tr>\n";
|
|
||||||
} ?>
|
|
||||||
</tbody></table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="widget-control-actions">
|
|
||||||
<?php if ( isset($_GET['addnew']) ) { ?>
|
|
||||||
<a href="widgets.php" class="button alignleft"><?php _e('Cancel'); ?></a>
|
|
||||||
<?php } else { ?>
|
|
||||||
<input type="submit" name="removewidget" class="button alignleft" value="<?php esc_attr_e('Remove'); ?>" />
|
|
||||||
<?php } ?>
|
|
||||||
<input type="submit" name="savewidget" class="button-primary alignright" value="<?php esc_attr_e('Save Widget'); ?>" />
|
|
||||||
<input type="hidden" name="widget-id" class="widget-id" value="<?php echo esc_attr($widget_id); ?>" />
|
|
||||||
<input type="hidden" name="id_base" class="id_base" value="<?php echo esc_attr($id_base); ?>" />
|
|
||||||
<input type="hidden" name="multi_number" class="multi_number" value="<?php echo esc_attr($multi_number); ?>" />
|
|
||||||
<?php wp_nonce_field("save-delete-widget-$widget_id"); ?>
|
|
||||||
<br class="clear" />
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<?php
|
<?php
|
||||||
require_once( 'admin-footer.php' );
|
if ( is_callable( $control_callback ) )
|
||||||
exit;
|
call_user_func_array( $control_callback, $control['params'] );
|
||||||
}
|
else
|
||||||
wp_redirect('widgets.php?error=1');
|
echo '<p>' . __('There are no options for this widget.') . "</p>\n"; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="describe"><?php _e('Select both the sidebar for this widget and the position of the widget in that sidebar.'); ?></p>
|
||||||
|
<div class="widget-position">
|
||||||
|
<table class="widefat"><thead><tr><th><?php _e('Sidebar'); ?></th><th><?php _e('Position'); ?></th></tr></thead><tbody>
|
||||||
|
<?php foreach ( $wp_registered_sidebars as $sbname => $sbvalue ) {
|
||||||
|
echo "\t\t<tr><td><label><input type='radio' name='sidebar' value='" . esc_attr($sbname) . "'" . checked( $sbname, $sidebar, false ) . " /> $sbvalue[name]</label></td><td>";
|
||||||
|
if ( 'wp_inactive_widgets' == $sbname ) {
|
||||||
|
echo ' ';
|
||||||
|
} else {
|
||||||
|
if ( !isset($sidebars_widgets[$sbname]) || !is_array($sidebars_widgets[$sbname]) ) {
|
||||||
|
$j = 1;
|
||||||
|
} else {
|
||||||
|
$j = count($sidebars_widgets[$sbname]);
|
||||||
|
if ( isset($_GET['addnew']) || !in_array($widget_id, $sidebars_widgets[$sbname], true) )
|
||||||
|
$j++;
|
||||||
|
}
|
||||||
|
$selected = '';
|
||||||
|
echo "\t\t<select name='{$sbname}_position'>\n";
|
||||||
|
echo "\t\t<option value=''>" . __('-- select --') . "</option>\n";
|
||||||
|
for ( $i = 1; $i <= $j; $i++ ) {
|
||||||
|
if ( in_array($widget_id, $sidebars_widgets[$sbname], true) )
|
||||||
|
$selected = selected( $i, $key + 1, false );
|
||||||
|
echo "\t\t<option value='$i'$selected> $i </option>\n";
|
||||||
|
}
|
||||||
|
echo "\t\t</select>\n";
|
||||||
|
}
|
||||||
|
echo "</td></tr>\n";
|
||||||
|
} ?>
|
||||||
|
</tbody></table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="widget-control-actions">
|
||||||
|
<?php if ( isset($_GET['addnew']) ) { ?>
|
||||||
|
<a href="widgets.php" class="button alignleft"><?php _e('Cancel'); ?></a>
|
||||||
|
<?php } else { ?>
|
||||||
|
<input type="submit" name="removewidget" class="button alignleft" value="<?php esc_attr_e('Remove'); ?>" />
|
||||||
|
<?php } ?>
|
||||||
|
<input type="submit" name="savewidget" class="button-primary alignright" value="<?php esc_attr_e('Save Widget'); ?>" />
|
||||||
|
<input type="hidden" name="widget-id" class="widget-id" value="<?php echo esc_attr($widget_id); ?>" />
|
||||||
|
<input type="hidden" name="id_base" class="id_base" value="<?php echo esc_attr($id_base); ?>" />
|
||||||
|
<input type="hidden" name="multi_number" class="multi_number" value="<?php echo esc_attr($multi_number); ?>" />
|
||||||
|
<?php wp_nonce_field("save-delete-widget-$widget_id"); ?>
|
||||||
|
<br class="clear" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
require_once( 'admin-footer.php' );
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -759,9 +759,8 @@ class WP_Widget_RSS extends WP_Widget {
|
||||||
function form($instance) {
|
function form($instance) {
|
||||||
|
|
||||||
if ( empty($instance) )
|
if ( empty($instance) )
|
||||||
$instance = array( 'number' => '__i__', 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
|
$instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
|
||||||
else
|
$instance['number'] = $this->number;
|
||||||
$instance['number'] = $this->number;
|
|
||||||
|
|
||||||
wp_widget_rss_form( $instance );
|
wp_widget_rss_form( $instance );
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,58 +191,54 @@ class WP_Widget {
|
||||||
$all_instances = $this->get_settings();
|
$all_instances = $this->get_settings();
|
||||||
|
|
||||||
// We need to update the data
|
// We need to update the data
|
||||||
if ( !$this->updated && !empty($_POST['sidebar']) ) {
|
if ( $this->updated )
|
||||||
|
return;
|
||||||
|
|
||||||
// Tells us what sidebar to put the data in
|
$sidebars_widgets = wp_get_sidebars_widgets();
|
||||||
$sidebar = (string) $_POST['sidebar'];
|
|
||||||
|
|
||||||
$sidebars_widgets = wp_get_sidebars_widgets();
|
if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
|
||||||
if ( isset($sidebars_widgets[$sidebar]) )
|
// Delete the settings for this instance of the widget
|
||||||
$this_sidebar =& $sidebars_widgets[$sidebar];
|
if ( isset($_POST['the-widget-id']) )
|
||||||
|
$del_id = $_POST['the-widget-id'];
|
||||||
else
|
else
|
||||||
$this_sidebar = array();
|
return;
|
||||||
|
|
||||||
if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
|
if ( isset($wp_registered_widgets[$del_id]['params'][0]['number']) ) {
|
||||||
// Delete the settings for this instance of the widget
|
$number = $wp_registered_widgets[$del_id]['params'][0]['number'];
|
||||||
if ( isset($_POST['widget-id']) )
|
|
||||||
$del_id = $_POST['widget-id'];
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ( $this->_get_display_callback() == $wp_registered_widgets[$del_id]['callback'] && isset($wp_registered_widgets[$del_id]['params'][0]['number']) ) {
|
if ( $this->id_base . '-' . $number == $del_id )
|
||||||
$number = $wp_registered_widgets[$del_id]['params'][0]['number'];
|
unset($all_instances[$number]);
|
||||||
|
}
|
||||||
if ( $this->id_base . '-' . $number == $del_id ) {
|
} else {
|
||||||
unset($all_instances[$number]);
|
if ( isset($_POST['widget-' . $this->id_base]) && is_array($_POST['widget-' . $this->id_base]) ) {
|
||||||
}
|
$settings = $_POST['widget-' . $this->id_base];
|
||||||
}
|
} elseif ( isset($_POST['id_base']) && $_POST['id_base'] == $this->id_base ) {
|
||||||
|
$num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number'];
|
||||||
|
$settings = array( $num => array() );
|
||||||
} else {
|
} else {
|
||||||
if ( isset($_POST['widget-' . $this->id_base]) && is_array($_POST['widget-' . $this->id_base]) ) {
|
return;
|
||||||
$settings = $_POST['widget-' . $this->id_base];
|
|
||||||
} else {
|
|
||||||
$num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number'];
|
|
||||||
$settings = array( $num => array() );
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ( $settings as $number => $new_instance ) {
|
|
||||||
$new_instance = stripslashes_deep($new_instance);
|
|
||||||
$this->_set($number);
|
|
||||||
|
|
||||||
if ( isset($all_instances[$number]) )
|
|
||||||
$instance = $this->update($new_instance, $all_instances[$number]);
|
|
||||||
else
|
|
||||||
$instance = $this->update($new_instance, array());
|
|
||||||
|
|
||||||
// filters the widget's settings before saving, return false to cancel saving (keep the old settings if updating)
|
|
||||||
$instance = apply_filters('widget_update_callback', $instance, $new_instance, $this);
|
|
||||||
if ( false !== $instance )
|
|
||||||
$all_instances[$number] = $instance;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->save_settings($all_instances);
|
foreach ( $settings as $number => $new_instance ) {
|
||||||
$this->updated = true;
|
$new_instance = stripslashes_deep($new_instance);
|
||||||
|
$this->_set($number);
|
||||||
|
|
||||||
|
if ( isset($all_instances[$number]) )
|
||||||
|
$instance = $this->update($new_instance, $all_instances[$number]);
|
||||||
|
else
|
||||||
|
$instance = $this->update($new_instance, array());
|
||||||
|
|
||||||
|
// filters the widget's settings before saving, return false to cancel saving (keep the old settings if updating)
|
||||||
|
$instance = apply_filters('widget_update_callback', $instance, $new_instance, $this);
|
||||||
|
if ( false !== $instance )
|
||||||
|
$all_instances[$number] = $instance;
|
||||||
|
|
||||||
|
break; // run only once
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->save_settings($all_instances);
|
||||||
|
$this->updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Generate the control form.
|
/** Generate the control form.
|
||||||
|
|
Loading…
Reference in New Issue