bbp_check_post_lock( int $post_id )
Check to see if the post is currently being edited by another user.
Description Description
See also See also
Parameters Parameters
- $post_id
-
(Required) ID of the post to check for editing
Return Return
(integer) False: not locked or locked by current user. Int: user ID of user with lock.
Source Source
File: includes/common/locks.php
function bbp_check_post_lock( $post_id = 0 ) {
// Bail if no post
if ( !$post = get_post( $post_id ) ) {
return false;
}
// Bail if no lock
if ( !$lock = get_post_meta( $post->ID, '_edit_lock', true ) ) {
return false;
}
// Get lock
$lock = explode( ':', $lock );
$time = $lock[0];
$user = (int) isset( $lock[1] )
? $lock[1]
: get_post_meta( $post->ID, '_edit_last', true );
// Filter editing window duration
$time_window = apply_filters( 'bbp_check_post_lock_window', 3 * MINUTE_IN_SECONDS );
// Return user who is or last edited
if ( ! empty( $time ) && ( $time > ( time() - $time_window ) ) && ( $user !== bbp_get_current_user_id() ) ) {
return (int) $user;
}
return false;
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.6.0 | Introduced. |