WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Adding Custom Action Link to Admin User List (7 posts)

  1. justbishop
    Member
    Posted 3 months ago #

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

  2. justbishop
    Member
    Posted 3 months ago #

    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?

  3. bcworkz
    Member
    Posted 3 months ago #

    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.

  4. justbishop
    Member
    Posted 3 months ago #

    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!

  5. bcworkz
    Member
    Posted 3 months ago #

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

  6. justbishop
    Member
    Posted 3 months ago #

    Ahhhh! Everything is awesome! Thank you :D

    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);
  7. aceneeraj
    Member
    Posted 3 months ago #

    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

Reply

You must log in to post.

About this Topic

Tags

No tags yet.