Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




add_user_to_blog [ WordPress Function ]

add_user_to_blog ( $blog_id, $user_id, $role )
Parameters:
  • (int) $blog_id ID of the blog you're adding the user to.
  • (int) $user_id ID of the user you're adding.
  • (string) $role The role you want the user to have
Returns:
  • (bool)
Defined at:



Add a user to a blog.

Use the 'add_user_to_blog' action to fire an event when users are added to a blog.

Source


<?php
function add_user_to_blog$blog_id$user_id$role ) {
    
switch_to_blog($blog_id);

    
$user = new WP_User($user_id);

    if ( ! 
$user->exists() ) {
        
restore_current_blog();
        return new 
WP_Error('user_does_not_exist'__('That user does not exist.'));
    }

    if ( !
get_user_meta($user_id'primary_blog'true) ) {
        
update_user_meta($user_id'primary_blog'$blog_id);
        
$details get_blog_details($blog_id);
        
update_user_meta($user_id'source_domain'$details->domain);
    }

    
$user->set_role($role);

    
do_action('add_user_to_blog'$user_id$role$blog_id);
    
wp_cache_delete$user_id'users' );
    
restore_current_blog();
    return 
true;
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

Gebruikersdiscussies [ wordpress.org ]

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics