Make WordPress Core

Changeset 61187


Ignore:
Timestamp:
11/09/2025 11:01:32 PM (10 months ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use more meaningful variable names in Classic Widgets screen.

Per the Naming Conventions:

Don’t abbreviate variable names unnecessarily; let the code be unambiguous and self-documenting.

This commit includes renaming of the following variables:

  • $sbname to $sidebar_name.
  • $sbvalue to $sidebar_data.
  • $j to $widget_count.
  • $i to $sidebar_index.
  • $sb to $sidebar.
  • $key to $sidebar_id.

Follow-up to [10912], [11009], [11427], [26285], [50997].

Props costdev, mukesh27.
See #63168.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/widgets-form.php

    r57295 r61187  
    188188        // Remove old position.
    189189        if ( ! isset( $_POST['delete_widget'] ) ) {
    190                 foreach ( $sidebars_widgets as $key => $sb ) {
    191                         if ( is_array( $sb ) ) {
    192                                 $sidebars_widgets[ $key ] = array_diff( $sb, array( $widget_id ) );
     190                foreach ( $sidebars_widgets as $sidebar_id => $sidebar ) {
     191                        if ( is_array( $sidebar ) ) {
     192                                $sidebars_widgets[ $sidebar_id ] = array_diff( $sidebar, array( $widget_id ) );
    193193                        }
    194194                }
     195
    195196                array_splice( $sidebars_widgets[ $sidebar_id ], $position, 0, $widget_id );
    196197        }
     
    236237                        foreach ( $wp_registered_widget_controls as $control ) {
    237238                                if ( $_GET['base'] === $control['id_base'] ) {
    238                                         $control_callback                                = $control['callback'];
    239                                         $multi_number                                    = (int) $_GET['num'];
    240                                         $control['params'][0]['number']                  = -1;
    241                                         $control['id']                                   = $control['id_base'] . '-' . $multi_number;
    242                                         $widget_id                                       = $control['id'];
     239                                        $control_callback               = $control['callback'];
     240                                        $multi_number                   = (int) $_GET['num'];
     241                                        $control['params'][0]['number'] = -1;
     242                                        $control['id']                  = $control['id_base'] . '-' . $multi_number;
     243                                        $widget_id                      = $control['id'];
     244
    243245                                        $wp_registered_widget_controls[ $control['id'] ] = $control;
    244246                                        break;
     
    300302        <table class="widefat"><thead><tr><th><?php _e( 'Sidebar' ); ?></th><th><?php _e( 'Position' ); ?></th></tr></thead><tbody>
    301303        <?php
    302         foreach ( $wp_registered_sidebars as $sbname => $sbvalue ) {
    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>";
    304                 if ( 'wp_inactive_widgets' === $sbname || str_starts_with( $sbname, 'orphaned_widgets' ) ) {
     304        foreach ( $wp_registered_sidebars as $sidebar_name => $sidebar_data ) {
     305                echo "\t\t<tr><td><label><input type='radio' name='sidebar' value='" . esc_attr( $sidebar_name ) . "'" .
     306                        checked( $sidebar_name, $sidebar, false ) . " /> $sidebar_data[name]</label></td><td>";
     307
     308                if ( 'wp_inactive_widgets' === $sidebar_name || str_starts_with( $sidebar_name, 'orphaned_widgets' ) ) {
    305309                        echo '&nbsp;';
    306310                } else {
    307                         if ( ! isset( $sidebars_widgets[ $sbname ] ) || ! is_array( $sidebars_widgets[ $sbname ] ) ) {
    308                                 $j                           = 1;
    309                                 $sidebars_widgets[ $sbname ] = array();
     311                        if ( ! isset( $sidebars_widgets[ $sidebar_name ] ) || ! is_array( $sidebars_widgets[ $sidebar_name ] ) ) {
     312                                $widget_count = 1;
     313
     314                                $sidebars_widgets[ $sidebar_name ] = array();
    310315                        } else {
    311                                 $j = count( $sidebars_widgets[ $sbname ] );
    312                                 if ( isset( $_GET['addnew'] ) || ! in_array( $widget_id, $sidebars_widgets[ $sbname ], true ) ) {
    313                                         ++$j;
     316                                $widget_count = count( $sidebars_widgets[ $sidebar_name ] );
     317
     318                                if ( isset( $_GET['addnew'] ) || ! in_array( $widget_id, $sidebars_widgets[ $sidebar_name ], true ) ) {
     319                                        ++$widget_count;
    314320                                }
    315321                        }
     322
    316323                        $selected = '';
    317                         echo "\t\t<select name='{$sbname}_position'>\n";
     324
     325                        echo "\t\t<select name='{$sidebar_name}_position'>\n";
    318326                        echo "\t\t<option value=''>" . __( '&mdash; Select &mdash;' ) . "</option>\n";
    319                         for ( $i = 1; $i <= $j; $i++ ) {
    320                                 if ( in_array( $widget_id, $sidebars_widgets[ $sbname ], true ) ) {
     327
     328                        for ( $i = 1; $i <= $widget_count; $i++ ) {
     329                                if ( in_array( $widget_id, $sidebars_widgets[ $sidebar_name ], true ) ) {
    321330                                        $selected = selected( $i, $key + 1, false );
    322331                                }
     332
    323333                                echo "\t\t<option value='$i'$selected> $i </option>\n";
    324334                        }
     335
    325336                        echo "\t\t</select>\n";
    326337                }
     338
    327339                echo "</td></tr>\n";
    328340        }
     
    513525<?php
    514526
    515 $i                    = 0;
     527$sidebar_index        = 0;
    516528$split                = 0;
    517529$single_sidebar_class = '';
     
    536548        }
    537549
    538         if ( $i > 0 ) {
     550        if ( $sidebar_index > 0 ) {
    539551                $wrap_class .= ' closed';
    540552        }
    541553
    542         if ( $split && $i === $split ) {
     554        if ( $split && $sidebar_index === $split ) {
    543555                ?>
    544556                </div><div class="sidebars-column-2">
     
    555567        <?php
    556568
    557         ++$i;
     569        ++$sidebar_index;
    558570}
    559571
Note: See TracChangeset for help on using the changeset viewer.