wp_check_post_lock

The timeline below displays how wordpress function wp_check_post_lock has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Determines whether the post is currently being edited by another user.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post $post ID or object of the post to check for editing.
 * @return 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.
 */
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]) ? $lock[1] : 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;
}

WordPress Version: 5.9

/**
 * Determines whether the post is currently being edited by another user.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post $post_id ID or object of the post to check for editing.
 * @return 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.
 */
function wp_check_post_lock($post_id)
{
    $post = get_post($post_id);
    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]) ? $lock[1] : 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;
}

WordPress Version: 5.6

/**
 * Check to see if the post is currently being edited by another user.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post $post_id ID or object of the post to check for editing.
 * @return 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.
 */
function wp_check_post_lock($post_id)
{
    $post = get_post($post_id);
    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]) ? $lock[1] : 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;
}

WordPress Version: 5.4

/**
 * Check to see if the post is currently being edited by another user.
 *
 * @since 2.5.0
 *
 * @param int $post_id ID of the post to check for editing.
 * @return 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.
 */
function wp_check_post_lock($post_id)
{
    $post = get_post($post_id);
    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]) ? $lock[1] : 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;
}

WordPress Version: 5.3

/**
 * Check to see if the post is currently being edited by another user.
 *
 * @since 2.5.0
 *
 * @param int $post_id ID of the post to check for editing.
 * @return 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.
 */
function wp_check_post_lock($post_id)
{
    $post = get_post($post_id);
    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]) ? $lock[1] : 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 && $user != get_current_user_id()) {
        return $user;
    }
    return false;
}

WordPress Version: 4.8

/**
 * Check to see if the post is currently being edited by another user.
 *
 * @since 2.5.0
 *
 * @param int $post_id ID of the post to check for editing.
 * @return 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.
 */
function wp_check_post_lock($post_id)
{
    if (!$post = get_post($post_id)) {
        return false;
    }
    if (!$lock = get_post_meta($post->ID, '_edit_lock', true)) {
        return false;
    }
    $lock = explode(':', $lock);
    $time = $lock[0];
    $user = isset($lock[1]) ? $lock[1] : 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 && $user != get_current_user_id()) {
        return $user;
    }
    return false;
}

WordPress Version: 4.1

/**
 * Check to see if the post is currently being edited by another user.
 *
 * @since 2.5.0
 *
 * @param int $post_id ID of the post to check for editing
 * @return integer False: not locked or locked by current user. Int: user ID of user with lock.
 */
function wp_check_post_lock($post_id)
{
    if (!$post = get_post($post_id)) {
        return false;
    }
    if (!$lock = get_post_meta($post->ID, '_edit_lock', true)) {
        return false;
    }
    $lock = explode(':', $lock);
    $time = $lock[0];
    $user = isset($lock[1]) ? $lock[1] : get_post_meta($post->ID, '_edit_last', true);
    /** 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 && $user != get_current_user_id()) {
        return $user;
    }
    return false;
}

WordPress Version: 3.9

/**
 * Check to see if the post is currently being edited by another user.
 *
 * @since 2.5.0
 *
 * @param int $post_id ID of the post to check for editing
 * @return bool|int False: not locked or locked by current user. Int: user ID of user with lock.
 */
function wp_check_post_lock($post_id)
{
    if (!$post = get_post($post_id)) {
        return false;
    }
    if (!$lock = get_post_meta($post->ID, '_edit_lock', true)) {
        return false;
    }
    $lock = explode(':', $lock);
    $time = $lock[0];
    $user = isset($lock[1]) ? $lock[1] : get_post_meta($post->ID, '_edit_last', true);
    /** 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 && $user != get_current_user_id()) {
        return $user;
    }
    return false;
}

WordPress Version: 3.8

/**
 * Check to see if the post is currently being edited by another user.
 *
 * @since 2.5.0
 *
 * @param int $post_id ID of the post to check for editing
 * @return bool|int False: not locked or locked by current user. Int: user ID of user with lock.
 */
function wp_check_post_lock($post_id)
{
    if (!$post = get_post($post_id)) {
        return false;
    }
    if (!$lock = get_post_meta($post->ID, '_edit_lock', true)) {
        return false;
    }
    $lock = explode(':', $lock);
    $time = $lock[0];
    $user = isset($lock[1]) ? $lock[1] : get_post_meta($post->ID, '_edit_last', true);
    $time_window = apply_filters('wp_check_post_lock_window', 150);
    if ($time && $time > time() - $time_window && $user != get_current_user_id()) {
        return $user;
    }
    return false;
}

WordPress Version: 3.7

/**
 * Check to see if the post is currently being edited by another user.
 *
 * @since 2.5.0
 *
 * @param int $post_id ID of the post to check for editing
 * @return bool|int False: not locked or locked by current user. Int: user ID of user with lock.
 */
function wp_check_post_lock($post_id)
{
    if (!$post = get_post($post_id)) {
        return false;
    }
    if (!$lock = get_post_meta($post->ID, '_edit_lock', true)) {
        return false;
    }
    $lock = explode(':', $lock);
    $time = $lock[0];
    $user = isset($lock[1]) ? $lock[1] : get_post_meta($post->ID, '_edit_last', true);
    $time_window = apply_filters('wp_check_post_lock_window', 120);
    if ($time && $time > time() - $time_window && $user != get_current_user_id()) {
        return $user;
    }
    return false;
}