maybe_add_existing_user_to_blog

Add a new user to a blog by visiting /newbloguser/username/.

Description

maybe_add_existing_user_to_blog(); 

This will only work when the user's details are saved as an option keyed as new_user_x,, where x is the username of the user to be added, as when a user is invited through the regular WP Add User interface.


Usage

  1. if ( !function_exists( 'maybe_add_existing_user_to_blog' ) ) { 
  2. require_once ABSPATH . WPINC . '/ms-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = maybe_add_existing_user_to_blog(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/ms-functions.php  
  1. function maybe_add_existing_user_to_blog() { 
  2. if ( false === strpos( $_SERVER[ 'REQUEST_URI' ], '/newbloguser/' ) ) 
  3. return; 
  4.  
  5. $parts = explode( '/', $_SERVER[ 'REQUEST_URI' ] ); 
  6. $key = array_pop( $parts ); 
  7.  
  8. if ( $key == '' ) 
  9. $key = array_pop( $parts ); 
  10.  
  11. $details = get_option( 'new_user_' . $key ); 
  12. if ( !empty( $details ) ) 
  13. delete_option( 'new_user_' . $key ); 
  14.  
  15. if ( empty( $details ) || is_wp_error( add_existing_user_to_blog( $details ) ) ) 
  16. wp_die( sprintf(__('Anerroroccurred adding you to this site. Back to the <a href="%s">homepage</a>.'), home_url() ) ); 
  17.  
  18. wp_die( sprintf( __( 'You have been added to this site. Please visit the <a href="%s">homepage</a> or <a href="%s">log in</a> using your username and password.' ), home_url(), admin_url() ), __( 'WordPress › Success' ), array( 'response' => 200 ) );