wp_update_link

Updates a link in the database.

Description

(int|WP_Error) wp_update_link( (array) $linkdata ); 

Returns (int|WP_Error)

Value 0 or WP_Error on failure. The updated link ID on success.

Parameters (1)

0. $linkdata (array)
Link data to update.

Usage

  1. if ( !function_exists( 'wp_update_link' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/bookmark.php'; 
  3.  
  4. // Link data to update. 
  5. $linkdata = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_update_link($linkdata); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/bookmark.php  
  1. function wp_update_link( $linkdata ) { 
  2. $link_id = (int) $linkdata['link_id']; 
  3.  
  4. $link = get_bookmark( $link_id, ARRAY_A ); 
  5.  
  6. // Escape data pulled from DB. 
  7. $link = wp_slash( $link ); 
  8.  
  9. // Passed link category list overwrites existing category list if not empty. 
  10. if ( isset( $linkdata['link_category'] ) && is_array( $linkdata['link_category'] ) 
  11. && 0 != count( $linkdata['link_category'] ) ) 
  12. $link_cats = $linkdata['link_category']; 
  13. else 
  14. $link_cats = $link['link_category']; 
  15.  
  16. // Merge old and new fields with new fields overwriting old ones. 
  17. $linkdata = array_merge( $link, $linkdata ); 
  18. $linkdata['link_category'] = $link_cats; 
  19.  
  20. return wp_insert_link( $linkdata );