remove_user_from_blog [ WordPress Function ]
remove_user_from_blog ( $user_id, $blog_id = '', $reassign = '' )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Soorgelijke functies: remove_query_arg, get_users_of_blog, add_user_to_blog, current_user_can_for_blog, remove_role
Remove a user from a blog.
Use the 'remove_user_from_blog' action to fire an event when users are removed from a blog.
Accepts an optional $reassign parameter, if you want to reassign the user's blog posts to another user upon removal.
Source
<?php
function remove_user_from_blog($user_id, $blog_id = '', $reassign = '') {
global $wpdb;
switch_to_blog($blog_id);
$user_id = (int) $user_id;
do_action('remove_user_from_blog', $user_id, $blog_id);
// If being removed from the primary blog, set a new primary if the user is assigned
// to multiple blogs.
$primary_blog = get_user_meta($user_id, 'primary_blog', true);
if ( $primary_blog == $blog_id ) {
$new_id = '';
$new_domain = '';
$blogs = get_blogs_of_user($user_id);
foreach ( (array) $blogs as $blog ) {
if ( $blog->userblog_id == $blog_id )
continue;
$new_id = $blog->userblog_id;
$new_domain = $blog->domain;
break;
}
update_user_meta($user_id, 'primary_blog', $new_id);
update_user_meta($user_id, 'source_domain', $new_domain);
}
// wp_revoke_user($user_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.'));
}
$user->remove_all_caps();
$blogs = get_blogs_of_user($user_id);
if ( count($blogs) == 0 ) {
update_user_meta($user_id, 'primary_blog', '');
update_user_meta($user_id, 'source_domain', '');
}
if ( $reassign != '' ) {
$reassign = (int) $reassign;
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $user_id) );
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign, $user_id) );
}
restore_current_blog();
return true;
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- WPMU Functions/remove user from blog « WordPress Codex
Description. Removes the specified user from the specified (or primary blog) and optionally reassigns their posts and other submissions to a new user.
codex.wordpress.org - #16444 (add_user_to_blog() and remove_user_from_blog() can ...
Both add_user_to_blog() and remove_user_from_blog() call switch_to_blog() first thing. On encountering an error, however, they can return before calling ...
core.trac.wordpress.org - MS Function - remove_user_from_blog returns null - WordPress Trac
Issue: remove_user_from_blog() returns false on success. I added a return true; to the above function. It would make sense that since add_user_to_blog returns ...
core.trac.wordpress.org - remove_user_from_blog (WordPress Function) - WPSeek.com
WordPress lookup for remove_user_from_blog, a WordPress Function. wpseek. com is a WordPress-centric search tool for developers and theme authors.
wpseek.com