- $link = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->links WHERE link_id = %d LIMIT 1", $bookmark_id));
- $link->link_category = array_unique( wp_get_object_terms($link->link_id, 'link_category', 'fields=ids') );
+ if ( empty($bookmark) ) {
+ if ( isset($GLOBALS['link']) )
+ $_bookmark = & $GLOBALS['link'];
+ else
+ $_bookmark = null;
+ } elseif ( is_object($bookmark) ) {
+ wp_cache_add($bookmark->link_id, $bookmark, 'bookmark');
+ $_bookmark = $bookmark;
+ } else {
+ if ( isset($GLOBALS['link']) && ($GLOBALS['link']->link_id == $bookmark) ) {
+ $_bookmark = & $GLOBALS['link'];
+ } elseif ( ! $_bookmark = wp_cache_get($bookmark, 'bookmark') ) {
+ $_bookmark = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->links WHERE link_id = %d LIMIT 1", $bookmark));
+ $_bookmark->link_category = array_unique( wp_get_object_terms($_bookmark->link_id, 'link_category', array('fields' => 'ids')) );
+ wp_cache_add($_bookmark->link_id, $_bookmark, 'bookmark');
+ }
+ }