Skip to content

Commit b77fbe6

Browse files
Coding Standards: Use more meaningful variable names in Classic Widgets screen.
Per the [https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#naming-conventions 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. git-svn-id: https://develop.svn.wordpress.org/trunk@61187 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 682f534 commit b77fbe6

File tree

1 file changed

+36
-24
lines changed

1 file changed

+36
-24
lines changed

src/wp-admin/widgets-form.php

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,12 @@
187187

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
}
197198

@@ -235,11 +236,12 @@
235236
// Copy minimal info from an existing instance of this widget to a new instance.
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;
245247
}
@@ -299,31 +301,41 @@
299301
<div class="widget-position">
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
}
329341
?>
@@ -512,7 +524,7 @@
512524
</div>
513525
<?php
514526

515-
$i = 0;
527+
$sidebar_index = 0;
516528
$split = 0;
517529
$single_sidebar_class = '';
518530
$sidebars_count = count( $theme_sidebars );
@@ -535,11 +547,11 @@
535547
$wrap_class .= ' sidebar-' . $registered_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">
545557
<?php
@@ -554,7 +566,7 @@
554566
</div>
555567
<?php
556568

557-
++$i;
569+
++$sidebar_index;
558570
}
559571

560572
?>

0 commit comments

Comments
 (0)