Ticket #23328: 23328.3.patch
File 23328.3.patch, 5.7 KB (added by , 7 years ago) |
---|
-
src/wp-admin/css/widgets.css
332 332 } 333 333 334 334 .editwidget { 335 ma rgin: 0 auto;335 max-width: 40em; /* about 80 characters, for readability */ 336 336 } 337 337 338 .editwidget select { 339 width: 100%; 340 } 341 338 342 .editwidget .widget-inside { 339 343 display: block; 340 344 padding: 0 15px; -
src/wp-admin/widgets.php
182 182 183 183 // Remove old position. 184 184 if ( !isset($_POST['delete_widget']) ) { 185 // Detect if the widget is registered, in case remove from the sidebar in editing 186 global $wp_widget_factory; 187 foreach ( $sidebars_widgets[$_POST['sidebar']] as $key => $sb ) { 188 $notfound = false; 189 foreach ( $wp_widget_factory->widgets as $widget_obj => $class ) { 190 // Get the base id of the widget 191 $widget_base_id = explode('-', $sb); 192 $widget_base_id = $widget_base_id[0]; 193 // We have found that widget? 194 if( $widget_base_id === $class->id_base ) { 195 $notfound = true; 196 } 197 } 198 // Inc ase not found we remove from the db 199 if( false === $notfound ) { 200 unset($sidebars_widgets[$_POST['sidebar']][$key]); 201 } 202 } 203 array_values($sidebars_widgets); 185 204 foreach ( $sidebars_widgets as $key => $sb ) { 186 205 if ( is_array($sb) ) 187 206 $sidebars_widgets[$key] = array_diff( $sb, array($widget_id) ); … … 259 278 $id_base = isset($control['id_base']) ? $control['id_base'] : $control['id']; 260 279 261 280 // Show the widget form. 262 $width = ' style="width:' . max($control['width'], 350) . 'px"';263 281 $key = isset($_GET['key']) ? (int) $_GET['key'] : 0; 264 282 265 283 require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?> 266 284 <div class="wrap"> 267 285 <h1><?php echo esc_html( $title ); ?></h1> 268 <div class="editwidget" <?php echo $width; ?>>286 <div class="editwidget"> 269 287 <h2><?php printf( __( 'Widget %s' ), $name ); ?></h2> 270 288 271 289 <form action="widgets.php" method="post"> … … 279 297 280 298 <p class="describe"><?php _e('Select both the sidebar for this widget and the position of the widget in that sidebar.'); ?></p> 281 299 <div class="widget-position"> 282 <table class="widefat"><thead><tr><th><?php _e( 'Sidebar'); ?></th><th><?php _e('Position'); ?></th></tr></thead><tbody>300 <table class="widefat"><thead><tr><th><?php _e( 'Sidebar' ); ?></th><th><?php _e( 'Widget position' ); ?></th></tr></thead><tbody> 283 301 <?php 284 302 foreach ( $wp_registered_sidebars as $sbname => $sbvalue ) { 285 303 echo "\t\t<tr><td><label><input type='radio' name='sidebar' value='" . esc_attr($sbname) . "'" . checked( $sbname, $sidebar, false ) . " /> $sbvalue[name]</label></td><td>"; … … 291 309 $sidebars_widgets[$sbname] = array(); 292 310 } else { 293 311 $j = count($sidebars_widgets[$sbname]); 294 if ( isset($_GET['addnew']) || !in_array($widget_id, $sidebars_widgets[$sbname], true) ) 312 // When adding a new widget or the edited widget is not in this sidebar, add one more cycle to the loop below. 313 if ( isset( $_GET['addnew'] ) || ! in_array( $widget_id, $sidebars_widgets[$sbname], true ) ) { 295 314 $j++; 315 } 296 316 } 297 317 $selected = ''; 318 $index = $widget_new_position = 0; 298 319 echo "\t\t<select name='{$sbname}_position'>\n"; 299 320 echo "\t\t<option value=''>" . __('— Select —') . "</option>\n"; 321 /* 322 * When adding a new widget or the edited widget is not in this sidebar, this loop runs 323 * one cycle more than the actual widgets count to build an empty option in the select. 324 */ 300 325 for ( $i = 1; $i <= $j; $i++ ) { 301 if ( in_array($widget_id, $sidebars_widgets[$sbname], true) ) 302 $selected = selected( $i, $key + 1, false ); 303 echo "\t\t<option value='$i'$selected> $i </option>\n"; 326 // Get the ID of the widget in the loop. Set it to false when running the additional loop cycle. 327 $sidebar_widget_id = isset( $sidebars_widgets[$sbname][$index] ) ? $sidebars_widgets[$sbname][$index] : false; 328 // If the widget is not avalaible o not exist add an available position option 329 if( empty( $sidebar_widget_id ) || isset( $wp_registered_widgets[$sidebar_widget_id]['name'] ) ) { 330 $widget_new_position++; 331 // If the widget ID is set then get the widget name otherwise set a name for the empty option. 332 $select_option_content = $sidebar_widget_id ? sprintf( __( '(currently set to: %s)' ), $wp_registered_widgets[$sidebar_widget_id]['name'] ) : esc_html_x( '(available position)', 'widget' ); 333 334 if ( in_array( $widget_id, $sidebars_widgets[$sbname], true ) ) { 335 $selected = selected( $i, $key + 1, false ); 336 } 337 338 echo "\t\t<option value='$widget_new_position'$selected>$widget_new_position $select_option_content</option>\n"; 339 } else { 340 // Add a new option because this code is executed only when the widget is removed from the check above 341 $j++; 342 } 343 $index++; 304 344 } 305 345 echo "\t\t</select>\n"; 306 346 }