Created
March 8, 2017 07:31
-
-
Save mauriciogofas/8059ea03d9ade12c146c78d823cd147f to your computer and use it in GitHub Desktop.
Massive remove users from blog based on user meta data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* Massive remove users from blog | |
* remove_users_from_blog_based_userdata.php | |
* | |
*/ | |
// Load WP components, no themes | |
define('WP_USE_THEMES', false); | |
require('wp-load.php'); // root path | |
// Get users | |
$user_query = new WP_User_Query( array( 'exclude' => array( 1, 2603 ) ) ); // https://codex.wordpress.org/Class_Reference/WP_User_Query#Blog_Parameter | |
$all_users = $user_query->get_results(); | |
$stc_users = array(); | |
foreach ( $all_users as $user ) { | |
$stc_users[$user->ID] = array( | |
//'id' => $user->ID, | |
//'email' => $user->user_email, | |
//'source_domain' => get_userdata( $user->ID )->source_domain, // https://codex.wordpress.org/Function_Reference/get_userdata | |
//'primary_blog' => get_userdata( $user->ID )->primary_blog, | |
'user_blogs_count' => count(get_blogs_of_user( $user->ID )), // https://codex.wordpress.org/WPMU_Functions/get_blogs_of_user | |
//'user_blogs' => get_blogs_of_user( $user->ID ), | |
); | |
} | |
foreach ( $stc_users as $key => $value ) { | |
if ( $value['user_blogs_count'] > 1 ) { | |
echo $key.' - '.$value['user_blogs_count'].'<br>'; | |
remove_user_from_blog( $key, 381, $reassign ); // https://codex.wordpress.org/Function_Reference/remove_user_from_blog | |
} | |
} | |
// Debug echo '<pre style="height:250px;">'; print_r($stc_users); echo '<p>'.count($stc_users).' usuários.</p>'; echo '</pre>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment