get_bookmark( int|stdClass $bookmark, string $output = OBJECT, string $filter = 'raw' )

Retrieve Bookmark data


Description Description


Parameters Parameters

$bookmark

(int|stdClass) (Required)

$output

(string) (Optional) 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 value: OBJECT

$filter

(string) (Optional)

Default value: 'raw'


Top ↑

Return Return

(array|object|null) Type returned depends on $output value.


Top ↑

Source Source

File: wp-includes/bookmark.php

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function get_bookmark( $bookmark, $output = OBJECT, $filter = 'raw' ) {
    global $wpdb;
 
    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 ) );
            if ( $_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' );
            }
        }
    }
 
    if ( ! $_bookmark ) {
        return $_bookmark;
    }
 
    $_bookmark = sanitize_bookmark( $_bookmark, $filter );
 
    if ( $output == OBJECT ) {
        return $_bookmark;
    } elseif ( $output == ARRAY_A ) {
        return get_object_vars( $_bookmark );
    } elseif ( $output == ARRAY_N ) {
        return array_values( get_object_vars( $_bookmark ) );
    } else {
        return $_bookmark;
    }
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.1.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.