wp_set_post_lock() WordPress Function

The wp_set_post_lock() function is used to set a post lock for a specific post. This lock will prevent other users from editing the post.

wp_set_post_lock( int|WP_Post $post_id ) #

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


Parameters

$post_id

(int|WP_Post)(Required)ID or object of the post being edited.


Top ↑

Return

(array|false) Array of the lock time and user ID. False if the post does not exist, or there is no current user.

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


Top ↑

Source

File: wp-admin/includes/post.php

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


Top ↑

Changelog

Changelog
VersionDescription
2.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.