Wordpress filter user_row_actions

Go To StackoverFlow.com

2

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.

2012-04-04 18:47
by Prathamesh Gharat


4

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

2012-04-05 03:47
by Prathamesh Gharat
Ah - so your add_filter wasn't being called from inside a class - Hobo 2012-04-05 10:54
No, am very new to plugin writing so wanted to keep it as simple as possible.. whats the benefit of having everything inside a class in a wordpress plugin - Prathamesh Gharat 2012-04-07 03:07


1

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).

2012-04-04 20:55
by Hobo
ok, am giving it a try now, thanks for the tips - Prathamesh Gharat 2012-04-05 02:00


-1

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..

2014-05-28 09:48
by Neeraj
Ads