1

I'd like to create a kind of auditing. How can I check if an user is modifying an article?

Is there a db query I can do to achieve this task?

enter image description here

I've found the following solution but I wonder if there is a native WordPress solution: https://wordpress.stackexchange.com/a/297035/64590

1

Yes, there is a function in WP for that: wp_check_post_lock()

Give it the post ID and it will return the user ID that is currently editing the post OR false if no one is editing the post (i.e. it is not locked).

$is_locked = wp_check_post_lock( $post_id );

if ( false === $is_locked ) {

     // Post $post_id is not not locked for editing

} else {

     // Post is not locked, $is_locked contains the user ID who is editing.
     $user = get_user_by( 'id', $is_locked );
     echo 'Post id being edited by ' . $user->user_login;

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.