From b4ab399def21e9c4ecbbf1d66c9948491dd274b0 Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Wed, 24 Feb 2016 21:43:25 +0000 Subject: [PATCH] Multisite: Provide an "Edit user" link after adding a new user Props codex-m, jeremyfelt. Fixes #35705. Built from https://develop.svn.wordpress.org/trunk@36695 git-svn-id: http://core.svn.wordpress.org/trunk@36662 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/network/user-new.php | 19 ++++++++++++++++--- wp-admin/user-edit.php | 4 ++-- wp-admin/user-new.php | 24 ++++++++++++++++++++---- wp-includes/version.php | 2 +- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/wp-admin/network/user-new.php b/wp-admin/network/user-new.php index 62d5752caa..b86d4234d3 100644 --- a/wp-admin/network/user-new.php +++ b/wp-admin/network/user-new.php @@ -59,7 +59,7 @@ if ( isset($_REQUEST['action']) && 'add-user' == $_REQUEST['action'] ) { * @param int $user_id ID of the newly created user. */ do_action( 'network_user_new_created_user', $user_id ); - wp_redirect( add_query_arg( array('update' => 'added'), 'user-new.php' ) ); + wp_redirect( add_query_arg( array('update' => 'added', 'user_id' => $user_id ), 'user-new.php' ) ); exit; } } @@ -67,8 +67,21 @@ if ( isset($_REQUEST['action']) && 'add-user' == $_REQUEST['action'] ) { if ( isset($_GET['update']) ) { $messages = array(); - if ( 'added' == $_GET['update'] ) - $messages[] = __('User added.'); + if ( 'added' == $_GET['update'] ) { + $edit_link = ''; + if ( isset( $_GET['user_id'] ) ) { + $user_id_new = absint( $_GET['user_id'] ); + if ( $user_id_new ) { + $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user_id_new ) ) ); + } + } + + if ( empty( $edit_link ) ) { + $messages[] = __( 'User added.' ); + } else { + $messages[] = sprintf( __( 'User added. Edit User' ), $edit_link ); + } + } } $title = __('Add New User'); diff --git a/wp-admin/user-edit.php b/wp-admin/user-edit.php index bbf21f4510..3ecfe0a455 100644 --- a/wp-admin/user-edit.php +++ b/wp-admin/user-edit.php @@ -55,7 +55,7 @@ get_current_screen()->set_help_sidebar( '

' . __('Support Forums') . '

' ); -$wp_http_referer = remove_query_arg(array('update', 'delete_count'), $wp_http_referer ); +$wp_http_referer = remove_query_arg( array( 'update', 'delete_count', 'user_id' ), $wp_http_referer ); $user_can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ); @@ -179,7 +179,7 @@ include(ABSPATH . 'wp-admin/admin-header.php');

- +

diff --git a/wp-admin/user-new.php b/wp-admin/user-new.php index ff0bffb840..5400be255b 100644 --- a/wp-admin/user-new.php +++ b/wp-admin/user-new.php @@ -68,7 +68,7 @@ if ( isset($_REQUEST['action']) && 'adduser' == $_REQUEST['action'] ) { } else { if ( isset( $_POST[ 'noconfirmation' ] ) && current_user_can( 'manage_network_users' ) ) { add_existing_user_to_blog( array( 'user_id' => $user_id, 'role' => $_REQUEST[ 'role' ] ) ); - $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' ); + $redirect = add_query_arg( array( 'update' => 'addnoconfirmation' , 'user_id' => $user_id ), 'user-new.php' ); } else { $newuser_key = substr( md5( $user_id ), 0, 5 ); add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) ); @@ -147,8 +147,12 @@ Please click the following link to confirm the invite: wpmu_signup_user( $new_user_login, $new_user_email, array( 'add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST['role'] ) ); if ( isset( $_POST[ 'noconfirmation' ] ) && current_user_can( 'manage_network_users' ) ) { $key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $new_user_login, $new_user_email ) ); - wpmu_activate_signup( $key ); - $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' ); + $new_user = wpmu_activate_signup( $key ); + if ( ! is_wp_error( $new_user ) ) { + $redirect = add_query_arg( array( 'update' => 'addnoconfirmation' ), 'user-new.php' ); + } else { + $redirect = add_query_arg( array( 'update' => 'addnoconfirmation', 'user_id' => $new_user['user_id'] ), 'user-new.php' ); + } } else { $redirect = add_query_arg( array('update' => 'newuserconfirmation'), 'user-new.php' ); } @@ -223,6 +227,14 @@ require_once( ABSPATH . 'wp-admin/admin-header.php' ); if ( isset($_GET['update']) ) { $messages = array(); if ( is_multisite() ) { + $edit_link = ''; + if ( ( isset( $_GET['user_id'] ) ) ) { + $user_id_new = absint( $_GET['user_id'] ); + if ( $user_id_new ) { + $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user_id_new ) ) ); + } + } + switch ( $_GET['update'] ) { case "newuserconfirmation": $messages[] = __('Invitation email sent to new user. A confirmation link must be clicked before their account is created.'); @@ -231,7 +243,11 @@ if ( isset($_GET['update']) ) { $messages[] = __('Invitation email sent to user. A confirmation link must be clicked for them to be added to your site.'); break; case "addnoconfirmation": - $messages[] = __('User has been added to your site.'); + if ( empty( $edit_link ) ) { + $messages[] = __( 'User has been added to your site.' ); + } else { + $messages[] = sprintf( __( 'User has been added to your site. Edit User' ), $edit_link ); + } break; case "addexisting": $messages[] = __('That user is already a member of this site.'); diff --git a/wp-includes/version.php b/wp-includes/version.php index a856a2714a..16d23e257e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.5-alpha-36694'; +$wp_version = '4.5-alpha-36695'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.