WordPress.org

WordPress MU

Changeset 1852


Ignore:
Timestamp:
07/10/09 16:23:37 (5 years ago)
Author:
donncha
Message:

Site admin can add new users to blogs without confirmation email

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/user-new.php

    r1851 r1852  
    5050            $redirect = add_query_arg( array('update' => 'addexisting'), 'user-new.php' ); 
    5151        } else { 
    52             $newuser_key = substr( md5( $user_id ), 0, 5 ); 
    53             add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) ); 
    54             $message = __("Hi,\n\nYou have been invited to join '%s' at\n%s\nPlease click the following link to confirm the invite:\n%s\n"); 
    55             wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), get_option( 'blogname' ) ),  sprintf($message, get_option('blogname'), site_url(), site_url("/newbloguser/$newuser_key/"))); 
    56             $redirect = add_query_arg( array('update' => 'add'), 'user-new.php' ); 
     52            if ( false == isset( $_POST[ 'noconfirmation' ] ) ) { 
     53                $newuser_key = substr( md5( $user_id ), 0, 5 ); 
     54                add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) ); 
     55                $message = __("Hi,\n\nYou have been invited to join '%s' at\n%s\nPlease click the following link to confirm the invite:\n%s\n"); 
     56                wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), get_option( 'blogname' ) ),  sprintf($message, get_option('blogname'), site_url(), site_url("/newbloguser/$newuser_key/"))); 
     57                $redirect = add_query_arg( array('update' => 'add'), 'user-new.php' ); 
     58            } else { 
     59                add_existing_user_to_blog( array( 'user_id' => $user_id, 'role' => $_REQUEST[ 'role' ] ) ); 
     60                $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' ); 
     61            } 
    5762        } 
    5863        wp_redirect( $redirect ); 
     
    6469            $add_user_errors = $user_details[ 'errors' ]; 
    6570        } else { 
    66             wpmu_signup_user( $_REQUEST[ 'user_login' ], $_REQUEST[ 'email' ], array( 'add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST[ 'role' ] ) ); 
    6771            $new_user_login = apply_filters('pre_user_login', sanitize_user(stripslashes($_REQUEST['user_login']), true)); 
    68             $redirect = add_query_arg( array('update' => 'newuserconfimation'), 'user-new.php' ); 
     72            if ( isset( $_POST[ 'noconfirmation' ] ) ) { 
     73                add_filter( 'wpmu_signup_user_notification', create_function('', '{return false;}') ); // Disable confirmation email 
     74            } 
     75            wpmu_signup_user( $new_user_login, $_REQUEST[ 'email' ], array( 'add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST[ 'role' ] ) ); 
     76            if ( isset( $_POST[ 'noconfirmation' ] ) ) { 
     77                $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' ] ) ); 
     78                wpmu_activate_signup( $key ); 
     79                $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' ); 
     80            } else { 
     81                $redirect = add_query_arg( array('update' => 'newuserconfimation'), 'user-new.php' ); 
     82            } 
    6983            wp_redirect( $redirect ); 
    7084            die(); 
     
    88102    case "add": 
    89103        $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>'; 
     104        break; 
     105    case "addnoconfirmation": 
     106        $messages[] = '<div id="message" class="updated fade"><p>' . __('User has been added to your blog.') . '</p></div>'; 
    90107        break; 
    91108    case "addexisting": 
     
    161178        </td> 
    162179    </tr> 
     180    <?php if ( is_site_admin() ) { ?> 
     181    <tr class="form-field"> 
     182        <th scope="row"><label for="noconfirmation"><?php _e('Skip Confirmation Email') ?></label></th> 
     183        <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> 
     184    </tr> 
     185    <?php } ?> 
    163186</table> 
    164187<p class="submit"> 
  • trunk/wp-includes/wpmu-default-filters.php

    r1771 r1852  
    22// Users 
    33add_filter ( 'wpmu_validate_user_signup', 'signup_nonce_check' ); 
    4 add_action ( 'init', 'add_existing_user_to_blog' ); 
     4add_action ( 'init', 'maybe_add_existing_user_to_blog' ); 
    55add_filter ( 'xmlrpc_methods', 'attach_wpmu_xmlrpc' ); 
    66add_filter ( 'wp_authenticate_user', 'wordpressmu_authenticate_siteadmin', 10, 2 ); 
  • trunk/wp-includes/wpmu-functions.php

    r1847 r1852  
    19581958} 
    19591959 
    1960 function add_existing_user_to_blog() { 
    1961     if( false !== strpos( $_SERVER[ 'REQUEST_URI' ], '/newbloguser/' ) ) { 
    1962         $parts = explode( '/', $_SERVER[ 'REQUEST_URI' ] ); 
     1960function maybe_add_existing_user_to_blog() { 
     1961    if ( false === strpos( $_SERVER[ 'REQUEST_URI' ], '/newbloguser/' ) ) { 
     1962        return false; 
     1963    } 
     1964 
     1965    $parts = explode( '/', $_SERVER[ 'REQUEST_URI' ] ); 
     1966    $key = array_pop( $parts ); 
     1967    if ( $key == '' ) 
    19631968        $key = array_pop( $parts ); 
    1964         if( $key == '' ) 
    1965             $key = array_pop( $parts ); 
    1966         $details = get_option( "new_user_" . $key ); 
    1967         if( is_array( $details ) ) { 
    1968             add_user_to_blog( '', $details[ 'user_id' ], $details[ 'role' ] ); 
    1969             delete_option( 'new_user_' . $key ); 
    1970             do_action( "added_existing_user", $details[ 'user_id' ] ); 
    1971             wp_die( sprintf(__('You have been added to this blog. Please visit the <a href="%s">homepage</a> or <a href="%s">login</a> using your username and password.'), site_url(), site_url( '/wp-admin/' ) ) ); 
    1972         } 
     1969    $details = get_option( "new_user_" . $key ); 
     1970    add_existing_user_to_blog( $details ); 
     1971    delete_option( 'new_user_' . $key ); 
     1972    wp_die( sprintf(__('You have been added to this blog. Please visit the <a href="%s">homepage</a> or <a href="%s">login</a> using your username and password.'), site_url(), site_url( '/wp-admin/' ) ) ); 
     1973} 
     1974 
     1975function add_existing_user_to_blog( $details = false ) { 
     1976    if ( is_array( $details ) ) { 
     1977        add_user_to_blog( '', $details[ 'user_id' ], $details[ 'role' ] ); 
     1978        do_action( "added_existing_user", $details[ 'user_id' ] ); 
    19731979    } 
    19741980} 
Note: See TracChangeset for help on using the changeset viewer.