wp_set_post_lock( int|WP_Post $post )

Marks the post as currently being edited by the current user.


Parameters

$post

(Required) 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.<br>

  • (int) The current time as a Unix timestamp.<br>
  • '1'
    (int) The ID of the current user.<br>


Source

File: wp-admin/includes/post.php

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 );
}


Changelog

Changelog
Version Description
2.5.0 Introduced.