Support » Plugin: User Groups » [patch] Multi-site delete

  • mortydot

    (@mortydot)


    Hi there,

    I’ve recently encountered a problem with the user-groups plugin. Relations between the user and the user-groups weren’t deleted if the plugin is running on a multi-site installation. I’ve developed a patch to fix this problem (see below). Please consider adding this patch to improve the experience for multi-site users.

    --- user-groups.svn.php	2013-12-05 14:25:33.000000000 -0100
    +++ user-groups.php	2013-12-05 14:31:53.000000000 -0100
    @@ -18,6 +18,8 @@
    
     	function KWS_User_Groups() {
    
    +		add_submenu_page(null, '',  '', 'manage_options',  'fixUserGroupsMultiSite', array($this, 'fixUserGroupsMultiSite'));
    +
     		add_filter('manage_users_columns', array(&$this, 'add_manage_users_columns'), 15, 1);
     		add_action('manage_users_custom_column', array(&$this, 'user_column_data'), 15, 3);
    
    @@ -55,11 +57,41 @@
     		add_action( 'edit_user_profile', array(&$this, 'edit_user_user_group_section'), 99999);
    
     		/* Cleanup stuff */
    +		add_action( 'remove_user_from_blog', array(&$this, 'delete_term_relationships'));
     		add_action( 'delete_user', array(&$this, 'delete_term_relationships'));
     		add_filter( 'sanitize_user', array(&$this, 'disable_username'));
    
     	}
    
    +	function fixUserGroupsMultiSite() {
    +		if(!class_exists('KWS_User_Groups')) {
    +			echo 'User Groups plugin not found, download it <a href="http://wordpress.org/extend/plugins/user-groups/">here</a>.';
    +		} else {
    +			echo '<div class="wrap"><h2>Fixing user groups</h2>' . PHP_EOL . '<pre><code>';
    +			echo 'starting the cleaning of user groups' . PHP_EOL;
    +			$blogs = get_blog_list(0, 'all');
    +			foreach($blogs as $blog) {
    +				echo 'switched to:' . $blog[ 'blog_id'] . '(' . $blog['domain'] . ')' . PHP_EOL;
    +				switch_to_blog($blog['blog_id']);
    +				$terms = get_terms( 'user-group', array( 'hide_empty' => false ) );
    +				foreach($terms as $term) {
    +					echo 'user group found: ' . $term->name . PHP_EOL;
    +					$objects = get_objects_in_term($term->term_id, 'user-group');
    +
    +					foreach($objects as $userid) {
    +						if (!is_user_member_of_blog($userid)) {
    +							echo 'user ' . $userid . ' is not a member of this blog!' . PHP_EOL;
    +							wp_delete_object_term_relationships($userid, 'user-group');
    +						}
    +					}
    +				}
    +			}
    +			echo 'ending the cleaning of user groups' . PHP_EOL;
    +			echo '</code></pre></div>' . PHP_EOL;
    +			restore_current_blog();
    +		}
    +	}
    +
     	function get_user_user_groups($user = '') {
     		if(is_object($user)) { $user_id = $user->ID; } elseif(is_int($user*1)) { $user_id = $user*1; }
     		if(empty($user)) { return false;}

    http://wordpress.org/plugins/user-groups/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘[patch] Multi-site delete’ is closed to new replies.