I am trying to allow my editors and admins to click to “Edit Author” as they would “Edit Post” or “Edit [Custom Post Type]” from the admin bar when they are on a page like /authors/jdoe
(Note: I do $wp_rewrite->author_base="people"
so that my addresses are /people/jdoe … not sure if that creates any potential issues.)
I tried to do this through functions but later read that functions.php is processed too early to get the current template or any variables or IDs from the page content.
function add_author_edit_link( $wp_admin_bar ) {
if ( is_page_template('author.php') ) {
$args = array(
'id' => 'author-edit',
'title' => __( 'Edit Person' ),
'href' => '/wp-admin/user-edit.php?user_id=' . $user->ID
);
$wp_admin_bar->add_node($args);
} // if is_page_template author
}
add_action( 'admin_bar_menu', 'add_author_edit_link', 500 );
Not sure how to approach this but will appreciate any thoughts.
I guess I could try to put it into the page content for certain roles only, but is there no easier way to add something like it to the admin bar?