Prathamesh Gharat
Prathamesh Gharat

Reputation: 514

Wordpress filter user_row_actions

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.

Upvotes: 2

Views: 4059

Answers (3)

Neeraj
Neeraj

Reputation: 43

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

Upvotes: -1

Prathamesh Gharat
Prathamesh Gharat

Reputation: 514

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

Upvotes: 4

Hobo
Hobo

Reputation: 7611

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

Upvotes: 1

Related Questions