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

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

Related posts

Leave a Reply

3 comments

  1. 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! 😀

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