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.

Built from https://develop.svn.wordpress.org/trunk@61298


git-svn-id: http://core.svn.wordpress.org/trunk@60610 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter
2025-11-25 01:34:30 +00:00
parent 879ba497c2
commit ec15921c78
2 changed files with 8 additions and 8 deletions

View File

@@ -48,19 +48,19 @@ function get_category_to_edit( $id ) {
*
* @since 2.0.0
*
* @param int|string $cat_name Category name.
* @param int $category_parent Optional. ID of parent category.
* @return int|WP_Error
* @param string $category_name Category name.
* @param int $category_parent Optional. ID of parent category.
* @return int The ID of category term on success, or zero on failure.
*/
function wp_create_category( $cat_name, $category_parent = 0 ) {
$id = category_exists( $cat_name, $category_parent );
function wp_create_category( $category_name, $category_parent = 0 ) {
$id = category_exists( $category_name, $category_parent );
if ( $id ) {
return $id;
return (int) $id;
}
return wp_insert_category(
array(
'cat_name' => $cat_name,
'cat_name' => $category_name,
'category_parent' => $category_parent,
)
);

View File

@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '7.0-alpha-61295';
$wp_version = '7.0-alpha-61298';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.