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&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
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.
The WP_List_Table is really great, but be careful with it, since it has not yet been finalized; it could change a lot.
Hi,
Do you have an example where you handle the ‘edit_badges’ action?
P
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):
Does that help?
thanks for that. The logic for the form processing is OK it just i’m not sure what is the correct action hook to link to. I’m using the ‘init’ action and at the end of the function i use wp_mail
add_filter(‘user_row_actions’,array( &$this,’bhaa_runner_renew_link’),10,2);
add_action(‘init’,array(&$this,’bhaa_runner_renew_action’),11);
but I think the ‘init’ action is being called multiple times. I’m wondering is there a more specific action that is only called once by wordpress.
Sorry – have found https://github.com/CGCookie/CGC-User-Badges 😉
Great to hear you found it 🙂
good tip, but I’m wondering how to add those actions on a custom post type table… any idea?
See this Stack Exchange post: http://wordpress.stackexchange.com/questions/14973/row-actions-for-custom-post-types
4 years later… saved my day!