Make WordPress Core

Changeset 61298


Ignore:
Timestamp:
11/25/2025 01:32:39 AM (8 weeks ago)
Author:
westonruter
Message:

Docs: Update typing for wp_create_category().

  • Ensure that wp_create_category() returns int as opposed to numeric-string.
  • Rename $cat_name to $category_name to avoid abbreviating variables.
  • Update docblock to remove erroneous int for $category_name param when only string is intended.
  • Add missing tests for wp_create_category().

Developed in https://github.com/WordPress/wordpress-develop/pull/8861

Props justlevine, westonruter.
See #64238, #64226.

Location:
trunk
Files:
1 added
1 edited

Legend:

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

    r60275 r61298  
    4949 * @since 2.0.0
    5050 *
    51  * @param int|string $cat_name        Category name.
    52  * @param int        $category_parent Optional. ID of parent category.
    53  * @return int|WP_Error
    54  */
    55 function wp_create_category( $cat_name, $category_parent = 0 ) {
    56     $id = category_exists( $cat_name, $category_parent );
     51 * @param string $category_name   Category name.
     52 * @param int    $category_parent Optional. ID of parent category.
     53 * @return int The ID of category term on success, or zero on failure.
     54 */
     55function wp_create_category( $category_name, $category_parent = 0 ) {
     56    $id = category_exists( $category_name, $category_parent );
    5757    if ( $id ) {
    58         return $id;
     58        return (int) $id;
    5959    }
    6060
    6161    return wp_insert_category(
    6262        array(
    63             'cat_name'        => $cat_name,
     63            'cat_name'        => $category_name,
    6464            'category_parent' => $category_parent,
    6565        )
Note: See TracChangeset for help on using the changeset viewer.