wp_set_post_lock

The timeline below displays how wordpress function wp_set_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

/**
 * Marks the post as currently being edited by the current user.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post $post ID or object of the post being edited.
 * @return array|false {
 *     Array of the lock time and user ID. False if the post does not exist, or there
 *     is no current user.
 *
 *     @type int $0 The current time as a Unix timestamp.
 *     @type int $1 The ID of the current user.
 * }
 */
function wp_set_post_lock($post)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $user_id = get_current_user_id();
    if (0 == $user_id) {
        return false;
    }
    $now = time();
    $lock = "{$now}:{$user_id}";
    update_post_meta($post->ID, '_edit_lock', $lock);
    return array($now, $user_id);
}

WordPress Version: 5.9

/**
 * Marks the post as currently being edited by the current user.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post $post_id ID or object of the post being edited.
 * @return array|false Array of the lock time and user ID. False if the post does not exist, or
 *                     there is no current user.
 */
function wp_set_post_lock($post_id)
{
    $post = get_post($post_id);
    if (!$post) {
        return false;
    }
    $user_id = get_current_user_id();
    if (0 == $user_id) {
        return false;
    }
    $now = time();
    $lock = "{$now}:{$user_id}";
    update_post_meta($post->ID, '_edit_lock', $lock);
    return array($now, $user_id);
}

WordPress Version: 5.6

/**
 * Mark the post as currently being edited by the current user
 *
 * @since 2.5.0
 *
 * @param int|WP_Post $post_id ID or object of the post being edited.
 * @return array|false Array of the lock time and user ID. False if the post does not exist, or
 *                     there is no current user.
 */
function wp_set_post_lock($post_id)
{
    $post = get_post($post_id);
    if (!$post) {
        return false;
    }
    $user_id = get_current_user_id();
    if (0 == $user_id) {
        return false;
    }
    $now = time();
    $lock = "{$now}:{$user_id}";
    update_post_meta($post->ID, '_edit_lock', $lock);
    return array($now, $user_id);
}

WordPress Version: 5.3

/**
 * Mark the post as currently being edited by the current user
 *
 * @since 2.5.0
 *
 * @param int $post_id ID of the post being edited.
 * @return array|false Array of the lock time and user ID. False if the post does not exist, or
 *                     there is no current user.
 */
function wp_set_post_lock($post_id)
{
    $post = get_post($post_id);
    if (!$post) {
        return false;
    }
    $user_id = get_current_user_id();
    if (0 == $user_id) {
        return false;
    }
    $now = time();
    $lock = "{$now}:{$user_id}";
    update_post_meta($post->ID, '_edit_lock', $lock);
    return array($now, $user_id);
}

WordPress Version: 4.8

/**
 * Mark the post as currently being edited by the current user
 *
 * @since 2.5.0
 *
 * @param int $post_id ID of the post being edited.
 * @return array|false Array of the lock time and user ID. False if the post does not exist, or
 *                     there is no current user.
 */
function wp_set_post_lock($post_id)
{
    if (!$post = get_post($post_id)) {
        return false;
    }
    if (0 == $user_id = get_current_user_id()) {
        return false;
    }
    $now = time();
    $lock = "{$now}:{$user_id}";
    update_post_meta($post->ID, '_edit_lock', $lock);
    return array($now, $user_id);
}

WordPress Version: 3.7

/**
 * Mark the post as currently being edited by the current user
 *
 * @since 2.5.0
 *
 * @param int $post_id ID of the post to being edited
 * @return bool|array Returns false if the post doesn't exist of there is no current user, or
 * 	an array of the lock time and the user ID.
 */
function wp_set_post_lock($post_id)
{
    if (!$post = get_post($post_id)) {
        return false;
    }
    if (0 == $user_id = get_current_user_id()) {
        return false;
    }
    $now = time();
    $lock = "{$now}:{$user_id}";
    update_post_meta($post->ID, '_edit_lock', $lock);
    return array($now, $user_id);
}