wp_set_link_cats

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

WordPress Version: 6.3

/**
 * Updates link with the specified link categories.
 *
 * @since 2.1.0
 *
 * @param int   $link_id         ID of the link to update.
 * @param int[] $link_categories Array of link category IDs to add the link to.
 */
function wp_set_link_cats($link_id = 0, $link_categories = array())
{
    // If $link_categories isn't already an array, make it one:
    if (!is_array($link_categories) || 0 === count($link_categories)) {
        $link_categories = array(get_option('default_link_category'));
    }
    $link_categories = array_map('intval', $link_categories);
    $link_categories = array_unique($link_categories);
    wp_set_object_terms($link_id, $link_categories, 'link_category');
    clean_bookmark_cache($link_id);
}

WordPress Version: 5.5

/**
 * Update link with the specified link categories.
 *
 * @since 2.1.0
 *
 * @param int   $link_id         ID of the link to update.
 * @param int[] $link_categories Array of link category IDs to add the link to.
 */
function wp_set_link_cats($link_id = 0, $link_categories = array())
{
    // If $link_categories isn't already an array, make it one:
    if (!is_array($link_categories) || 0 === count($link_categories)) {
        $link_categories = array(get_option('default_link_category'));
    }
    $link_categories = array_map('intval', $link_categories);
    $link_categories = array_unique($link_categories);
    wp_set_object_terms($link_id, $link_categories, 'link_category');
    clean_bookmark_cache($link_id);
}

WordPress Version: 5.1

/**
 * Update link with the specified link categories.
 *
 * @since 2.1.0
 *
 * @param int   $link_id         ID of the link to update.
 * @param int[] $link_categories Array of link category IDs to add the link to.
 */
function wp_set_link_cats($link_id = 0, $link_categories = array())
{
    // If $link_categories isn't already an array, make it one:
    if (!is_array($link_categories) || 0 == count($link_categories)) {
        $link_categories = array(get_option('default_link_category'));
    }
    $link_categories = array_map('intval', $link_categories);
    $link_categories = array_unique($link_categories);
    wp_set_object_terms($link_id, $link_categories, 'link_category');
    clean_bookmark_cache($link_id);
}

WordPress Version: 4.4

/**
 * Update link with the specified link categories.
 *
 * @since 2.1.0
 *
 * @param int   $link_id         ID of the link to update.
 * @param array $link_categories Array of link categories to add the link to.
 */
function wp_set_link_cats($link_id = 0, $link_categories = array())
{
    // If $link_categories isn't already an array, make it one:
    if (!is_array($link_categories) || 0 == count($link_categories)) {
        $link_categories = array(get_option('default_link_category'));
    }
    $link_categories = array_map('intval', $link_categories);
    $link_categories = array_unique($link_categories);
    wp_set_object_terms($link_id, $link_categories, 'link_category');
    clean_bookmark_cache($link_id);
}

WordPress Version: 3.7

/**
 * Update link with the specified link categories.
 *
 * @since 2.1.0
 *
 * @param int $link_id ID of link to update
 * @param array $link_categories Array of categories to
 */
function wp_set_link_cats($link_id = 0, $link_categories = array())
{
    // If $link_categories isn't already an array, make it one:
    if (!is_array($link_categories) || 0 == count($link_categories)) {
        $link_categories = array(get_option('default_link_category'));
    }
    $link_categories = array_map('intval', $link_categories);
    $link_categories = array_unique($link_categories);
    wp_set_object_terms($link_id, $link_categories, 'link_category');
    clean_bookmark_cache($link_id);
}