_admin_notice_post_locked

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

Description

_admin_notice_post_locked(); 

Usage

  1. if ( !function_exists( '_admin_notice_post_locked' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/post.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = _admin_notice_post_locked(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/post.php  
  1. function _admin_notice_post_locked() { 
  2. if ( ! $post = get_post() ) 
  3. return; 
  4.  
  5. $user = null; 
  6. if ( $user_id = wp_check_post_lock( $post->ID ) ) 
  7. $user = get_userdata( $user_id ); 
  8.  
  9. if ( $user ) { 
  10.  
  11. /** 
  12. * Filters whether to show the post locked dialog. 
  13. * Returning a falsey value to the filter will short-circuit displaying the dialog. 
  14. * @since 3.6.0 
  15. * @param bool $display Whether to display the dialog. Default true. 
  16. * @param WP_User|bool $user WP_User object on success, false otherwise. 
  17. */ 
  18. if ( ! apply_filters( 'show_post_locked_dialog', true, $post, $user ) ) 
  19. return; 
  20.  
  21. $locked = true; 
  22. } else { 
  23. $locked = false; 
  24.  
  25. if ( $locked && ( $sendback = wp_get_referer() ) && 
  26. false === strpos( $sendback, 'post.php' ) && false === strpos( $sendback, 'post-new.php' ) ) { 
  27.  
  28. $sendback_text = __('Go back'); 
  29. } else { 
  30. $sendback = admin_url( 'edit.php' ); 
  31.  
  32. if ( 'post' != $post->post_type ) 
  33. $sendback = add_query_arg( 'post_type', $post->post_type, $sendback ); 
  34.  
  35. $sendback_text = get_post_type_object( $post->post_type )->labels->all_items; 
  36.  
  37. $hidden = $locked ? '' : ' hidden'; 
  38.  
  39. ?> 
  40. <div id="post-lock-dialog" class="notification-dialog-wrap<?php echo $hidden; ?>"> 
  41. <div class="notification-dialog-background"></div> 
  42. <div class="notification-dialog"> 
  43. <?php 
  44.  
  45. if ( $locked ) { 
  46. $query_args = array(); 
  47. if ( get_post_type_object( $post->post_type )->public ) { 
  48. if ( 'publish' == $post->post_status || $user->ID != $post->post_author ) { 
  49. // Latest content is in autosave 
  50. $nonce = wp_create_nonce( 'post_preview_' . $post->ID ); 
  51. $query_args['preview_id'] = $post->ID; 
  52. $query_args['preview_nonce'] = $nonce; 
  53.  
  54. $preview_link = get_preview_post_link( $post->ID, $query_args ); 
  55.  
  56. /** 
  57. * Filters whether to allow the post lock to be overridden. 
  58. * Returning a falsey value to the filter will disable the ability 
  59. * to override the post lock. 
  60. * @since 3.6.0 
  61. * @param bool $override Whether to allow overriding post locks. Default true. 
  62. * @param WP_Post $post Post object. 
  63. * @param WP_User $user User object. 
  64. */ 
  65. $override = apply_filters( 'override_post_lock', true, $post, $user ); 
  66. $tab_last = $override ? '' : ' wp-tab-last'; 
  67.  
  68. ?> 
  69. <div class="post-locked-message"> 
  70. <div class="post-locked-avatar"><?php echo get_avatar( $user->ID, 64 ); ?></div> 
  71. <p class="currently-editing wp-tab-first" tabindex="0"> 
  72. <?php 
  73. _e( 'This content is currently locked.' ); 
  74. if ( $override ) 
  75. printf( ' ' . __( 'If you take over, %s will be blocked from continuing to edit.' ), esc_html( $user->display_name ) ); 
  76. ?> 
  77. </p> 
  78. <?php 
  79. /** 
  80. * Fires inside the post locked dialog before the buttons are displayed. 
  81. * @since 3.6.0 
  82. * @param WP_Post $post Post object. 
  83. */ 
  84. ?> 
  85. <p> 
  86. <a class="button" href="<?php echo esc_url( $sendback ); ?>"><?php echo $sendback_text; ?></a> 
  87. <?php if ( $preview_link ) { ?> 
  88. <a class="button<?php echo $tab_last; ?>" href="<?php echo esc_url( $preview_link ); ?>"><?php _e('Preview'); ?></a> 
  89. <?php 
  90.  
  91. // Allow plugins to prevent some users overriding the post lock 
  92. if ( $override ) { 
  93. ?> 
  94. <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> 
  95. <?php 
  96.  
  97. ?> 
  98. </p> 
  99. </div> 
  100. <?php 
  101. } else { 
  102. ?> 
  103. <div class="post-taken-over"> 
  104. <div class="post-locked-avatar"></div> 
  105. <p class="wp-tab-first" tabindex="0"> 
  106. <span class="currently-editing"></span><br /> 
  107. <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…' ); ?></span> 
  108. <span class="locked-saved hidden"><?php _e('Your latest changes were saved as a revision.'); ?></span> 
  109. </p> 
  110. <?php 
  111. /** 
  112. * Fires inside the dialog displayed when a user has lost the post lock. 
  113. * @since 3.6.0 
  114. * @param WP_Post $post Post object. 
  115. */ 
  116. ?> 
  117. <p><a class="button button-primary wp-tab-last" href="<?php echo esc_url( $sendback ); ?>"><?php echo $sendback_text; ?></a></p> 
  118. </div> 
  119. <?php 
  120.  
  121. ?> 
  122. </div> 
  123. </div> 
  124. <?php