wp_check_post_lock( int|WP_Post $post ): int|false
- Since
- 2.5.0
- Source
wp-admin/includes/post.php:1701
Compatibility
- WordPress
- since 2.5.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
$postint|WP_Post- ID or object of the post to check for editing.
Return value
int|false- ID of the user with lock. False if the post does not exist, post is not locked, the user with lock does not exist, or the post is locked by current user.
Performance profile
How much work a call to wp_check_post_lock() 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
- 7–52
- Plugin surface
- 1 hook
- Called by
- 15
Reaches the database via get_post().
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 59.
Third-party callbacks on 'wp_check_post_lock_window' run inside this call, and their cost is not bounded by anything here.
15 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach cache, serialize, option 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 · 10 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_check_post_lock() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 7 | get_post() |
| always | 16 | get_post(), get_post_meta() |
isset($lock) && !get_userdata() | 32 | get_post(), get_post_meta(), explode(), get_userdata() |
!isset($lock) && !get_userdata() | 37 | get_post(), get_post_meta(), explode(), get_post_meta(), get_userdata() |
isset($lock) && get_userdata() && !$lock | 38 | get_post(), get_post_meta(), explode(), get_userdata(), apply_filters() |
!isset($lock) && get_userdata() && !$lock | 43 | get_post(), get_post_meta(), explode(), get_post_meta(), get_userdata(), apply_filters() |
isset($lock) && get_userdata() && $lock && !$time | 43 | get_post(), get_post_meta(), explode(), get_userdata(), apply_filters(), time() |
isset($lock) && get_userdata() && $lock && $time | 47 | get_post(), get_post_meta(), explode(), get_userdata(), apply_filters(), time(), get_current_user_id() |
!isset($lock) && get_userdata() && $lock && !$time | 48 | get_post(), get_post_meta(), explode(), get_post_meta(), get_userdata(), apply_filters(), time() |
!isset($lock) && get_userdata() && $lock && $time | 52 | get_post(), get_post_meta(), explode(), get_post_meta(), get_userdata(), apply_filters(), time(), get_current_user_id() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 59 | 7–52 | 7 | |
| 8.5 | 59 | 7–52 | 7 | |
| 8.4 | 59 | 7–52 | 7 | |
| 8.3 | 59 | 7–52 | 7 | |
| 8.2 | 59 | 7–52 | 7 | |
| 8.1 | 59 | 7–52 | 7 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 61 | 7–53 | 7 |
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.
Hooks and filters fired · 1
One hook fires while wp_check_post_lock() runs, in this order:
- apply_filters( wp_check_post_lock_window )filterline 1723 (+22 into the body)
Filters the post lock window duration.
Uses · 5
- get_post()Retrieves post data given a post ID or post object.
- get_post_meta()Retrieves a post meta field for the given post ID.
- get_userdata()Retrieves user info by user ID.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_current_user_id()Gets the current user's ID.
Used by · 15
- WP_Customize_Manager::check_changeset_lock_with_heartbeat()Checks locked changeset with heartbeat API.
- WP_Customize_Manager::customize_pane_settings()Prints JavaScript settings for parent window.
- WP_Customize_Manager::handle_changeset_trash_request()Handles request to trash a changeset.
- WP_Customize_Manager::save()Handles customize_save WP Ajax request to save/update a changeset.
- WP_Posts_List_Table::column_title()Handles the title column output.
- WP_Posts_List_Table::single_row()
- WP_REST_Autosaves_Controller::create_item()Creates, updates or deletes an autosave revision.
- _admin_notice_post_locked()Outputs the HTML for the notice to say that someone else is editing or has taken over editing of this post.
- bulk_edit_posts()Processes the post data for the bulk editing of posts.
- post_preview()Saves a draft or manually autosaves for the purpose of showing a post preview.
- wp_ajax_inline_save()Handles Quick Edit saving a post from a list table via AJAX.
- wp_autosave()Saves a post submitted with XHR.
Show all 15
- wp_check_locked_posts()Checks lock status for posts displayed on the Posts screen.
- wp_print_revision_templates()Print JavaScript templates required for the revisions experience.
- wp_refresh_post_lock()Checks lock status on the New/Edit Post screen and refresh the lock.
Source code
function wp_check_post_lock( $post ) { $post = get_post( $post ); if ( ! $post ) { return false; } $lock = get_post_meta( $post->ID, '_edit_lock', true ); if ( ! $lock ) { return false; } $lock = explode( ':', $lock ); $time = $lock[0]; $user = isset( $lock[1] ) ? (int) $lock[1] : (int) get_post_meta( $post->ID, '_edit_last', true ); if ( ! get_userdata( $user ) ) { return false; } /** This filter is documented in wp-admin/includes/ajax-actions.php */ $time_window = apply_filters( 'wp_check_post_lock_window', 150 ); if ( $time && $time > time() - $time_window && get_current_user_id() !== $user ) { return $user; } return false;}Changelog
Introduced in 2.5.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.7.7 tag, from
src/wp-admin/includes/post.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.