Title: _admin_notice_post_locked
Published: April 25, 2014
Last modified: February 24, 2026

---

# _admin_notice_post_locked()

## In this article

 * [Source](https://developer.wordpress.org/reference/functions/_admin_notice_post_locked/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/_admin_notice_post_locked/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/_admin_notice_post_locked/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_admin_notice_post_locked/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/_admin_notice_post_locked/?output_format=md#wp--skip-link--target)

Outputs the HTML for the notice to say that someone else is editing or has taken
over editing of this post.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/_admin_notice_post_locked/?output_format=md#source)󠁿

    ```php
    function _admin_notice_post_locked() {
    	$post = get_post();

    	if ( ! $post ) {
    		return;
    	}

    	$user    = null;
    	$user_id = wp_check_post_lock( $post->ID );

    	if ( $user_id ) {
    		$user = get_userdata( $user_id );
    	}

    	if ( $user ) {
    		/**
    		 * Filters whether to show the post locked dialog.
    		 *
    		 * Returning false from the filter will prevent the dialog from being displayed.
    		 *
    		 * @since 3.6.0
    		 *
    		 * @param bool    $display Whether to display the dialog. Default true.
    		 * @param WP_Post $post    Post object.
    		 * @param WP_User $user    The user with the lock for the post.
    		 */
    		if ( ! apply_filters( 'show_post_locked_dialog', true, $post, $user ) ) {
    			return;
    		}

    		$locked = true;
    	} else {
    		$locked = false;
    	}

    	$sendback      = wp_get_referer();
    	$sendback_text = __( 'Go back' );

    	if ( ! $locked || ! $sendback || str_contains( $sendback, 'post.php' ) || str_contains( $sendback, 'post-new.php' ) ) {
    		$sendback = admin_url( 'edit.php' );

    		if ( 'post' !== $post->post_type ) {
    			$sendback = add_query_arg( 'post_type', $post->post_type, $sendback );
    		}

    		$post_type_object = get_post_type_object( $post->post_type );

    		if ( $post_type_object ) {
    			$sendback_text = $post_type_object->labels->all_items;
    		}
    	}

    	$hidden = $locked ? '' : ' hidden';

    	?>
    	<div id="post-lock-dialog" class="notification-dialog-wrap<?php echo $hidden; ?>">
    	<div class="notification-dialog-background"></div>
    	<div class="notification-dialog">
    	<?php

    	if ( $locked ) {
    		$query_args = array();
    		if ( get_post_type_object( $post->post_type )->public ) {
    			if ( 'publish' === $post->post_status || $user->ID !== (int) $post->post_author ) {
    				// Latest content is in autosave.
    				$nonce                       = wp_create_nonce( 'post_preview_' . $post->ID );
    				$query_args['preview_id']    = $post->ID;
    				$query_args['preview_nonce'] = $nonce;
    			}
    		}

    		$preview_link = get_preview_post_link( $post->ID, $query_args );

    		/**
    		 * Filters whether to allow the post lock to be overridden.
    		 *
    		 * Returning false from the filter will disable the ability
    		 * to override the post lock.
    		 *
    		 * @since 3.6.0
    		 *
    		 * @param bool    $override Whether to allow the post lock to be overridden. Default true.
    		 * @param WP_Post $post     Post object.
    		 * @param WP_User $user     The user with the lock for the post.
    		 */
    		$override = apply_filters( 'override_post_lock', true, $post, $user );
    		$tab_last = $override ? '' : ' wp-tab-last';

    		?>
    		<div class="post-locked-message">
    		<div class="post-locked-avatar"><?php echo get_avatar( $user->ID, 64 ); ?></div>
    		<p class="currently-editing wp-tab-first" tabindex="0">
    		<?php
    		if ( $override ) {
    			/* translators: %s: User's display name. */
    			printf( __( '%s is currently editing this post. Do you want to take over?' ), esc_html( $user->display_name ) );
    		} else {
    			/* translators: %s: User's display name. */
    			printf( __( '%s is currently editing this post.' ), esc_html( $user->display_name ) );
    		}
    		?>
    		</p>
    		<?php
    		/**
    		 * Fires inside the post locked dialog before the buttons are displayed.
    		 *
    		 * @since 3.6.0
    		 * @since 5.4.0 The $user parameter was added.
    		 *
    		 * @param WP_Post $post Post object.
    		 * @param WP_User $user The user with the lock for the post.
    		 */
    		do_action( 'post_locked_dialog', $post, $user );
    		?>
    		<p>
    		<a class="button" href="<?php echo esc_url( $sendback ); ?>"><?php echo $sendback_text; ?></a>
    		<?php if ( $preview_link ) { ?>
    		<a class="button<?php echo $tab_last; ?>" href="<?php echo esc_url( $preview_link ); ?>"><?php _e( 'Preview' ); ?></a>
    			<?php
    		}

    		// Allow plugins to prevent some users overriding the post lock.
    		if ( $override ) {
    			?>
    	<a class="button button-primary wp-tab-last" href="<?php echo esc_url( add_query_arg( 'get-post-lock', '1', wp_nonce_url( get_edit_post_link( $post->ID, 'url' ), 'lock-post_' . $post->ID ) ) ); ?>"><?php _e( 'Take over' ); ?></a>
    			<?php
    		}

    		?>
    		</p>
    		</div>
    		<?php
    	} else {
    		?>
    		<div class="post-taken-over">
    			<div class="post-locked-avatar"></div>
    			<p class="wp-tab-first" tabindex="0">
    			<span class="currently-editing"></span><br />
    			<span class="locked-saving hidden"><img src="<?php echo esc_url( admin_url( 'images/spinner-2x.gif' ) ); ?>" width="16" height="16" alt="" /> <?php _e( 'Saving revision&hellip;' ); ?></span>
    			<span class="locked-saved hidden"><?php _e( 'Your latest changes were saved as a revision.' ); ?></span>
    			</p>
    			<?php
    			/**
    			 * Fires inside the dialog displayed when a user has lost the post lock.
    			 *
    			 * @since 3.6.0
    			 *
    			 * @param WP_Post $post Post object.
    			 */
    			do_action( 'post_lock_lost_dialog', $post );
    			?>
    			<p><a class="button button-primary wp-tab-last" href="<?php echo esc_url( $sendback ); ?>"><?php echo $sendback_text; ?></a></p>
    		</div>
    		<?php
    	}

    	?>
    	</div>
    	</div>
    	<?php
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/post.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/post.php#L1790)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/post.php#L1790-L1950)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/_admin_notice_post_locked/?output_format=md#hooks)󠁿

 [apply_filters( ‘override_post_lock’, bool $override, WP_Post $post, WP_User $user )](https://developer.wordpress.org/reference/hooks/override_post_lock/)

Filters whether to allow the post lock to be overridden.

 [do_action( ‘post_locked_dialog’, WP_Post $post, WP_User $user )](https://developer.wordpress.org/reference/hooks/post_locked_dialog/)

Fires inside the post locked dialog before the buttons are displayed.

 [do_action( ‘post_lock_lost_dialog’, WP_Post $post )](https://developer.wordpress.org/reference/hooks/post_lock_lost_dialog/)

Fires inside the dialog displayed when a user has lost the post lock.

 [apply_filters( ‘show_post_locked_dialog’, bool $display, WP_Post $post, WP_User $user )](https://developer.wordpress.org/reference/hooks/show_post_locked_dialog/)

Filters whether to show the post locked dialog.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/_admin_notice_post_locked/?output_format=md#related)󠁿

| Uses | Description | 
| [get_preview_post_link()](https://developer.wordpress.org/reference/functions/get_preview_post_link/)`wp-includes/link-template.php` |

Retrieves the URL used for the post preview.

  | 
| [wp_check_post_lock()](https://developer.wordpress.org/reference/functions/wp_check_post_lock/)`wp-admin/includes/post.php` |

Determines whether the post is currently being edited by another user.

  | 
| [get_avatar()](https://developer.wordpress.org/reference/functions/get_avatar/)`wp-includes/pluggable.php` |

Retrieves the avatar `<img>` tag for a user, email address, MD5 hash, comment, or post.

  | 
| [wp_get_referer()](https://developer.wordpress.org/reference/functions/wp_get_referer/)`wp-includes/functions.php` |

Retrieves referer from ‘_wp_http_referer’ or HTTP referer.

  | 
| [get_edit_post_link()](https://developer.wordpress.org/reference/functions/get_edit_post_link/)`wp-includes/link-template.php` |

Retrieves the edit post link for post.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [_e()](https://developer.wordpress.org/reference/functions/_e/)`wp-includes/l10n.php` |

Displays translated text.

  | 
| [esc_html()](https://developer.wordpress.org/reference/functions/esc_html/)`wp-includes/formatting.php` |

Escaping for HTML blocks.

  | 
| [esc_url()](https://developer.wordpress.org/reference/functions/esc_url/)`wp-includes/formatting.php` |

Checks and cleans a URL.

  | 
| [wp_create_nonce()](https://developer.wordpress.org/reference/functions/wp_create_nonce/)`wp-includes/pluggable.php` |

Creates a cryptographic token tied to a specific action, user, user session, and window of time.

  | 
| [get_userdata()](https://developer.wordpress.org/reference/functions/get_userdata/)`wp-includes/pluggable.php` |

Retrieves user info by user ID.

  | 
| [wp_nonce_url()](https://developer.wordpress.org/reference/functions/wp_nonce_url/)`wp-includes/functions.php` |

Retrieves URL with nonce added to URL query.

  | 
| [add_query_arg()](https://developer.wordpress.org/reference/functions/add_query_arg/)`wp-includes/functions.php` |

Retrieves a modified URL query string.

  | 
| [admin_url()](https://developer.wordpress.org/reference/functions/admin_url/)`wp-includes/link-template.php` |

Retrieves the URL to the admin area for the current site.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [do_action()](https://developer.wordpress.org/reference/functions/do_action/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to an action hook.

  | 
| [get_post()](https://developer.wordpress.org/reference/functions/get_post/)`wp-includes/post.php` |

Retrieves post data given a post ID or post object.

  | 
| [get_post_type_object()](https://developer.wordpress.org/reference/functions/get_post_type_object/)`wp-includes/post.php` |

Retrieves a post type object by name.

  |

[Show 13 more](https://developer.wordpress.org/reference/functions/_admin_notice_post_locked/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/_admin_notice_post_locked/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/_admin_notice_post_locked/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.8.5](https://developer.wordpress.org/reference/since/2.8.5/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2F_admin_notice_post_locked%2F)
before being able to contribute a note or feedback.