Skip to content

Commit 48e5ac7

Browse files
Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/template.php.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names. This commit: * Renames the `$echo` parameter to `$display` in: * `wp_popular_terms_checklist()` * `_post_states()` * `_media_states()` * Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`. * Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`. * Renames the `$default` parameter to `$default_page` in `parent_dropdown()`. * Renames the `$object` parameter to `$data_object` in: * `do_block_editor_incompatible_meta_box()` * `do_meta_boxes()` * `do_accordion_sections()` * Amends the `$item_object` parameter in other functions for consistency: * `wp_nav_menu_item_post_type_meta_box()` * `wp_nav_menu_item_taxonomy_meta_box()` * `_wp_nav_menu_meta_box_object()` Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216]. Props jrf, aristath, poena, justinahinon, SergeyBiryukov. See #55327. git-svn-id: https://develop.svn.wordpress.org/trunk@53220 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 5d3a78b commit 48e5ac7

2 files changed

Lines changed: 67 additions & 63 deletions

File tree

src/wp-admin/includes/nav-menu.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ function wp_nav_menu_item_link_meta_box() {
325325
* @global int $_nav_menu_placeholder
326326
* @global int|string $nav_menu_selected_id
327327
*
328-
* @param string $item_object Not used.
328+
* @param string $data_object Not used.
329329
* @param array $box {
330330
* Post type menu item meta box arguments.
331331
*
@@ -335,7 +335,7 @@ function wp_nav_menu_item_link_meta_box() {
335335
* @type WP_Post_Type $args Extra meta box arguments (the post type object for this meta box).
336336
* }
337337
*/
338-
function wp_nav_menu_item_post_type_meta_box( $item_object, $box ) {
338+
function wp_nav_menu_item_post_type_meta_box( $data_object, $box ) {
339339
global $_nav_menu_placeholder, $nav_menu_selected_id;
340340

341341
$post_type_name = $box['args']->name;
@@ -689,7 +689,7 @@ function wp_nav_menu_item_post_type_meta_box( $item_object, $box ) {
689689
*
690690
* @global int|string $nav_menu_selected_id
691691
*
692-
* @param string $item_object Not used.
692+
* @param string $data_object Not used.
693693
* @param array $box {
694694
* Taxonomy menu item meta box arguments.
695695
*
@@ -699,7 +699,7 @@ function wp_nav_menu_item_post_type_meta_box( $item_object, $box ) {
699699
* @type object $args Extra meta box arguments (the taxonomy object for this meta box).
700700
* }
701701
*/
702-
function wp_nav_menu_item_taxonomy_meta_box( $item_object, $box ) {
702+
function wp_nav_menu_item_taxonomy_meta_box( $data_object, $box ) {
703703
global $nav_menu_selected_id;
704704

705705
$taxonomy_name = $box['args']->name;
@@ -989,40 +989,40 @@ function wp_save_nav_menu_items( $menu_id = 0, $menu_data = array() ) {
989989
*
990990
* @access private
991991
*
992-
* @param object $item_object The post type or taxonomy meta-object.
992+
* @param object $data_object The post type or taxonomy meta-object.
993993
* @return object The post type or taxonomy object.
994994
*/
995995
function _wp_nav_menu_meta_box_object( $item_object = null ) {
996-
if ( isset( $item_object->name ) ) {
996+
if ( isset( $data_object->name ) ) {
997997

998-
if ( 'page' === $item_object->name ) {
999-
$item_object->_default_query = array(
998+
if ( 'page' === $data_object->name ) {
999+
$data_object->_default_query = array(
10001000
'orderby' => 'menu_order title',
10011001
'post_status' => 'publish',
10021002
);
10031003

10041004
// Posts should show only published items.
1005-
} elseif ( 'post' === $item_object->name ) {
1006-
$item_object->_default_query = array(
1005+
} elseif ( 'post' === $data_object->name ) {
1006+
$data_object->_default_query = array(
10071007
'post_status' => 'publish',
10081008
);
10091009

10101010
// Categories should be in reverse chronological order.
1011-
} elseif ( 'category' === $item_object->name ) {
1012-
$item_object->_default_query = array(
1011+
} elseif ( 'category' === $data_object->name ) {
1012+
$data_object->_default_query = array(
10131013
'orderby' => 'id',
10141014
'order' => 'DESC',
10151015
);
10161016

10171017
// Custom post types should show only published items.
10181018
} else {
1019-
$item_object->_default_query = array(
1019+
$data_object->_default_query = array(
10201020
'post_status' => 'publish',
10211021
);
10221022
}
10231023
}
10241024

1025-
return $item_object;
1025+
return $data_object;
10261026
}
10271027

10281028
/**

src/wp-admin/includes/template.php

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,20 @@ function wp_terms_checklist( $post_id = 0, $args = array() ) {
193193
/**
194194
* Retrieves a list of the most popular terms from the specified taxonomy.
195195
*
196-
* If the $echo argument is true then the elements for a list of checkbox
196+
* If the `$display` argument is true then the elements for a list of checkbox
197197
* `<input>` elements labelled with the names of the selected terms is output.
198-
* If the $post_ID global is not empty then the terms associated with that
198+
* If the `$post_ID` global is not empty then the terms associated with that
199199
* post will be marked as checked.
200200
*
201201
* @since 2.5.0
202202
*
203-
* @param string $taxonomy Taxonomy to retrieve terms from.
204-
* @param int $default Not used.
205-
* @param int $number Number of terms to retrieve. Defaults to 10.
206-
* @param bool $echo Optionally output the list as well. Defaults to true.
203+
* @param string $taxonomy Taxonomy to retrieve terms from.
204+
* @param int $default_term Optional. Not used.
205+
* @param int $number Optional. Number of terms to retrieve. Default 10.
206+
* @param bool $display Optional. Whether to display the list as well. Default true.
207207
* @return int[] Array of popular term IDs.
208208
*/
209-
function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
209+
function wp_popular_terms_checklist( $taxonomy, $default_term = 0, $number = 10, $display = true ) {
210210
$post = get_post();
211211

212212
if ( $post && $post->ID ) {
@@ -231,9 +231,11 @@ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $ech
231231

232232
foreach ( (array) $terms as $term ) {
233233
$popular_ids[] = $term->term_id;
234-
if ( ! $echo ) { // Hack for Ajax use.
234+
235+
if ( ! $display ) { // Hack for Ajax use.
235236
continue;
236237
}
238+
237239
$id = "popular-$taxonomy-$term->term_id";
238240
$checked = in_array( $term->term_id, $checked_terms, true ) ? 'checked="checked"' : '';
239241
?>
@@ -874,16 +876,16 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
874876
* @since 1.5.0
875877
* @since 4.7.0 Added the `$post_type` parameter.
876878
*
877-
* @param string $default Optional. The template file name. Default empty.
878-
* @param string $post_type Optional. Post type to get templates for. Default 'post'.
879+
* @param string $default_template Optional. The template file name. Default empty.
880+
* @param string $post_type Optional. Post type to get templates for. Default 'post'.
879881
*/
880-
function page_template_dropdown( $default = '', $post_type = 'page' ) {
882+
function page_template_dropdown( $default_template = '', $post_type = 'page' ) {
881883
$templates = get_page_templates( null, $post_type );
882884

883885
ksort( $templates );
884886

885887
foreach ( array_keys( $templates ) as $template ) {
886-
$selected = selected( $default, $templates[ $template ], false );
888+
$selected = selected( $default_template, $templates[ $template ], false );
887889
echo "\n\t<option value='" . esc_attr( $templates[ $template ] ) . "' $selected>" . esc_html( $template ) . '</option>';
888890
}
889891
}
@@ -896,13 +898,13 @@ function page_template_dropdown( $default = '', $post_type = 'page' ) {
896898
*
897899
* @global wpdb $wpdb WordPress database abstraction object.
898900
*
899-
* @param int $default Optional. The default page ID to be pre-selected. Default 0.
900-
* @param int $parent Optional. The parent page ID. Default 0.
901-
* @param int $level Optional. Page depth level. Default 0.
902-
* @param int|WP_Post $post Post ID or WP_Post object.
901+
* @param int $default_page Optional. The default page ID to be pre-selected. Default 0.
902+
* @param int $parent Optional. The parent page ID. Default 0.
903+
* @param int $level Optional. Page depth level. Default 0.
904+
* @param int|WP_Post $post Post ID or WP_Post object.
903905
* @return void|false Void on success, false if the page has no children.
904906
*/
905-
function parent_dropdown( $default = 0, $parent = 0, $level = 0, $post = null ) {
907+
function parent_dropdown( $default_page = 0, $parent = 0, $level = 0, $post = null ) {
906908
global $wpdb;
907909

908910
$post = get_post( $post );
@@ -916,10 +918,10 @@ function parent_dropdown( $default = 0, $parent = 0, $level = 0, $post = null )
916918
}
917919

918920
$pad = str_repeat( '&nbsp;', $level * 3 );
919-
$selected = selected( $default, $item->ID, false );
921+
$selected = selected( $default_page, $item->ID, false );
920922

921923
echo "\n\t<option class='level-$level' value='$item->ID' $selected>$pad " . esc_html( $item->post_title ) . '</option>';
922-
parent_dropdown( $default, $item->ID, $level + 1 );
924+
parent_dropdown( $default_page, $item->ID, $level + 1 );
923925
}
924926
} else {
925927
return false;
@@ -1128,8 +1130,8 @@ function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advan
11281130
*
11291131
* @since 5.0.0
11301132
*
1131-
* @param mixed $object The data object being rendered on this screen.
1132-
* @param array $box {
1133+
* @param mixed $data_object The data object being rendered on this screen.
1134+
* @param array $box {
11331135
* Custom formats meta box arguments.
11341136
*
11351137
* @type string $id Meta box 'id' attribute.
@@ -1138,7 +1140,7 @@ function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advan
11381140
* @type array $args Extra meta box arguments.
11391141
* }
11401142
*/
1141-
function do_block_editor_incompatible_meta_box( $object, $box ) {
1143+
function do_block_editor_incompatible_meta_box( $data_object, $box ) {
11421144
$plugin = _get_plugin_from_callback( $box['old_callback'] );
11431145
$plugins = get_plugins();
11441146
echo '<p>';
@@ -1174,13 +1176,13 @@ function do_block_editor_incompatible_meta_box( $object, $box ) {
11741176
printf( __( 'Please activate the <a href="%s">Classic Editor plugin</a> to use this meta box.' ), esc_url( $activate_url ) );
11751177
echo '</p>';
11761178
}
1177-
} elseif ( $object instanceof WP_Post ) {
1179+
} elseif ( $data_object instanceof WP_Post ) {
11781180
$edit_url = add_query_arg(
11791181
array(
11801182
'classic-editor' => '',
11811183
'classic-editor__forget' => '',
11821184
),
1183-
get_edit_post_link( $object )
1185+
get_edit_post_link( $data_object )
11841186
);
11851187
echo '<p>';
11861188
/* translators: %s: A link to use the Classic Editor plugin. */
@@ -1244,17 +1246,17 @@ function _get_plugin_from_callback( $callback ) {
12441246
*
12451247
* @global array $wp_meta_boxes
12461248
*
1247-
* @param string|WP_Screen $screen The screen identifier. If you have used add_menu_page() or
1248-
* add_submenu_page() to create a new screen (and hence screen_id)
1249-
* make sure your menu slug conforms to the limits of sanitize_key()
1250-
* otherwise the 'screen' menu may not correctly render on your page.
1251-
* @param string $context The screen context for which to display meta boxes.
1252-
* @param mixed $object Gets passed to the meta box callback function as the first parameter.
1253-
* Often this is the object that's the focus of the current screen, for
1254-
* example a `WP_Post` or `WP_Comment` object.
1249+
* @param string|WP_Screen $screen The screen identifier. If you have used add_menu_page() or
1250+
* add_submenu_page() to create a new screen (and hence screen_id)
1251+
* make sure your menu slug conforms to the limits of sanitize_key()
1252+
* otherwise the 'screen' menu may not correctly render on your page.
1253+
* @param string $context The screen context for which to display meta boxes.
1254+
* @param mixed $data_object Gets passed to the meta box callback function as the first parameter.
1255+
* Often this is the object that's the focus of the current screen,
1256+
* for example a `WP_Post` or `WP_Comment` object.
12551257
* @return int Number of meta_boxes.
12561258
*/
1257-
function do_meta_boxes( $screen, $context, $object ) {
1259+
function do_meta_boxes( $screen, $context, $data_object ) {
12581260
global $wp_meta_boxes;
12591261
static $already_sorted = false;
12601262

@@ -1396,7 +1398,7 @@ function do_meta_boxes( $screen, $context, $object ) {
13961398
}
13971399
}
13981400

1399-
call_user_func( $box['callback'], $object, $box );
1401+
call_user_func( $box['callback'], $data_object, $box );
14001402
echo "</div>\n";
14011403
echo "</div>\n";
14021404
}
@@ -1473,12 +1475,12 @@ function remove_meta_box( $id, $screen, $context ) {
14731475
*
14741476
* @uses global $wp_meta_boxes Used to retrieve registered meta boxes.
14751477
*
1476-
* @param string|object $screen The screen identifier.
1477-
* @param string $context The screen context for which to display accordion sections.
1478-
* @param mixed $object Gets passed to the section callback function as the first parameter.
1478+
* @param string|object $screen The screen identifier.
1479+
* @param string $context The screen context for which to display accordion sections.
1480+
* @param mixed $data_object Gets passed to the section callback function as the first parameter.
14791481
* @return int Number of meta boxes as accordion sections.
14801482
*/
1481-
function do_accordion_sections( $screen, $context, $object ) {
1483+
function do_accordion_sections( $screen, $context, $data_object ) {
14821484
global $wp_meta_boxes;
14831485

14841486
wp_enqueue_script( 'accordion' );
@@ -1523,7 +1525,7 @@ function do_accordion_sections( $screen, $context, $object ) {
15231525
</h3>
15241526
<div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
15251527
<div class="inside">
1526-
<?php call_user_func( $box['callback'], $object, $box ); ?>
1528+
<?php call_user_func( $box['callback'], $data_object, $box ); ?>
15271529
</div><!-- .inside -->
15281530
</div><!-- .accordion-section-content -->
15291531
</li><!-- .accordion-section -->
@@ -2135,15 +2137,16 @@ function iframe_footer() {
21352137
* Echoes or returns the post states as HTML.
21362138
*
21372139
* @since 2.7.0
2138-
* @since 5.3.0 Added the `$echo` parameter and a return value.
2140+
* @since 5.3.0 Added the `$display` parameter and a return value.
21392141
*
21402142
* @see get_post_states()
21412143
*
2142-
* @param WP_Post $post The post to retrieve states for.
2143-
* @param bool $echo Optional. Whether to echo the post states as an HTML string. Default true.
2144+
* @param WP_Post $post The post to retrieve states for.
2145+
* @param bool $display Optional. Whether to display the post states as an HTML string.
2146+
* Default true.
21442147
* @return string Post states string.
21452148
*/
2146-
function _post_states( $post, $echo = true ) {
2149+
function _post_states( $post, $display = true ) {
21472150
$post_states = get_post_states( $post );
21482151
$post_states_string = '';
21492152

@@ -2163,7 +2166,7 @@ function _post_states( $post, $echo = true ) {
21632166
}
21642167
}
21652168

2166-
if ( $echo ) {
2169+
if ( $display ) {
21672170
echo $post_states_string;
21682171
}
21692172

@@ -2250,13 +2253,14 @@ function get_post_states( $post ) {
22502253
* Outputs the attachment media states as HTML.
22512254
*
22522255
* @since 3.2.0
2253-
* @since 5.6.0 Added the `$echo` parameter and a return value.
2256+
* @since 5.6.0 Added the `$display` parameter and a return value.
22542257
*
2255-
* @param WP_Post $post The attachment post to retrieve states for.
2256-
* @param bool $echo Optional. Whether to echo the post states as an HTML string. Default true.
2258+
* @param WP_Post $post The attachment post to retrieve states for.
2259+
* @param bool $display Optional. Whether to display the post states as an HTML string.
2260+
* Default true.
22572261
* @return string Media states string.
22582262
*/
2259-
function _media_states( $post, $echo = true ) {
2263+
function _media_states( $post, $display = true ) {
22602264
$media_states = get_media_states( $post );
22612265
$media_states_string = '';
22622266

@@ -2276,7 +2280,7 @@ function _media_states( $post, $echo = true ) {
22762280
}
22772281
}
22782282

2279-
if ( $echo ) {
2283+
if ( $display ) {
22802284
echo $media_states_string;
22812285
}
22822286

0 commit comments

Comments
 (0)