Skip to content

Commit

Permalink
Avoid data-loss when editing multi-widgets. Props mdawaffe. fixes #66…
Browse files Browse the repository at this point in the history
…36 for 2.5

git-svn-id: https://develop.svn.wordpress.org/branches/2.5@7621 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
ryanboren committed Apr 7, 2008
1 parent 66930bb commit 2d49a29
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions wp-admin/js/widgets.js
Expand Up @@ -11,7 +11,7 @@ jQuery(function($) {
var widgetAnim = $.browser.msie ? function() {
var t = $(this);
if ( t.is(':visible') ) {
if ( disableFields ) { t.find( ':enabled' ).not( '[name="widget-id[]"], [name*="[submit]"]' ).attr( 'disabled', 'disabled' ); }
if ( disableFields ) { t.find( ':input:enabled' ).not( '[name="widget-id[]"], [name*="[submit]"]' ).attr( 'disabled', 'disabled' ); }
li.css( 'marginLeft', 0 );
t.siblings('h4').children('a').text( widgetsL10n.edit );
} else {
Expand All @@ -25,7 +25,7 @@ jQuery(function($) {
var t = $(this);

if ( t.is(':visible') ) {
if ( disableFields ) { t.find( ':enabled' ).not( '[name="widget-id[]"], [name*="[submit]"]' ).attr( 'disabled', 'disabled' ); }
if ( disableFields ) { t.find( ':input:enabled' ).not( '[name="widget-id[]"], [name*="[submit]"]' ).attr( 'disabled', 'disabled' ); }
if ( width > 250 )
li.animate( { marginLeft: 0 } );
t.siblings('h4').children('a').text( widgetsL10n.edit );
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/script-loader.php
Expand Up @@ -187,7 +187,7 @@ function default_scripts() {
'saveText' => attribute_escape(__('Save »')),
'confirmText' => __("Are you sure you want to delete the file '%title%'?\nClick ok to delete or cancel to go back.")
) );
$this->add( 'admin-widgets', '/wp-admin/js/widgets.js', array( 'interface' ), '20080319' );
$this->add( 'admin-widgets', '/wp-admin/js/widgets.js', array( 'interface' ), '20080407c' );
$this->localize( 'admin-widgets', 'widgetsL10n', array(
'add' => __('Add'),
'edit' => __('Edit'),
Expand Down
8 changes: 8 additions & 0 deletions wp-includes/widgets.php
Expand Up @@ -614,6 +614,8 @@ function wp_widget_text_control($widget_args) {
}

foreach ( (array) $_POST['widget-text'] as $widget_number => $widget_text ) {
if ( !isset($widget_text['text']) && isset($options[$widget_number]) ) // user clicked cancel
continue;
$title = strip_tags(stripslashes($widget_text['title']));
if ( current_user_can('unfiltered_html') )
$text = stripslashes( $widget_text['text'] );
Expand Down Expand Up @@ -750,6 +752,8 @@ function wp_widget_categories_control( $widget_args ) {
}

foreach ( (array) $_POST['widget-categories'] as $widget_number => $widget_cat ) {
if ( !isset($widget_cat['title']) && isset($options[$widget_number]) ) // user clicked cancel
continue;
$title = trim(strip_tags(stripslashes($widget_cat['title'])));
$count = isset($widget_cat['count']);
$hierarchical = isset($widget_cat['hierarchical']);
Expand Down Expand Up @@ -1170,6 +1174,8 @@ function wp_widget_rss_control($widget_args) {
}

foreach( (array) $_POST['widget-rss'] as $widget_number => $widget_rss ) {
if ( !isset($widget_rss['url']) && isset($options[$widget_number]) ) // user clicked cancel
continue;
$widget_rss = stripslashes_deep( $widget_rss );
$url = sanitize_url(strip_tags($widget_rss['url']));
$options[$widget_number] = wp_widget_rss_process( $widget_rss, !isset($urls[$url]) );
Expand Down Expand Up @@ -1460,6 +1466,8 @@ function widget_many_control( $widget_args = 1 ) {
foreach ( (array) $_POST['widget-many'] as $widget_number => $widget_many_instance ) {
// compile data from $widget_many_instance
if ( !isset($widget_many_instance['something']) && isset($options[$widget_number]) ) // user clicked cancel
continue;
$something = wp_specialchars( $widget_many_instance['something'] );
$options[$widget_number] = array( 'something' => $something ); // Even simple widgets should store stuff in array, rather than in scalar
}
Expand Down

0 comments on commit 2d49a29

Please sign in to comment.