• Resolved justbishop

    (@justbishop)


    I’m trying to add a link to each user’s author archive from the back end user list, in the list of links that appear for each user when their row is moused over. Here’s the code I have so far:

    function frontend_profile_action_link($actions, $user_object) {
    
    	$actions['view profile'] = "<a class='view_frontend_profile' href='" . home_url( "/archives/author/" ) . get_the_author_meta( 'user_login' ) . "'>" . __( 'View Profile', 'frontend_profile' ) . "</a>";
    
    	return $actions;
    
    }
    
    add_filter('user_row_actions', 'frontend_profile_action_link', 11, 2);

    It works as far as displaying the link, but only to a point. It returns nothing after the “archives/author/” part of the URL, so every user’s “View Profile” link ends up being http://www.mysite.com/archives/author/ when it should be http://www.mysite.com/archives/author/user_login

    I’m not sure what I’m doing wrong. Is it my syntax in building the URL, or is get_the_author_meta not the function I need?

    TIA 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter justbishop

    (@justbishop)

    Sorry, maybe my wording was confusing? I’m calling the author archive page on the frontend (rendered by a customized author.php template file I’ve created) a frontend “profile”.

    In any case, can anyone tell me where I may have gone wrong in building the URL?

    Moderator bcworkz

    (@bcworkz)

    The user row actions occur outside of a post loop, so you need to provide the user ID to get_the_author_meta(). You can get it from $user_object.

    Thread Starter justbishop

    (@justbishop)

    Thanks so much! Small success, but I still need some guidance…I’ve got the following code working to spit the correct ID# for each user out into the URL, but I’m not sure how to translate that to the user’s login:

    $actions['view profile'] = "<a class='view_frontend_profile' href='" . home_url( "/archives/author/" ) .  $user_object->ID . "'>" . __( 'View Profile', 'frontend_profile' ) . "</a>";

    Thanks again for the help!

    Moderator bcworkz

    (@bcworkz)

    $user_object contains most user data, the login name is referenced by $user_object->user_login. I was originally suggesting that to use get_author_meta() properly, you should do this:
    get_the_author_meta( 'user_login', $user_object->ID )

    That would be silly :), I didn’t think that one through. Just use $user_object->user_login.

    Thread Starter justbishop

    (@justbishop)

    Ahhhh! Everything is awesome! Thank you 😀

    So for posterity’s sake, here’s the finished snippet to go in the theme’s functions.php:

    /* Add a 'View Profile' action link to user list */
    
    function frontend_profile_action_link($actions, $user_object) {
    	$actions['view profile'] = "<a class='view_frontend_profile' href='" . home_url( "/archives/author/" ) .  $user_object->user_login . "'>" . __( 'View Profile', 'frontend_profile' ) . "</a>";
    
    	return $actions;
    
    }
    
    add_filter('user_row_actions', 'frontend_profile_action_link', 10, 2);

    Yeah it is quite possbile by using this hook add_action('user_row_actions','your_function'), i have done it when i visit this site please check this post Add or edit custom link in wp users list in wordpress admin

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding Custom Action Link to Admin User List’ is closed to new replies.