wp_update_category

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

WordPress Version: 6.3

/**
 * Aliases wp_insert_category() with minimal args.
 *
 * If you want to update only some fields of an existing category, call this
 * function with only the new values set inside $catarr.
 *
 * @since 2.0.0
 *
 * @param array $catarr The 'cat_ID' value is required. All other keys are optional.
 * @return int|false The ID number of the new or updated Category on success. Zero or FALSE on failure.
 */
function wp_update_category($catarr)
{
    $cat_id = (int) $catarr['cat_ID'];
    if (isset($catarr['category_parent']) && $cat_id === (int) $catarr['category_parent']) {
        return false;
    }
    // First, get all of the original fields.
    $category = get_term($cat_id, 'category', ARRAY_A);
    _make_cat_compat($category);
    // Escape data pulled from DB.
    $category = wp_slash($category);
    // Merge old and new fields with new fields overwriting old ones.
    $catarr = array_merge($category, $catarr);
    return wp_insert_category($catarr);
}

WordPress Version: 6.2

/**
 * Aliases wp_insert_category() with minimal args.
 *
 * If you want to update only some fields of an existing category, call this
 * function with only the new values set inside $catarr.
 *
 * @since 2.0.0
 *
 * @param array $catarr The 'cat_ID' value is required. All other keys are optional.
 * @return int|false The ID number of the new or updated Category on success. Zero or FALSE on failure.
 */
function wp_update_category($catarr)
{
    $cat_id = (int) $catarr['cat_ID'];
    if (isset($catarr['category_parent']) && $cat_id == $catarr['category_parent']) {
        return false;
    }
    // First, get all of the original fields.
    $category = get_term($cat_id, 'category', ARRAY_A);
    _make_cat_compat($category);
    // Escape data pulled from DB.
    $category = wp_slash($category);
    // Merge old and new fields with new fields overwriting old ones.
    $catarr = array_merge($category, $catarr);
    return wp_insert_category($catarr);
}

WordPress Version: 5.7

/**
 * Aliases wp_insert_category() with minimal args.
 *
 * If you want to update only some fields of an existing category, call this
 * function with only the new values set inside $catarr.
 *
 * @since 2.0.0
 *
 * @param array $catarr The 'cat_ID' value is required. All other keys are optional.
 * @return int|false The ID number of the new or updated Category on success. Zero or FALSE on failure.
 */
function wp_update_category($catarr)
{
    $cat_ID = (int) $catarr['cat_ID'];
    if (isset($catarr['category_parent']) && $cat_ID == $catarr['category_parent']) {
        return false;
    }
    // First, get all of the original fields.
    $category = get_term($cat_ID, 'category', ARRAY_A);
    _make_cat_compat($category);
    // Escape data pulled from DB.
    $category = wp_slash($category);
    // Merge old and new fields with new fields overwriting old ones.
    $catarr = array_merge($category, $catarr);
    return wp_insert_category($catarr);
}

WordPress Version: 5.4

/**
 * Aliases wp_insert_category() with minimal args.
 *
 * If you want to update only some fields of an existing category, call this
 * function with only the new values set inside $catarr.
 *
 * @since 2.0.0
 *
 * @param array $catarr The 'cat_ID' value is required. All other keys are optional.
 * @return int|bool The ID number of the new or updated Category on success. Zero or FALSE on failure.
 */
function wp_update_category($catarr)
{
    $cat_ID = (int) $catarr['cat_ID'];
    if (isset($catarr['category_parent']) && $cat_ID == $catarr['category_parent']) {
        return false;
    }
    // First, get all of the original fields.
    $category = get_term($cat_ID, 'category', ARRAY_A);
    _make_cat_compat($category);
    // Escape data pulled from DB.
    $category = wp_slash($category);
    // Merge old and new fields with new fields overwriting old ones.
    $catarr = array_merge($category, $catarr);
    return wp_insert_category($catarr);
}

WordPress Version: 3.7

/**
 * Aliases wp_insert_category() with minimal args.
 *
 * If you want to update only some fields of an existing category, call this
 * function with only the new values set inside $catarr.
 *
 * @since 2.0.0
 *
 * @param array $catarr The 'cat_ID' value is required. All other keys are optional.
 * @return int|bool The ID number of the new or updated Category on success. Zero or FALSE on failure.
 */
function wp_update_category($catarr)
{
    $cat_ID = (int) $catarr['cat_ID'];
    if (isset($catarr['category_parent']) && $cat_ID == $catarr['category_parent']) {
        return false;
    }
    // First, get all of the original fields
    $category = get_term($cat_ID, 'category', ARRAY_A);
    _make_cat_compat($category);
    // Escape data pulled from DB.
    $category = wp_slash($category);
    // Merge old and new fields with new fields overwriting old ones.
    $catarr = array_merge($category, $catarr);
    return wp_insert_category($catarr);
}