Am trying to add a link besides the Edit | Delete links in wordpress admin > users > all users list through a plugin.. this is my first attempt at making a wordpress plugin by looking at other plugins or search google..
I have added a function
function pa_user_list_pay_link( $actions, $user_object ) {
if ( current_user_can( 'administrator', $user_object->ID ) )
$actions['pay'] = '<a href="#">Pay</a>';
return $actions;
}
and the applied the filter
add_filter( 'user_row_actions', array( $this, 'pa_user_list_pay_link' ), 10, 2 );
But something seems to go wrong as this link is not appearing and the Edit | Delete links also disappear (no longer in the html output)
UPDATE 1 : I modified /wp-admin/includes/class-wp-users-list-table.php
After this line
$actions = apply_filters( 'user_row_actions', $actions, $user_object );
I added this
file_put_contents("test_output.txt" , count($actions));
the test_output.txt was written to /wp-admin/ and it contained 0
I think i am doing some mistake in applying the filter..
Update 2: Answered my own question.
function pa_user_list_pay_link( $actions, $user_object ) {
if ( current_user_can( 'administrator', $user_object->ID ) )
$actions['pay'] = '<a href="#">Pay</a>';
return $actions;
}
add_filter( 'user_row_actions', 'pa_user_list_pay_link', 10, 2 );
Works! :D
If the edit / delete links are disappearing, that'd imply your function's being called, but causing an error.
The first thing I wonder looking at your code is whether $actions
is an associative array. Does it work if you change
$actions['pay'] = '<a href="#">Pay</a>';
to
$actions[] = '<a href="#">Pay</a>';
?
If that works, you can look at inserting it into the right position, rather than appending.
Just for testing purposes, I'd comment out the if
statement too, to eliminate permissions as a cause of the error (i.e. try to work out why edit/delete are disappearing before adding too much other logic).
I think there is best way to do it.you can customize Edit and Delete or Add new badge by using add_action('user_row_actions','your_function_name') . for more details you can visit the site where i found the best solution..See this post Add or edit custom link in wp users list in wordpress admin
Hope it will help you..
add_filter
wasn't being called from inside a class - Hobo 2012-04-05 10:54