get_bookmark( int|stdClass $bookmark, string $output = OBJECT, string $filter = 'raw' ): array|object|null
- Since
- 2.1.0
- Source
wp-includes/bookmark.php:24
Compatibility
- WordPress
- since 2.1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$bookmarkint|stdClass$outputstringoptional- 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.Default:
OBJECT $filterstringoptional- How to sanitize bookmark fields. Default 'raw'.Default:
'raw'
Return value
array|object|null- Type returned depends on $output value.
Performance profile
How much work a call to get_bookmark() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 12–74
- Plugin surface
- None
- Called by
- 7
Reaches the database via ->get_row().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 100.
Nothing here hands control to plugin code.
7 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- cacheobject cache
wp_cache_add()called directly - querycontent query
wp_get_object_terms()called directly - sqldatabase query
->get_row()called directly - hookthird-party callbacks
apply_filters()one call below get_bookmark()
Further down the call graph this can also reach option, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 16 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_bookmark() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 12–19 | none |
!empty($bookmark) && is_object($bookmark) | 19 | wp_cache_add() |
| always | 20–33 | sanitize_bookmark() |
!empty($bookmark) && !is_object($bookmark) | 25–35 | wp_cache_get(), sanitize_bookmark() |
| always | 26–33 | sanitize_bookmark(), get_object_vars() |
!empty($bookmark) && is_object($bookmark) | 27–33 | wp_cache_add(), sanitize_bookmark() |
!empty($bookmark) && !is_object($bookmark) | 30–34 | wp_cache_get(), ->prepare(), ->get_row() |
!empty($bookmark) && !is_object($bookmark) | 31–35 | wp_cache_get(), sanitize_bookmark(), get_object_vars() |
| always | 32–39 | sanitize_bookmark(), get_object_vars(), array_values() |
!empty($bookmark) && is_object($bookmark) | 33 | wp_cache_add(), sanitize_bookmark(), get_object_vars() |
!empty($bookmark) && !is_object($bookmark) | 37–41 | wp_cache_get(), sanitize_bookmark(), get_object_vars(), array_values() |
!empty($bookmark) && is_object($bookmark) | 39 | wp_cache_add(), sanitize_bookmark(), get_object_vars(), array_values() |
4 further outcomes, up to 74 instructions
!empty($bookmark) && !is_object($bookmark) | 50–54 | wp_cache_get(), ->prepare(), ->get_row(), wp_get_object_terms(), array_unique(), wp_cache_add() |
!empty($bookmark) && !is_object($bookmark) | 58–68 | wp_cache_get(), ->prepare(), ->get_row(), wp_get_object_terms(), array_unique(), wp_cache_add(), sanitize_bookmark() |
!empty($bookmark) && !is_object($bookmark) | 64–68 | wp_cache_get(), ->prepare(), ->get_row(), wp_get_object_terms(), array_unique(), wp_cache_add(), sanitize_bookmark(), get_object_vars() |
!empty($bookmark) && !is_object($bookmark) | 70–74 | wp_cache_get(), ->prepare(), ->get_row(), wp_get_object_terms(), array_unique(), wp_cache_add(), sanitize_bookmark(), get_object_vars(), array_values() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 100 | 12–74 | 11 | |
| 8.5 | 100 | 12–74 | 11 | |
| 8.4 | 100 | 12–74 | 11 | |
| 8.3 | 100 | 12–74 | 11 | |
| 8.2 | 100 | 12–74 | 11 | |
| 8.1 | 100 | 12–74 | 11 | 5 fewer instructions than PHP 7.4 |
| 7.4 | 105 | 13–76 | 11 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 4
- wp_cache_add()Adds data to the cache, if the cache key doesn't already exist.
- wp_cache_get()Retrieves the cache contents from the cache by key and group.
- wp_get_object_terms()Retrieves the terms associated with the given object(s), in the supplied taxonomies.
- sanitize_bookmark()Sanitizes all bookmark fields.
Used by · 7
- edit_bookmark_link()Displays the edit bookmark link anchor content.
- get_bookmark_field()Retrieves single bookmark data item or field.
- get_edit_bookmark_link()Displays the edit bookmark link.
- get_link()Retrieves bookmark data based on ID.
- get_link_to_edit()Retrieves link data based on its ID.
- wp_ajax_delete_link()Handles deleting a link via AJAX.
- wp_update_link()Updates a link in the database.
Source code
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']; } else { $_bookmark = wp_cache_get( $bookmark, 'bookmark' ); if ( ! $_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 ( OBJECT === $output ) { return $_bookmark; } elseif ( ARRAY_A === $output ) { return get_object_vars( $_bookmark ); } elseif ( ARRAY_N === $output ) { return array_values( get_object_vars( $_bookmark ) ); } else { return $_bookmark; }}Changelog
Introduced in 2.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-includes/bookmark.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.