wp_create_category

The timeline below displays how wordpress function wp_create_category has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

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));
}

WordPress Version: 5.3

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

WordPress Version: 4.2

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

WordPress Version: 4.1

/**
 * {@internal Missing Short Description}}
 *
 * @since 2.0.0
 *
 * @param int|string $cat_name
 * @param int        $parent
 * @return int|WP_Error
 */
function wp_create_category($cat_name, $parent = 0)
{
    if ($id = category_exists($cat_name, $parent)) {
        return $id;
    }
    return wp_insert_category(array('cat_name' => $cat_name, 'category_parent' => $parent));
}

WordPress Version: 3.7

/**
 * {@internal Missing Short Description}}
 *
 * @since 2.0.0
 *
 * @param unknown_type $cat_name
 * @param unknown_type $parent
 * @return unknown
 */
function wp_create_category($cat_name, $parent = 0)
{
    if ($id = category_exists($cat_name, $parent)) {
        return $id;
    }
    return wp_insert_category(array('cat_name' => $cat_name, 'category_parent' => $parent));
}