get_bookmark

Retrieve Bookmark data.

Description

(array|object|null) get_bookmark( (int|stdClass) $bookmark, (constant) $output = OBJECT, (string) $filter = 'raw' ); 

Returns (array|object|null)

Type returned depends on $output value.

Parameters (3)

0. $bookmark (int|stdClass)
The bookmark.
1. $output — Optional. (constant) => OBJECT
The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to an stdClass object, an associative array, or a numeric array, respectively. Default OBJECT.
2. $filter — Optional. (string) => 'raw'
Optional, default is raw..

Usage

  1. if ( !function_exists( 'get_bookmark' ) ) { 
  2. require_once ABSPATH . WPINC . '/bookmark.php'; 
  3.  
  4. // The bookmark. 
  5. $bookmark = null; 
  6.  
  7. // Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to 
  8. // an stdClass object, an associative array, or a numeric array, respectively. Default OBJECT. 
  9. $output = OBJECT; 
  10.  
  11. // Optional, default is 'raw'. 
  12. $filter = 'raw'; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = get_bookmark($bookmark, $output, $filter); 
  16.  

Defined (1)

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

/wp-includes/bookmark.php  
  1. function get_bookmark($bookmark, $output = OBJECT, $filter = 'raw') { 
  2. global $wpdb; 
  3.  
  4. if ( empty($bookmark) ) { 
  5. if ( isset($GLOBALS['link']) ) 
  6. $_bookmark = & $GLOBALS['link']; 
  7. else 
  8. $_bookmark = null; 
  9. } elseif ( is_object($bookmark) ) { 
  10. wp_cache_add($bookmark->link_id, $bookmark, 'bookmark'); 
  11. $_bookmark = $bookmark; 
  12. } else { 
  13. if ( isset($GLOBALS['link']) && ($GLOBALS['link']->link_id == $bookmark) ) { 
  14. $_bookmark = & $GLOBALS['link']; 
  15. } elseif ( ! $_bookmark = wp_cache_get($bookmark, 'bookmark') ) { 
  16. $_bookmark = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->links WHERE link_id = %d LIMIT 1", $bookmark)); 
  17. if ( $_bookmark ) { 
  18. $_bookmark->link_category = array_unique( wp_get_object_terms( $_bookmark->link_id, 'link_category', array( 'fields' => 'ids' ) ) ); 
  19. wp_cache_add( $_bookmark->link_id, $_bookmark, 'bookmark' ); 
  20.  
  21. if ( ! $_bookmark ) 
  22. return $_bookmark; 
  23.  
  24. $_bookmark = sanitize_bookmark($_bookmark, $filter); 
  25.  
  26. if ( $output == OBJECT ) { 
  27. return $_bookmark; 
  28. } elseif ( $output == ARRAY_A ) { 
  29. return get_object_vars($_bookmark); 
  30. } elseif ( $output == ARRAY_N ) { 
  31. return array_values(get_object_vars($_bookmark)); 
  32. } else { 
  33. return $_bookmark;