The post_locked_dialog WordPress PHP action fires inside the post locked dialog before the buttons are displayed.
Usage
add_action('post_locked_dialog', 'your_custom_function', 10, 2); function your_custom_function($post, $user) { // your custom code here }
Parameters
$post
(WP_Post) – Post object.$user
(WP_User) – The user with the lock for the post.
More information
See WordPress Developer Resources: post_locked_dialog
Examples
Display a custom message in the post locked dialog
This example adds a custom message to the post locked dialog.
add_action('post_locked_dialog', 'display_custom_message', 10, 2); function display_custom_message($post, $user) { echo '<p><strong>Note:</strong> Please coordinate with ' . esc_html($user->display_name) . ' before editing this post.</p>'; }
Show the locked user’s email
This example displays the email address of the user who locked the post.
add_action('post_locked_dialog', 'show_locked_user_email', 10, 2); function show_locked_user_email($post, $user) { echo '<p>Email of user who locked the post: ' . esc_html($user->user_email) . '</p>'; }
Display the time the post was locked
This example shows the time when the post was locked by the user.
add_action('post_locked_dialog', 'display_locked_time', 10, 2); function display_locked_time($post, $user) { $lock_time = get_post_meta($post->ID, '_edit_lock', true); if ($lock_time) { $lock_time = date('F j, Y, g:i a', $lock_time); echo '<p>Post was locked on: ' . esc_html($lock_time) . '</p>'; } }
Show a link to the user’s profile
This example adds a link to the profile of the user who locked the post.
add_action('post_locked_dialog', 'link_to_locked_user_profile', 10, 2); function link_to_locked_user_profile($post, $user) { $profile_url = get_author_posts_url($user->ID); echo '<p><a href="' . esc_url($profile_url) . '">View ' . esc_html($user->display_name) . '\'s profile</a></p>'; }
Add a custom CSS class to the post locked dialog
This example adds a custom CSS class to the post locked dialog for styling purposes.
add_action('post_locked_dialog', 'add_custom_css_class', 10, 2); function add_custom_css_class($post, $user) { echo '<style>.wp-core-ui .notification-dialog { background-color: #f7f7f7; }</style>'; }