From 7b49ad8493b527a297e3725cfc7e73087eed8718 Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 30 Jul 2012 18:30:03 +0000 Subject: [PATCH] Introduce get_edit_user_link(). Props scribu, georgestephanis, johnbillion. fixes #14787 see #20307 git-svn-id: http://core.svn.wordpress.org/trunk@21364 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../includes/class-wp-ms-users-list-table.php | 6 +--- .../includes/class-wp-users-list-table.php | 7 +---- wp-admin/includes/dashboard.php | 2 +- wp-admin/includes/user.php | 2 +- wp-admin/user-edit.php | 2 +- wp-includes/comment-template.php | 2 +- wp-includes/link-template.php | 28 +++++++++++++++++++ wp-includes/theme-compat/comments-popup.php | 2 +- wp-includes/theme-compat/comments.php | 2 +- wp-login.php | 2 +- 10 files changed, 37 insertions(+), 18 deletions(-) diff --git a/wp-admin/includes/class-wp-ms-users-list-table.php b/wp-admin/includes/class-wp-ms-users-list-table.php index fd71a0a494..6a4268f6ae 100644 --- a/wp-admin/includes/class-wp-ms-users-list-table.php +++ b/wp-admin/includes/class-wp-ms-users-list-table.php @@ -173,11 +173,7 @@ class WP_MS_Users_List_Table extends WP_List_Table { case 'username': $avatar = get_avatar( $user->user_email, 32 ); - if ( get_current_user_id() == $user->ID ) { - $edit_link = esc_url( network_admin_url( 'profile.php' ) ); - } else { - $edit_link = esc_url( network_admin_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), 'user-edit.php?user_id=' . $user->ID ) ) ); - } + $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) ); echo ""; ?> user_login ); ?>ID ) { - $edit_link = 'profile.php'; - } else { - $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), "user-edit.php?user_id=$user_object->ID" ) ); - } + $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user_object->ID ) ) ); // Set up the hover actions for this user $actions = array(); diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php index 3f72398326..98c8318c31 100644 --- a/wp-admin/includes/dashboard.php +++ b/wp-admin/includes/dashboard.php @@ -1263,7 +1263,7 @@ function wp_welcome_panel() {
  • Choose your privacy setting' ), esc_url( admin_url('options-privacy.php') ) ); ?>
  • Select your tagline and time zone' ), esc_url( admin_url('options-general.php') ) ); ?>
  • Turn comments on or off' ), esc_url( admin_url('options-discussion.php') ) ); ?>
  • -
  • Fill in your profile' ), esc_url( admin_url('profile.php') ) ); ?>
  • +
  • Fill in your profile' ), esc_url( get_edit_profile_url( get_current_user_id() ) ) ); ?>
  • diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php index 3c93a69a23..55f0df2c6c 100644 --- a/wp-admin/includes/user.php +++ b/wp-admin/includes/user.php @@ -353,7 +353,7 @@ function default_password_nag() { echo '' . __('Notice:') . ' '; _e('You’re using the auto-generated password for your account. Would you like to change it to something easier to remember?'); echo '

    '; - printf( '' . __('Yes, take me to my profile page') . ' | ', admin_url('profile.php') . '#password' ); + printf( '' . __('Yes, take me to my profile page') . ' | ', get_edit_profile_url( get_current_user_id() ) . '#password' ); printf( '' . __('No thanks, do not remind me again') . '', '?default_password_nag=0' ); echo '

    '; } diff --git a/wp-admin/user-edit.php b/wp-admin/user-edit.php index 8db92cdb2e..1a0a9f767c 100644 --- a/wp-admin/user-edit.php +++ b/wp-admin/user-edit.php @@ -139,7 +139,7 @@ if ( !is_multisite() ) { } if ( !is_wp_error( $errors ) ) { - $redirect = (IS_PROFILE_PAGE ? "profile.php?" : "user-edit.php?user_id=$user_id&"). "updated=true"; + $redirect = add_query_arg( 'updated', true, get_edit_user_link( $user_id ) ); if ( $wp_http_referer ) $redirect = add_query_arg('wp_http_referer', urlencode($wp_http_referer), $redirect); wp_redirect($redirect); diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index 1b3032fb04..c6f8c455a7 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -1537,7 +1537,7 @@ function comment_form( $args = array(), $post_id = null ) { 'fields' => apply_filters( 'comment_form_default_fields', $fields ), 'comment_field' => '

    ', 'must_log_in' => '', - 'logged_in_as' => '

    ' . sprintf( __( 'Logged in as %2$s. Log out?' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '

    ', + 'logged_in_as' => '

    ' . sprintf( __( 'Logged in as %2$s. Log out?' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '

    ', 'comment_notes_before' => '

    ' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '

    ', 'comment_notes_after' => '

    ' . sprintf( __( 'You may use these HTML tags and attributes: %s' ), ' ' . allowed_tags() . '' ) . '

    ', 'id_form' => 'commentform', diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index 31bacca422..bdda370b28 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -1056,6 +1056,34 @@ function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after; } +/** + * Retrieve edit user link + * + * @since 3.5.0 + * + * @param int $user_id Optional. User ID. Defaults to the current user. + * @return string URL to edit user page or empty string. + */ +function get_edit_user_link( $user_id = null ) { + if ( ! $user_id ) + $user_id = get_current_user_id(); + + if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) ) + return ''; + + $user = new WP_User( $user_id ); + + if ( ! $user->exists() ) + return ''; + + if ( get_current_user_id() == $user->ID ) + $link = get_edit_profile_url( $user->ID ); + else + $link = add_query_arg( 'user_id', $user->ID, self_admin_url( 'user-edit.php' ) ); + + return apply_filters( 'get_edit_user_link', $link, $user->ID ); +} + // Navigation links /** diff --git a/wp-includes/theme-compat/comments-popup.php b/wp-includes/theme-compat/comments-popup.php index de4c1e9e71..79dccbef5b 100644 --- a/wp-includes/theme-compat/comments-popup.php +++ b/wp-includes/theme-compat/comments-popup.php @@ -68,7 +68,7 @@ if ( post_password_required($post) ) { // and it doesn't match the cookie
    -

    %2$s. Log out »'), get_option('siteurl') . '/wp-admin/profile.php', $user_identity, wp_logout_url(get_permalink())); ?>

    +

    %2$s. Log out »'), get_edit_user_link(), $user_identity, wp_logout_url(get_permalink())); ?>

    diff --git a/wp-includes/theme-compat/comments.php b/wp-includes/theme-compat/comments.php index 89a888c75d..75a85ed46e 100644 --- a/wp-includes/theme-compat/comments.php +++ b/wp-includes/theme-compat/comments.php @@ -69,7 +69,7 @@ _deprecated_file( sprintf( __( 'Theme without %1$s' ), basename(__FILE__) ), '3. -

    %2$s.'), get_option('siteurl') . '/wp-admin/profile.php', $user_identity); ?>

    +

    %2$s.'), get_edit_user_link(), $user_identity); ?>

    diff --git a/wp-login.php b/wp-login.php index a442679f4d..6b0bb1e1f1 100644 --- a/wp-login.php +++ b/wp-login.php @@ -626,7 +626,7 @@ default: elseif ( is_multisite() && !$user->has_cap('read') ) $redirect_to = get_dashboard_url( $user->ID ); elseif ( !$user->has_cap('edit_posts') ) - $redirect_to = admin_url('profile.php'); + $redirect_to = get_edit_user_link(); } wp_safe_redirect($redirect_to); exit();