wp_set_post_lock()
Marks the post as currently being edited by the current user.
No Hooks.
Return
Array|false
. Array of the lock time and user ID. False if the post does not exist, or there is no current user.
Usage
wp_set_post_lock( $post );
- $post(int|WP_Post) (required)
- ID or object of the post being edited.
Changelog
Since 2.5.0 | Introduced. |
wp_set_post_lock() wp set post lock code WP 6.7.1
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 ); }