Make WordPress Core

Changeset 53220


Ignore:
Timestamp:
04/19/2022 03:11:22 PM (3 years ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk/src/wp-admin/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/nav-menu.php

    r53207 r53220  
    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.
     
    336336 * }
    337337 */
    338 function wp_nav_menu_item_post_type_meta_box( $item_object, $box ) {
     338function wp_nav_menu_item_post_type_meta_box( $data_object, $box ) {
    339339    global $_nav_menu_placeholder, $nav_menu_selected_id;
    340340
     
    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.
     
    700700 * }
    701701 */
    702 function wp_nav_menu_item_taxonomy_meta_box( $item_object, $box ) {
     702function wp_nav_menu_item_taxonomy_meta_box( $data_object, $box ) {
    703703    global $nav_menu_selected_id;
    704704
     
    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 */
    995995function _wp_nav_menu_meta_box_object( $item_object = null ) {
    996     if ( isset( $item_object->name ) ) {
    997 
    998         if ( 'page' === $item_object->name ) {
    999             $item_object->_default_query = array(
     996    if ( isset( $data_object->name ) ) {
     997
     998        if ( 'page' === $data_object->name ) {
     999            $data_object->_default_query = array(
    10001000                'orderby'     => 'menu_order title',
    10011001                'post_status' => 'publish',
     
    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',
     
    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            );
     
    10231023    }
    10241024
    1025     return $item_object;
     1025    return $data_object;
    10261026}
    10271027
  • trunk/src/wp-admin/includes/template.php

    r52999 r53220  
    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 ) {
     209function wp_popular_terms_checklist( $taxonomy, $default_term = 0, $number = 10, $display = true ) {
    210210    $post = get_post();
    211211
     
    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"' : '';
     
    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  */
    880 function page_template_dropdown( $default = '', $post_type = 'page' ) {
     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'.
     881 */
     882function page_template_dropdown( $default_template = '', $post_type = 'page' ) {
    881883    $templates = get_page_templates( null, $post_type );
    882884
     
    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    }
     
    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 ) {
     907function parent_dropdown( $default_page = 0, $parent = 0, $level = 0, $post = null ) {
    906908    global $wpdb;
    907909
     
    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 {
     
    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 *
     
    11391141 * }
    11401142 */
    1141 function do_block_editor_incompatible_meta_box( $object, $box ) {
     1143function do_block_editor_incompatible_meta_box( $data_object, $box ) {
    11421144    $plugin  = _get_plugin_from_callback( $box['old_callback'] );
    11431145    $plugins = get_plugins();
     
    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(
     
    11811183                'classic-editor__forget' => '',
    11821184            ),
    1183             get_edit_post_link( $object )
     1185            get_edit_post_link( $data_object )
    11841186        );
    11851187        echo '<p>';
     
    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 ) {
     1259function do_meta_boxes( $screen, $context, $data_object ) {
    12581260    global $wp_meta_boxes;
    12591261    static $already_sorted = false;
     
    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";
     
    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 ) {
     1483function do_accordion_sections( $screen, $context, $data_object ) {
    14821484    global $wp_meta_boxes;
    14831485
     
    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 -->
     
    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 ) {
     2149function _post_states( $post, $display = true ) {
    21472150    $post_states        = get_post_states( $post );
    21482151    $post_states_string = '';
     
    21642167    }
    21652168
    2166     if ( $echo ) {
     2169    if ( $display ) {
    21672170        echo $post_states_string;
    21682171    }
     
    22512254 *
    22522255 * @since 3.2.0
    2253  * @since 5.6.0 Added the `$echo` parameter and a return value.
    2254  *
    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.
     2256 * @since 5.6.0 Added the `$display` parameter and a return value.
     2257 *
     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 ) {
     2263function _media_states( $post, $display = true ) {
    22602264    $media_states        = get_media_states( $post );
    22612265    $media_states_string = '';
     
    22772281    }
    22782282
    2279     if ( $echo ) {
     2283    if ( $display ) {
    22802284        echo $media_states_string;
    22812285    }
Note: See TracChangeset for help on using the changeset viewer.