WordPress Version: 6.1
/**
* Adds a new category to the database if it does not already exist.
*
* @since 2.0.0
*
* @param int|string $cat_name Category name.
* @param int $category_parent Optional. ID of parent category.
* @return int|WP_Error
*/
function wp_create_category($cat_name, $category_parent = 0)
{
$id = category_exists($cat_name, $category_parent);
if ($id) {
return $id;
}
return wp_insert_category(array('cat_name' => $cat_name, 'category_parent' => $category_parent));
}