wppaste
WordPress

wp_check_post_lock( int|WP_Post $post ): int|false

Since
2.5.0
Source
wp-admin/includes/post.php:1701
Determines whether the post is currently being edited by another user.

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

Reaches the database via get_post().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
7–52

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 59.

Plugin surface
1 hook

Third-party callbacks on 'wp_check_post_lock_window' run inside this call, and their cost is not bounded by anything here.

Called by
15

15 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
always7get_post()
always16get_post(), get_post_meta()
isset($lock) && !get_userdata()32get_post(), get_post_meta(), explode(), get_userdata()
!isset($lock) && !get_userdata()37get_post(), get_post_meta(), explode(), get_post_meta(), get_userdata()
isset($lock) && get_userdata() && !$lock38get_post(), get_post_meta(), explode(), get_userdata(), apply_filters()
!isset($lock) && get_userdata() && !$lock43get_post(), get_post_meta(), explode(), get_post_meta(), get_userdata(), apply_filters()
isset($lock) && get_userdata() && $lock && !$time43get_post(), get_post_meta(), explode(), get_userdata(), apply_filters(), time()
isset($lock) && get_userdata() && $lock && $time47get_post(), get_post_meta(), explode(), get_userdata(), apply_filters(), time(), get_current_user_id()
!isset($lock) && get_userdata() && $lock && !$time48get_post(), get_post_meta(), explode(), get_post_meta(), get_userdata(), apply_filters(), time()
!isset($lock) && get_userdata() && $lock && $time52get_post(), get_post_meta(), explode(), get_post_meta(), get_userdata(), apply_filters(), time(), get_current_user_id()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev597–527
8.5597–527
8.4597–527
8.3597–527
8.2597–527
8.1597–5272 fewer instructions than PHP 7.4
7.4617–537

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:

  1. apply_filters( wp_check_post_lock_window )filterline 1723 (+22 into the body)

    Filters the post lock window duration.

Uses · 5

Used by · 15

Show all 15

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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.