Skip to content

Instantly share code, notes, and snippets.

@ammist
Last active July 7, 2018 15:44
Show Gist options
  • Save ammist/b9cf8297ed9b437dbbbf435986bcde27 to your computer and use it in GitHub Desktop.
Save ammist/b9cf8297ed9b437dbbbf435986bcde27 to your computer and use it in GitHub Desktop.
Get info about owner and last modified by in WordPress
function tl_show_page_owner(){
// uncomment the line below if you want to use this only on pages.
// if (!is_page()) return;
$page = get_queried_object();
if (!($page instanceof WP_Post)){
return;
}
//$mod_date = date('M d, Y \a\t g:s a', strtotime($page->post_modified));
$mod_date = get_the_modified_date();
$page_owner = $page->post_author;
$page_owner = get_user_by('id', $page->post_author);
$first_name = get_user_meta($page->post_author, 'first_name', true);
$last_name = get_user_meta($page->post_author, 'last_name', true);
if (!$first_name && !$last_name){
$first_name = $page_owner->user_nicename;
}
$owner = $first_name . ' ' . $last_name;
// get the person who did the modifications
$last_editor_id = get_post_meta($page->ID, '_edit_last', true);
$last_editor = "deleted user";
if ($last_editor_id){
$last_editor_user = get_user_by('id', $last_editor_id);
if ($last_editor_user){
$first_name = get_user_meta($last_editor_id, 'first_name', true);
$last_name = get_user_meta($last_editor_id, 'last_name', true);
if (!$first_name && !$last_name){
$first_name = $last_editor_user->user_nicename;
}
$last_editor = $first_name . ' ' . $last_name;
}
}
echo "<p class='entry-meta page-owner'>Page owned by <a href='mailto:{$page_owner->user_email}'>$owner</a>. Last modified on <span class='date'>$mod_date</span> by $last_editor.</p>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment