You could try this modification of your code:
function add_author_edit_link( $wp_admin_bar )
{
if ( is_author() && current_user_can( 'add_users' ) )
{
$args = array(
'id' => 'author-edit',
'title' => __( 'Edit Author' ),
'href' => admin_url( sprintf(
'user-edit.php?user_id=%d',
get_queried_object_id()
) )
);
$wp_admin_bar->add_node($args);
}
}
add_action( 'admin_bar_menu', 'add_author_edit_link', 99 );
where we use the get_queried_object_id()
function to get the author id.
Notice that you can use the admin_url()
to get the url to the backend.
I use is_author()
here instead of is_page_template( 'author.php' )
.
This Edit Author link might not be relevant for users that can’t modify other users, so I added the current_user_can( 'add_users' )
check. I couldn’t find the edit_users
capability so I used add_users
instead.