Add ‘Edit User’ Toolbar link on author archives

Currently it takes 3-4 steps to get to a user’s edit screen from the front-end, which really comes down to a lot of wasted time when you’re working on a user-heavy site. One of my biggest usability pet peeves is unnecessary extra steps. On the WordPress front-end, we have ‘Edit *’ Toolbar links for objects like taxonomy terms and post types, so why not users?

The question was raised recently by John Blackbourn on Trac and I think it has a lot of merit. I’ll concede that the inherent behavior of an edit link on an archive shouldn’t be to edit an object but an author archive (usually) serves dual purposes: Author info and author archive.

Here’s the snippet I worked up from @lessbloat’s revised patch:

function ww_toolbar_edit_user_link( $wp_admin_bar ) {
	$current = get_queried_object();
	
	// Check that it's a WP_User object and user is editable
	if ( is_a( $current, 'WP_User' ) 
		&& current_user_can( 'edit_user', $current->ID ) ) {
	
		// Add the menu
		$wp_admin_bar->add_menu( array(
			'id' => 'edit',
			'title' => __( 'Edit User' ),
			'href' => get_edit_user_link( $current->ID ),
			'meta' => array(
				'title' => __( 'Edit User' )
			)
		) );
	}
}
add_action( 'admin_bar_menu', 'ww_toolbar_edit_user_link', 81 );

Published by

Drew Jaynes

Drew is a former Core Developer for the WordPress open source project, and he works on cool plugins like AffiliateWP, Easy Digital Downloads, and Restrict Content Pro.

Leave a Reply

Your email address will not be published. Required fields are marked *