On this page
wp_set_post_lock( int|WP_Post $post ): array|false
Marks the post as currently being edited by the current user.
Parameters
$postint|WP_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.
- int
The current time as a Unix timestamp.
1intThe ID of the current user.
Source
File: wp-admin/includes/post.php. View all references
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 );
}
Related
Uses
| Uses | Description |
|---|---|
| update_post_meta() wp-includes/post.php | Updates a post meta field based on the given post ID. |
| get_current_user_id() wp-includes/user.php | Gets the current user’s ID. |
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
Used By
| Used By | Description |
|---|---|
| wp_refresh_post_lock() wp-admin/includes/misc.php | Checks lock status on the New/Edit Post screen and refresh the lock. |
| wp_write_post() wp-admin/includes/post.php | Creates a new post from the “Write Post” form using |
| edit_post() wp-admin/includes/post.php | Updates an existing post with values provided in |
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_set_post_lock