WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/14/2010 02:02:19 AM (10 years ago)
Author:
wpmuguru
Message:

merge wp-admin user, plugins, themes, upgrade , See #11644

Location:
trunk/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin

    • Property svn:ignore set to
      .themes.php.swp
      .user-edit.php.swp
      .user-new.php.swp
      .users.php.swp
  • trunk/wp-admin/user-new.php

    r11369 r12722  
    1616require_once( ABSPATH . WPINC . '/registration.php');
    1717
     18if ( is_multisite() ) {
     19    function admin_created_user_email( $text ) {
     20        return sprintf( __( "Hi,
     21You've been invited to join '%s' at
     22%s as a %s.
     23If you do not want to join this blog please ignore
     24this email. This invitation will expire in a few days.
     25
     26Please click the following link to activate your user account:
     27%%s" ), get_bloginfo('name'), site_url(), wp_specialchars( $_REQUEST[ 'role' ] ) );
     28    }
     29    add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' );
     30
     31    function admin_created_user_subject( $text ) {
     32        return "[" . get_bloginfo('name') . "] Your blog invite";
     33    }
     34}
     35
    1836if ( isset($_REQUEST['action']) && 'adduser' == $_REQUEST['action'] ) {
    1937    check_admin_referer('add-user');
     
    2240        wp_die(__('You can’t create users.'));
    2341
    24     $user_id = add_user();
    25 
    26     if ( is_wp_error( $user_id ) ) {
    27         $add_user_errors = $user_id;
     42    if ( !is_multisite() ) {
     43        $user_id = add_user();
     44
     45        if ( is_wp_error( $user_id ) ) {
     46            $add_user_errors = $user_id;
     47        } else {
     48            $new_user_login = apply_filters('pre_user_login', sanitize_user(stripslashes($_REQUEST['user_login']), true));
     49            $redirect = 'users.php?usersearch='. urlencode($new_user_login) . '&update=add';
     50            wp_redirect( $redirect . '#user-' . $user_id );
     51            die();
     52        }
    2853    } else {
    29         $new_user_login = apply_filters('pre_user_login', sanitize_user(stripslashes($_REQUEST['user_login']), true));
    30         $redirect = 'users.php?usersearch='. urlencode($new_user_login) . '&update=add';
    31         wp_redirect( $redirect . '#user-' . $user_id );
    32         die();
     54        $user_login = preg_replace( "/\s+/", '', sanitize_user( $_REQUEST[ 'user_login' ], true ) );
     55        $user_details = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->users} WHERE user_login = %s AND user_email = %s", $user_login, $_REQUEST[ 'email' ] ) );
     56        if( $user_details ) {
     57            // Adding an existing user to this blog
     58            $new_user_email = wp_specialchars(trim($_REQUEST['email']));
     59            $redirect = 'user-new.php';
     60            $username = $user_details->user_login;
     61            $user_id = $user_details->ID;
     62            if( ($username != null && is_site_admin( $username ) == false ) && ( array_key_exists($blog_id, get_blogs_of_user($user_id)) ) ) {
     63                $redirect = add_query_arg( array('update' => 'addexisting'), 'user-new.php' );
     64            } else {
     65                if ( isset( $_POST[ 'noconfirmation' ] ) && is_site_admin() ) {
     66                    add_existing_user_to_blog( array( 'user_id' => $user_id, 'role' => $_REQUEST[ 'role' ] ) );
     67                    $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' );
     68                } else {
     69                    $newuser_key = substr( md5( $user_id ), 0, 5 );
     70                    add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) );
     71                    $message = __("Hi,\n\nYou have been invited to join '%s' at\n%s as a %s.\nPlease click the following link to confirm the invite:\n%s\n");
     72                    wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), get_option( 'blogname' ) ),  sprintf($message, get_option('blogname'), site_url(), $_REQUEST[ 'role' ], site_url("/newbloguser/$newuser_key/")));
     73                    $redirect = add_query_arg( array('update' => 'add'), 'user-new.php' );
     74                }
     75            }
     76            wp_redirect( $redirect );
     77            die();
     78        } else {
     79            // Adding a new user to this blog
     80            $user_details = wpmu_validate_user_signup( $_REQUEST[ 'user_login' ], $_REQUEST[ 'email' ] );
     81            unset( $user_details[ 'errors' ]->errors[ 'user_email_used' ] );
     82            if ( is_wp_error( $user_details[ 'errors' ] ) && !empty( $user_details[ 'errors' ]->errors ) ) {
     83                $add_user_errors = $user_details[ 'errors' ];
     84            } else {
     85                $new_user_login = apply_filters('pre_user_login', sanitize_user(stripslashes($_REQUEST['user_login']), true));
     86                if ( isset( $_POST[ 'noconfirmation' ] ) && is_site_admin() ) {
     87                    add_filter( 'wpmu_signup_user_notification', create_function('', '{return false;}') ); // Disable confirmation email
     88                }
     89                wpmu_signup_user( $new_user_login, $_REQUEST[ 'email' ], array( 'add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST[ 'role' ] ) );
     90                if ( isset( $_POST[ 'noconfirmation' ] ) && is_site_admin() ) {
     91                    $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' ] ) );
     92                    wpmu_activate_signup( $key );
     93                    $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' );
     94                } else {
     95                    $redirect = add_query_arg( array('update' => 'newuserconfimation'), 'user-new.php' );
     96                }
     97                wp_redirect( $redirect );
     98                die();
     99            }
     100        }
    33101    }
    34102}
     
    43111require_once ('admin-header.php');
    44112
     113if ( is_multisite() ) {
     114    switch( $_GET[ 'update' ] ) {
     115        case "newuserconfimation":
     116            $messages[] = '<div id="message" class="updated fade"><p>' . __('Invitation email sent to new user. A confirmation link must be clicked before their account is created.') . '</p></div>';
     117            break;
     118        case "add":
     119            $messages[] = '<div id="message" class="updated fade"><p>' . __('Invitation email sent to user. A confirmation link must be clicked for them to be added to your blog.') . '</p></div>';
     120            break;
     121        case "addnoconfirmation":
     122            $messages[] = '<div id="message" class="updated fade"><p>' . __('User has been added to your blog.') . '</p></div>';
     123            break;
     124        case "addexisting":
     125            $messages[] = '<div id="message" class="updated fade"><p>' . __('That user is already a member of this blog.') . '</p></div>';
     126            break;
     127    }
     128}
    45129?>
    46130<div class="wrap">
     
    75159
    76160<?php
     161if ( !is_multisite() ) {
    77162    if ( get_option('users_can_register') )
    78163        echo '<p>' . sprintf(__('Users can <a href="%1$s">register themselves</a> or you can manually create users here.'), site_url('wp-register.php')) . '</p>';
    79164    else
    80165        echo '<p>' . sprintf(__('Users cannot currently <a href="%1$s">register themselves</a>, but you can manually create users here.'), admin_url('options-general.php#users_can_register')) . '</p>';
     166} else {
     167    echo '<p>' . __( 'You can add new users to your blog in two ways:' ) . '<ol><li> ' . __( 'Enter the username and email address of an existing user on this site.' ) . '</li><li> ' . __( 'Enter the username and the email address of a person who is not already a member of this site. Choose the username carefully, it cannot be changed.' ) . '</li></ol></p>';
     168    echo '<p>' . __( 'That person will be sent an email asking them to click a link confirming the invite. New users will then be sent an email with a randomly generated password and a login link.' ) . '</p>';
     169}
    81170?>
    82171<form action="#add-new-user" method="post" name="adduser" id="adduser" class="add:users: validate">
     
    93182?>
    94183<table class="form-table">
     184<?php if ( !is_multisite() ) { ?>
    95185    <tr class="form-field form-required">
    96186        <th scope="row"><label for="user_login"><?php _e('Username'); ?> <span class="description"><?php _e('(required)'); ?></span></label>
     
    131221    </tr>
    132222<?php endif; ?>
    133 
     223<?php } else { // multisite ?>
     224    <tr class="form-field form-required">
     225        <th scope="row"><label for="user_login"><?php _e('Username (required)') ?></label><input name="action" type="hidden" id="action" value="adduser" /></th>
     226        <td ><input name="user_login" type="text" id="user_login" value="<?php echo $new_user_login; ?>" aria-required="true" /></td>
     227    </tr>
     228    <tr class="form-field form-required">
     229        <th scope="row"><label for="email"><?php _e('E-mail (required)') ?></label></th>
     230        <td><input name="email" type="text" id="email" value="<?php echo $new_user_email; ?>" /></td>
     231    </tr>
     232<?php } ?>
    134233    <tr class="form-field">
    135234        <th scope="row"><label for="role"><?php _e('Role'); ?></label></th>
     
    143242        </td>
    144243    </tr>
     244
     245    <?php if ( is_multisite() && is_super_admin() ) { ?>
     246    <tr class="form-field">
     247        <th scope="row"><label for="noconfirmation"><?php _e('Skip Confirmation Email') ?></label></th>
     248        <td><input name="noconfirmation" type="checkbox" id="noconfirmation" value="1" /> <label for="noconfirmation"><?php _e( 'Site administrators can add a user without sending the confirmation email.' ); ?></label></td>
     249    </tr>
     250    <?php } ?>
    145251</table>
    146252<p class="submit">
Note: See TracChangeset for help on using the changeset viewer.