edit_link

Updates or inserts a link using values provided in $_POST.

Description

(int|WP_Error) edit_link( (int) $link_id = 0 ); 

Returns (int|WP_Error)

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

Parameters (1)

0. $link_id — Optional. (int)
ID of the link to edit. Default 0.

Usage

  1. if ( !function_exists( 'edit_link' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/bookmark.php'; 
  3.  
  4. // Optional. ID of the link to edit. Default 0. 
  5. $link_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = edit_link($link_id); 
  9.  

Defined (1)

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

/wp-admin/includes/bookmark.php  
  1. function edit_link( $link_id = 0 ) { 
  2. if ( ! current_user_can( 'manage_links' ) ) { 
  3. wp_die
  4. '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . 
  5. '<p>' . __( 'Sorry, you are not allowed to edit the links for this site.' ) . '</p>',  
  6. 403 
  7. ); 
  8.  
  9. $_POST['link_url'] = esc_html( $_POST['link_url'] ); 
  10. $_POST['link_url'] = esc_url($_POST['link_url']); 
  11. $_POST['link_name'] = esc_html( $_POST['link_name'] ); 
  12. $_POST['link_image'] = esc_html( $_POST['link_image'] ); 
  13. $_POST['link_rss'] = esc_url($_POST['link_rss']); 
  14. if ( !isset($_POST['link_visible']) || 'N' != $_POST['link_visible'] ) 
  15. $_POST['link_visible'] = 'Y'; 
  16.  
  17. if ( !empty( $link_id ) ) { 
  18. $_POST['link_id'] = $link_id; 
  19. return wp_update_link( $_POST ); 
  20. } else { 
  21. return wp_insert_link( $_POST );