Last active
March 11, 2017 00:20
-
-
Save mklasen/e6bcdfb8ff0bf2bca09f1b6db2d89f22 to your computer and use it in GitHub Desktop.
Show a message on front-end when someone is editing the post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function mk_check_edit_in_progress($content) { | |
if (!is_single()) | |
return $content; | |
if ( !$lock = get_post_meta( get_the_ID(), '_edit_lock', true ) ) | |
return false; | |
$lock = explode( ':', $lock ); | |
$time = $lock[0]; | |
$user_id = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true ); | |
$time_window = apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 ); | |
if ( $time && $time > time() - $time_window && $user_id != get_current_user_id() ) { | |
$user = get_userdata($user_id); | |
$text = 'is currently editing this post'; | |
$admin_defined = get_option( 'mklasens-post-edit-status-settings' ); | |
if (isset($admin_defined['display_text'])) | |
$text = $admin_defined['display_text']; | |
$prepend = '<span class="mk-post-locked"><i>' . $user->user_nicename . ' ' . $text . '.</i></span>'; | |
return $prepend.$content; | |
} | |
return $content; | |
} | |
add_filter('the_content', 'mk_check_edit_in_progress'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment