On this page
wp_update_link( array $linkdata ): int|WP_Error
Updates a link in the database.
Parameters
$linkdataarray Required-
Link data to update. See wp_insert_link() for accepted arguments.
More Arguments from wp_insert_link( ... $linkdata )
Elements that make up the link to insert.
link_idintOptional. The ID of the existing link if updating.link_urlstringThe URL the link points to.link_namestringThe title of the link.link_imagestringOptional. A URL of an image.link_targetstringOptional. The target element for the anchor tag.link_descriptionstringOptional. A short description of the link.link_visiblestringOptional.'Y'means visible, anything else means not.link_ownerintOptional. A user ID.link_ratingintOptional. A rating for the link.link_relstringOptional. A relationship of the link to you.link_notesstringOptional. An extended description of or notes on the link.link_rssstringOptional. A URL of an associated RSS feed.link_categoryintOptional. The term ID of the link category.
If empty, uses default link category.
Return
int|WP_Error Value 0 or WP_Error on failure. The updated link ID on success.
Source
File: wp-admin/includes/bookmark.php. View all references
function wp_update_link( $linkdata ) {
$link_id = (int) $linkdata['link_id'];
$link = get_bookmark( $link_id, ARRAY_A );
// Escape data pulled from DB.
$link = wp_slash( $link );
// Passed link category list overwrites existing category list if not empty.
if ( isset( $linkdata['link_category'] ) && is_array( $linkdata['link_category'] )
&& count( $linkdata['link_category'] ) > 0
) {
$link_cats = $linkdata['link_category'];
} else {
$link_cats = $link['link_category'];
}
// Merge old and new fields with new fields overwriting old ones.
$linkdata = array_merge( $link, $linkdata );
$linkdata['link_category'] = $link_cats;
return wp_insert_link( $linkdata );
}
Related
Uses
| Uses | Description |
|---|---|
| wp_insert_link() wp-admin/includes/bookmark.php | Inserts a link into the database, or updates an existing link. |
| get_bookmark() wp-includes/bookmark.php | Retrieves bookmark data. |
| wp_slash() wp-includes/formatting.php | Adds slashes to a string or recursively adds slashes to strings within an array. |
Used By
| Used By | Description |
|---|---|
| edit_link() wp-admin/includes/bookmark.php | Updates or inserts a link using values provided in $_POST. |
Changelog
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_update_link