Pippins Plugins
  • Email
  • Facebook
  • Feedburner
  • Github
  • Google
  • Twitter
  • Vimeo
  • Youtube
  • Rss
  • About
  • News
  • Join the Site
    • Member Benefits
    • Member Plugins
    • Email Notifications
  • Plugin Store
    • Affiliate Area
    • Checkout
  • Plugins
    • Plugin Portfolio
      • Plugin Portfolio – List View
    • Free
    • Premium
    • Member Plugins
    • Coding Standards
    • Get Plugin Support
  • Tutorials
    • Series
      • Plugin Development 101
      • Creating a User Follow System Plugin
      • Customizing Restrict Content Pro
      • Displaying Content with Easy Content Types
      • Writing Your First WordPress Plugins, Basic to Advanced
      • Working with Widgets
      • User Submitted Image Galleries
      • Plugin Thoughts
      • Integrating Stripe.com with WordPress
      • WordPress Rewrite API
    • Member Exclusive
      • Free Members
      • Subscriber Only
    • Difficulty
      • Beginner
      • Intermediate
      • Advanced
    • Action and Filter Hooks
    • Ajax
    • Custom Post Types
    • External APIs
    • Short Codes
    • Taxonomies
    • Video Tutorials
    • Widget Tutorials
    • WordPress Admin / Dashboard
    • Working with jQuery
    • WordPress Database
    • Writing Plugins
    • Tag Index
  • Reviews
  • Support Forum
  • Contact
    • Support the Site
    • Request Code Review
    • Plugin Support

Add Custom Links to User Row Actions

Posted on April 18, 2012 by Pippin in Action and Filter Hooks, Intermediate, Tutorials, Working with Users, Writing Plugins 6 Comments
Home» Tutorials » Action and Filter Hooks » Add Custom Links to User Row Actions
Tweet
Love It - 1

While working on a user badge system for the CG Cookie network, I came across the need to add a custom link to the action links, such as Edit and Delete, present for each user on the WordPress Users page. After a quick google search, I was able to find a simple filter than can be used for doing exactly this.

The user row action links I’m referring to are those shown in the screenshot below:

WordPress has a filter setup that we can use to add our own custom links, or even modify existing ones, and it’s called “user_row_actions”. You can see the source for the core function that sets up the action links here.

I wanted to add a “Edit Badges” link to the list of actions, and this was quite simply done with the following function:

1
2
3
4
5
function cgc_ub_action_links($actions, $user_object) {
	$actions['edit_badges'] = "<a class='cgc_ub_edit_badges' href='" . admin_url( "users.php?page=cgc-badges&action=cgc_edit_badges&amp;user=$user_object->ID") . "'>" . __( 'Edit Badges', 'cgc_ub' ) . "</a>";
	return $actions;
}
add_filter('user_row_actions', 'cgc_ub_action_links', 10, 2);

Really quite simple, and the result looks like this:

Note, similar functions also exist for posts and pages:

post_row_actions
page_row_actions
Tweet Follow @pippinsplugins
add_filter, page_row_actions, post_row_actions, user_row_actions

6 comments on “Add Custom Links to User Row Actions”

  1. designerken says:
    April 29, 2012 at 10:22 pm

    Nice little tip there pippin, I have also found a way to create a user table by extending the class for WP_List_Table. In this you can also add in your own links.

    Reply
    • Pippin says:
      April 30, 2012 at 9:52 am

      The WP_List_Table is really great, but be careful with it, since it has not yet been finalized; it could change a lot.

  2. emeraldjava says:
    November 20, 2012 at 7:50 am

    Hi,

    Do you have an example where you handle the ‘edit_badges’ action?

    P

    Reply
    • Pippin says:
      November 20, 2012 at 9:44 am

      The edit_badges action would be handled from the function that you have setup to render your custom admin page (note the ?page= part). Inside of that function, you can do something like this (taken directly from the system I wrote):

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      
      if(isset($_GET['cgc_ub_page']) && wp_verify_nonce($_GET['_wpnonce'], 'cgc_ub_edit')) { 
      	switch($_GET['cgc_ub_page']) {
      		case 'edit_badge' :
      			include(CGC_UB_PLUGIN_DIR . '/includes/edit-badge.php');
      			break;
      		case 'edit_users_badges' :
      			include(CGC_UB_PLUGIN_DIR . '/includes/edit-users-badges.php');
      			break;
      	}
      }

      Does that help?

  3. Lucianno says:
    February 21, 2013 at 8:47 am

    good tip, but I’m wondering how to add those actions on a custom post type table… any idea?

    Reply
    • Pippin says:
      February 21, 2013 at 5:46 pm

      See this Stack Exchange post: http://wordpress.stackexchange.com/questions/14973/row-actions-for-custom-post-types

Leave a Reply Cancel reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Login

Lost your password?

Please enter your username or e-mail address. You will receive a new password via e-mail.

  • Facebook Become a Fan Like

  • Twitter Subscribe on Twitter Follow

  • YouTube Follow my Videos Subscribe

  • RSS Feed Subscribe with RSS Subscribe

Easy Digital Downloads

Most Loved

  • Love It Pro for WordPress
  • Write a “Love It” Plugin with Ajax to Let Users Love Their Favorite Posts / Pages
  • Simple Notices Pro Plugin for WordPress
  • User Bookmarks for WordPress
  • Front End Registration and Login Forms Plugin

Similar Plugins and Posts

  • Plugin Development 101 – An Intro to Filters
  • Introduction to the gettext Filter in WordPress
  • Let’s Talk Extensible Code
  • Playing Nice with the “the_content” Filter
  • Adding Custom Fields to the Easy Digital Downloads Checkout

Latest Premium Content

  • Plugin Development 101 – Introduction to Adding Dashboard Menus
  • Plugin Development 101 – Intro to Loading Scripts and Styles
  • User Follow System – Part 5
  • Plugin Development 101 – Intro to Short Codes
  • Plugin Development 101 – Registering a Custom Post Type
  • Plugin Development 101 – Intro to Actions

Latest Tutorials

  • Test Your Plugins with RTL (0)

    Right-To-Left languages are those that...

  • Submitting Your First Pull Request to a WordPress Plugin on Github (5)

    Github is an extremely popular tool for managing WordPress plugins, and one...

  • Plugin Development 101 – Introduction to Adding Dashboard Menus (1)

    Adding new menus, both top level and sub level, to the WordPress Dashboard is a really common task for plugins...

Enter your email to receive automated updates when new posts are published

Latest Tweets

  • @Otto42 certainly a more entertaining alternative
    May 26, 2013
  • RT @toscho: #WordPress: How post meta fields work. http://t.co/uDRaDu0EsS
    May 25, 2013
  • RT @strickland: Afternoon crowd: To celebrate Memorial Day weekend @gittyapp is on sale through Monday. Now is the time to join in! http:/…
    May 25, 2013

Topics

the_content wp_enqueue_script add_options_page shortcodes Tom McFarlin get_user_meta contextual help attachments add_shortcode register_setting featured Sugar Event Calendar meta box authors attachment Related posts image plugin forms do_action short codes mail chimp login bbpress recent posts comments apply_filters post types short code taxonomies custom post type Ajax images gallery Stripe taxonomy jquery widgets users add_filter easy content types add_action widget restrict content pro easy digital downloads

Weekly Newsletter

Useful Links

  • Join the Site
  • Plugin Store
  • Affiliate Area
  • Tag Index
  • Support the Site
  • Suggest a Tutorial
  • Random Post
  • Contact

Monthly Archives

(c) 2013 Pippin's Plugins