Make WordPress Core

Changeset 53245


Ignore:
Timestamp:
04/23/2022 08:57:06 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/class-wp-customize-nav-menus.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 $type and $object parameters to $object_type and $object_name in WP_Customize_Nav_Menus::load_available_items_query().

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243].

Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-nav-menus.php

    r53055 r53245  
    132132     * @since 4.3.0
    133133     *
    134      * @param string $type  Optional. Accepts any custom object type and has built-in support for
    135      *                         'post_type' and 'taxonomy'. Default is 'post_type'.
    136      * @param string $object Optional. Accepts any registered taxonomy or post type name. Default is 'page'.
    137      * @param int    $page   Optional. The page number used to generate the query offset. Default is '0'.
     134     * @param string $object_type Optional. Accepts any custom object type and has built-in support for
     135     *                            'post_type' and 'taxonomy'. Default is 'post_type'.
     136     * @param string $object_name Optional. Accepts any registered taxonomy or post type name. Default is 'page'.
     137     * @param int    $page        Optional. The page number used to generate the query offset. Default is '0'.
    138138     * @return array|WP_Error An array of menu items on success, a WP_Error object on failure.
    139139     */
    140     public function load_available_items_query( $type = 'post_type', $object = 'page', $page = 0 ) {
     140    public function load_available_items_query( $object_type = 'post_type', $object_name = 'page', $page = 0 ) {
    141141        $items = array();
    142142
    143         if ( 'post_type' === $type ) {
    144             $post_type = get_post_type_object( $object );
     143        if ( 'post_type' === $object_type ) {
     144            $post_type = get_post_type_object( $object_name );
    145145            if ( ! $post_type ) {
    146146                return new WP_Error( 'nav_menus_invalid_post_type' );
     
    153153            $important_pages   = array();
    154154            $suppress_page_ids = array();
    155             if ( 0 === $page && 'page' === $object ) {
     155            if ( 0 === $page && 'page' === $object_name ) {
    156156                // Insert Front Page or custom "Home" link.
    157157                $front_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0;
     
    189189                    }
    190190                }
    191             } elseif ( 'post' !== $object && 0 === $page && $post_type->has_archive ) {
     191            } elseif ( 'post' !== $object_name && 0 === $page && $post_type->has_archive ) {
    192192                // Add a post type archive link.
    193193                $items[] = array(
    194                     'id'         => $object . '-archive',
     194                    'id'         => $object_name . '-archive',
    195195                    'title'      => $post_type->labels->archives,
    196196                    'type'       => 'post_type_archive',
    197197                    'type_label' => __( 'Post Type Archive' ),
    198                     'object'     => $object,
    199                     'url'        => get_post_type_archive_link( $object ),
     198                    'object'     => $object_name,
     199                    'url'        => get_post_type_archive_link( $object_name ),
    200200                );
    201201            }
     
    217217                'orderby'     => 'date',
    218218                'order'       => 'DESC',
    219                 'post_type'   => $object,
     219                'post_type'   => $object_name,
    220220            );
    221221
     
    254254                );
    255255            }
    256         } elseif ( 'taxonomy' === $type ) {
     256        } elseif ( 'taxonomy' === $object_type ) {
    257257            $terms = get_terms(
    258258                array(
    259                     'taxonomy'     => $object,
     259                    'taxonomy'     => $object_name,
    260260                    'child_of'     => 0,
    261261                    'exclude'      => '',
     
    293293         * @since 4.3.0
    294294         *
    295          * @param array  $items  The array of menu items.
    296          * @param string $type  The object type.
    297          * @param string $object The object name.
     295         * @param array  $items       The array of menu items.
     296         * @param string $object_type The object type.
     297         * @param string $object_name The object name.
    298298         * @param int    $page   The current page number.
    299299         */
    300         $items = apply_filters( 'customize_nav_menu_available_items', $items, $type, $object, $page );
     300        $items = apply_filters( 'customize_nav_menu_available_items', $items, $object_type, $object_name, $page );
    301301
    302302        return $items;
Note: See TracChangeset for help on using the changeset viewer.