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:

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

Published by

Drew Jaynes

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

Leave a Reply