Make WordPress Core


Ignore:
Timestamp:
04/19/2022 01:49:19 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/taxonomy.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 $parent parameter to $category_parent in category_exists() and wp_create_category(). This matches the category object property of the same name.
  • Amends similar parameters in dropdown_categories() and wp_dropdown_cats() for consistency.

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215].

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

File:
1 edited

Legend:

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

    r52236 r53216  
    1818 * @see term_exists()
    1919 *
    20  * @param int|string $cat_name Category name.
    21  * @param int        $parent   Optional. ID of parent term.
     20 * @param int|string $cat_name        Category name.
     21 * @param int        $category_parent Optional. ID of parent category.
    2222 * @return string|null Returns the category ID as a numeric string if the pairing exists, null if not.
    2323 */
    24 function category_exists( $cat_name, $parent = null ) {
    25     $id = term_exists( $cat_name, 'category', $parent );
     24function category_exists( $cat_name, $category_parent = null ) {
     25    $id = term_exists( $cat_name, 'category', $category_parent );
    2626    if ( is_array( $id ) ) {
    2727        $id = $id['term_id'];
     
    4949 * @since 2.0.0
    5050 *
    51  * @param int|string $cat_name
    52  * @param int        $parent
     51 * @param int|string $cat_name        Category name.
     52 * @param int        $category_parent Optional. ID of parent category.
    5353 * @return int|WP_Error
    5454 */
    55 function wp_create_category( $cat_name, $parent = 0 ) {
    56     $id = category_exists( $cat_name, $parent );
     55function wp_create_category( $cat_name, $category_parent = 0 ) {
     56    $id = category_exists( $cat_name, $category_parent );
    5757    if ( $id ) {
    5858        return $id;
     
    6262        array(
    6363            'cat_name'        => $cat_name,
    64             'category_parent' => $parent,
     64            'category_parent' => $category_parent,
    6565        )
    6666    );
Note: See TracChangeset for help on using the changeset viewer.