Make WordPress Core

Ticket #23328: 23328.patch

File 23328.patch, 3.5 KB (added by afercia, 8 years ago)
  • src/wp-admin/css/widgets.css

     
    335335}
    336336
    337337.editwidget {
    338         margin: 0 auto;
     338        max-width: 40em; /* about 80 characters, for readability */
    339339}
    340340
     341.editwidget select {
     342    width: 100%;
     343}
     344
    341345.editwidget .widget-inside {
    342346        display: block;
    343347        padding: 0 15px;
  • src/wp-admin/widgets.php

     
    259259        $id_base = isset($control['id_base']) ? $control['id_base'] : $control['id'];
    260260
    261261        // Show the widget form.
    262         $width = ' style="width:' . max($control['width'], 350) . 'px"';
    263262        $key = isset($_GET['key']) ? (int) $_GET['key'] : 0;
    264263
    265264        require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?>
    266265        <div class="wrap">
    267266        <h1><?php echo esc_html( $title ); ?></h1>
    268         <div class="editwidget"<?php echo $width; ?>>
     267        <div class="editwidget">
    269268        <h2><?php printf( __( 'Widget %s' ), $name ); ?></h2>
    270269
    271270        <form action="widgets.php" method="post">
     
    279278
    280279        <p class="describe"><?php _e('Select both the sidebar for this widget and the position of the widget in that sidebar.'); ?></p>
    281280        <div class="widget-position">
    282         <table class="widefat"><thead><tr><th><?php _e('Sidebar'); ?></th><th><?php _e('Position'); ?></th></tr></thead><tbody>
     281        <table class="widefat"><thead><tr><th><?php _e('Sidebar'); ?></th><th><?php _e( 'Widget position' ); ?></th></tr></thead><tbody>
    283282<?php
    284283        foreach ( $wp_registered_sidebars as $sbname => $sbvalue ) {
    285284                echo "\t\t<tr><td><label><input type='radio' name='sidebar' value='" . esc_attr($sbname) . "'" . checked( $sbname, $sidebar, false ) . " /> $sbvalue[name]</label></td><td>";
     
    291290                                $sidebars_widgets[$sbname] = array();
    292291                        } else {
    293292                                $j = count($sidebars_widgets[$sbname]);
    294                                 if ( isset($_GET['addnew']) || !in_array($widget_id, $sidebars_widgets[$sbname], true) )
     293                                // When adding a new widget or the edited widget is not in this sidebar, add one more cycle to the loop below.
     294                                if ( isset($_GET['addnew']) || !in_array($widget_id, $sidebars_widgets[$sbname], true) ) {
    295295                                        $j++;
     296                                }
    296297                        }
    297298                        $selected = '';
     299                        $index = 0;
    298300                        echo "\t\t<select name='{$sbname}_position'>\n";
    299301                        echo "\t\t<option value=''>" . __('&mdash; Select &mdash;') . "</option>\n";
     302                        /*
     303                         * When adding a new widget or the edited widget is not in this sidebar, this loop runs
     304                         * one cycle more than the actual widgets count to build an empty option in the selects.
     305                         */
    300306                        for ( $i = 1; $i <= $j; $i++ ) {
    301                                 if ( in_array($widget_id, $sidebars_widgets[$sbname], true) )
     307
     308                                // Get the ID of the widget in the loop. Set it to false when running the additional loop cycle.
     309                                $wid = isset( $sidebars_widgets[$sbname][$index] ) ? $sidebars_widgets[$sbname][$index] : false;
     310                                // If the widget ID is set then get the widget name otherwise set a name for the empty option.
     311                                $wname = $wid ? sprintf( __( '(currently set to: %s)' ), $wp_registered_widgets[$wid]['name'] ) : esc_html_x( '(available position)', 'widget' );
     312
     313                                if ( in_array( $widget_id, $sidebars_widgets[$sbname], true ) ) {
    302314                                        $selected = selected( $i, $key + 1, false );
    303                                 echo "\t\t<option value='$i'$selected> $i </option>\n";
     315                                }
     316
     317                                echo "\t\t<option value='$i'$selected>$i $wname</option>\n";
     318                                $index++;
    304319                        }
    305320                        echo "\t\t</select>\n";
    306321                }