Plugin Directory

Changeset 1485935


Ignore:
Timestamp:
08/29/2016 09:14:23 PM (10 years ago)
Author:
harshit_ps
Message:

release 2.0.2

Location:
custom-add-user/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • custom-add-user/trunk/README.txt

    r1444394 r1485935  
    55Tags: custom, user, new, existing, add, promote, single, form, skip, invitation, shibboleth, ldap, activate, invite, expire, multisite, admin
    66Requires at least: 3.0.1
    7 Tested up to: 4.5.3
    8 Stable tag: 2.0.1
     7Tested up to: 4.6
     8Stable tag: 2.0.2
    99License: GPLv3 or later
    1010License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    7171
    7272== Changelog ==
     73
     74= 2.0.2 =
     75* Fix - Adding an existing user should not throw out the errror "Sorry, username already exists."
     76
    7377= 2.0.1 =
    7478* Bug fixes
     
    112116
    113117== Upgrade Notice ==
     118
    114119= 2.0.0 =
    115120* A lot has changed. Please check the changelog.
  • custom-add-user/trunk/custom-add-user.php

    r1443942 r1485935  
    1515 * Author URI:        http://sanghviharshit.com
    1616 * License: GPL3
    17  * Version: 2.0.1
     17 * Version: 2.0.2
    1818 */
    1919
     
    214214            /* Check if user already exists in the network */
    215215            $user_details = null;
    216             $user_email = wp_unslash( $_REQUEST['email'] );
    217             if ( false !== strpos( $user_email, '@' ) ) {
    218                 $user_details = get_user_by( 'email', $user_email );
    219             } else {
    220                 if ( is_super_admin() ) {
    221                     $user_details = get_user_by( 'login', $user_email );
    222                 } else {
    223                     wp_redirect( add_query_arg( array('update' => 'enter_email'), 'user-new.php' ) );
    224                     die();
    225                 }
    226             }
    227 
     216           
     217            /* Find user by user_login instead of email */
     218            $user_login = wp_unslash( $_REQUEST['user_login'] );
     219            //$user_email = wp_unslash( $_REQUEST['email'] );
     220            $user_details = get_user_by( 'login', $user_login );
     221           
    228222            if ( !$user_details ) {
     223                if ( ! current_user_can( 'create_users' ) ) {
     224                    wp_die(
     225                        '<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
     226                        '<p>' . __( 'Sorry, you are not allowed to create users.' ) . '</p>',
     227                        403
     228                    );
     229                }
    229230                // Adding a new user to this site
    230231                $new_user_email = wp_unslash( $_REQUEST['email'] );
     
    241242                    wpmu_signup_user( $new_user_login, $new_user_email, array( 'add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST[ 'role' ] ) );
    242243                    $key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $new_user_login, $_REQUEST[ 'email' ] ) );
    243                     wpmu_activate_signup( $key );
    244                     $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' );
    245                     wp_redirect( $redirect );
     244                    $new_user = wpmu_activate_signup( $key );
     245                    if ( is_wp_error( $new_user ) ) {
     246                        $redirect = add_query_arg( array( 'update' => 'addnoconfirmation' ), 'user-new.php' );
     247                    } else {
     248                        $redirect = add_query_arg( array( 'update' => 'addnoconfirmation', 'user_id' => $new_user['user_id'] ), 'user-new.php' );
     249                    }
     250                    wp_redirect( $redirect );
    246251                    die();
    247252                }
    248253            } else {
    249                 //Add existing user to the blog.
     254                if ( ! current_user_can( 'promote_user', $user_details->ID ) ) {
     255                    wp_die(
     256                        '<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
     257                        '<p>' . __( 'Sorry, you are not allowed to add users to this network.' ) . '</p>',
     258                        403
     259                    );
     260                }
     261                //Adding an existing user to this blog
    250262                $new_user_email = $user_details->user_email;
    251263                $redirect = 'user-new.php';
Note: See TracChangeset for help on using the changeset viewer.