Hi,
In the admin section you can view your own profile, but there are no links to view other people's profile. In essence when you click on their names you are editing their profile.
You can however view their account by going to [yoursite]wp-admin/profile.php?user_id=3 and that will show the profile of user 3.
I was wondering if it would be possible to add a custom link next to where the edit and delete are on the user.php page to say 'View Profile'.
Cheers,
Steve
John Cotton answers:
Something like this:
function view_user_profile( $actions, $user_object = null ) {
$actions['view'] = '<a class="submitdelete" href="#'.$user_object->ID.'">View Profile</a>';
return $actions;
}
add_filter( 'user_row_actions', 'view_user_profile', 10, 2 );
Change the # to whatever you want the link to be....
John Cotton comments:
<blockquote>/home/cordoval/sites-2/wp/wp-admin/includes/class-wp-users-list-table.php
just add on line 248 this</blockquote>
You should never be changing the core files....
Firstly you'll lose your changes as soon as you upgrade (and you ALWAYS want to upgrade.
Secondly, it becomes very difficult to manage changes.
Stick to the rules and you'll find that WordPress will always play nicely :)
Steven Jones comments:
John, the link didn't work correctly in the function you sent. Kailey below has now sent me the correct answer.
John Cotton comments:
<blockquote>However this will only appear if you are editing your own account, not if you go to edit someone elses. Therefore I need to be able to 'View' their account.</blockquote>
Why doesn't it appear if viewing someone elses?
Surely, you're using the $profile argument from the show_user_profile action and so $profile->ID gives you the currently displayed user.
Anyway, profile.php is just a wrapper for user-edit.php....
John Cotton comments:
<blockquote> the link didn't work correctly in the function you sent. </blockquote>
You needed to edit to suit....see comment below the code.
Otherwise, they are the same answer :)
Steven Jones comments:
John - I think the user id wasn't getting populated in your solution. I'm not sure why but I'm new to plugin development and just needed a solution - Kailey provided me with something I could literally copy and paste and can now continue with my work.
Also, I think Luis may have copied your answer from you.
Kailey Lampert answers:
I'm curious why you would want to use 'profile.php' instead of 'user-edit.php'
'profile.php' is designed to be used by the current user - preventing them from changing their own role, and address them as "you" instead of "the user."
Kailey Lampert comments:
I would recommend agains modifying core files.
add_filter( 'user_row_actions', 'custom_user_link', 10, 2 );
function custom_user_link( $actions, $user_object ) {
$link = admin_url( 'profile.php?user_id=' . $user_object->id );
if (!empty($link))
$actions['user_profile'] = "<a href='$link'>View Scores</a>";
return $actions;
}
Steven Jones comments:
I'm adding some custom information for each user. So I'm adding
add_action('show_user_profile' , 'addTestScores');
However this will only appear if you are editing your own account, not if you go to edit someone elses. Therefore I need to be able to 'View' their account.
Kailey Lampert comments:
In that case, I'd add this instead
add_action('edit_user_profile' , 'addTestScores');
Steven Jones comments:
Kailey,
Thanks for both of your solutions. Sometimes the obvious one is the best, although I may pick your original answer depending on what the client wants!
Thanks for your help.
Luis Cordova answers:
I think is possible checking on that ...
Luis Cordova comments:
it will be a view link like when you look at posts that will insert the url http://wp.local/wp-admin/user-edit.php?user_id=2&wp_http_referer=%2Fwp-admin%2Fusers.php right?
for id 2 and so on
Luis Cordova comments:
notice this will be only for admin right? just doublechecking
Steven Jones comments:
Luis,
What you have posted is the link to the edit profile screen which is already there in user.php.
I want a link called 'View Scores' and for it to link to http://wp.local/wp-admin/profile.php?user_id=3 (obviously the 3 will be whatever profile it is).
Yes, this is only for admin.
Luis Cordova comments:
oh ok yes i got all now, I am working on it
Luis Cordova comments:
almost done
Luis Cordova comments:
so on
/home/cordoval/sites-2/wp/wp-admin/includes/class-wp-users-list-table.php
just add on line 248 this
$actions['view'] = '<a class="submitdelete" href="#'.$user_object->ID.'">View Profile</a>';
or you can do like John Cotton, but working on a more accurate way hold it
Luis Cordova comments:
so this is the line
$actions['view'] = '<a href="/wp-admin/profile.php?user_id=' . $user_object->ID . '" title="' . esc_attr( sprintf( __( 'View “%s”' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
Steven Jones comments:
Luis - I do not want to edit the core files of WordPress.
Luis Cordova comments:
yes i know that, I am working on that so i just had to get the line right, now I will get into the functions.php
Luis Cordova comments:
function view_user_profile( $actions, $user_object = null ) {
$actions['view'] = '<a href="/wp-admin/profile.php?user_id=' . $user_object->ID . '" title="' . esc_attr( sprintf( __( 'View “%s”' ), $title ) ) . '" rel="permalink">' . __( 'View Scores' ) . '</a>';
return $actions;
}
add_filter( 'user_row_actions', 'view_user_profile', 10, 2 );