Make WordPress Core


Ignore:
Timestamp:
07/30/2012 06:30:03 PM (12 years ago)
Author:
ryan
Message:

Introduce get_edit_user_link(). Props scribu, georgestephanis, johnbillion. fixes #14787 see #20307

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/link-template.php

    r21174 r21364  
    10571057}
    10581058
     1059/**
     1060 * Retrieve edit user link
     1061 *
     1062 * @since 3.5.0
     1063 *
     1064 * @param int $user_id Optional. User ID. Defaults to the current user.
     1065 * @return string URL to edit user page or empty string.
     1066 */
     1067function get_edit_user_link( $user_id = null ) {
     1068    if ( ! $user_id )
     1069        $user_id = get_current_user_id();
     1070
     1071    if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) )
     1072        return '';
     1073
     1074    $user = new WP_User( $user_id );
     1075
     1076    if ( ! $user->exists() )
     1077        return '';
     1078
     1079    if ( get_current_user_id() == $user->ID )
     1080        $link = get_edit_profile_url( $user->ID );
     1081    else
     1082        $link = add_query_arg( 'user_id', $user->ID, self_admin_url( 'user-edit.php' ) );
     1083
     1084    return apply_filters( 'get_edit_user_link', $link, $user->ID );
     1085}
     1086
    10591087// Navigation links
    10601088
Note: See TracChangeset for help on using the changeset viewer.