Winner of the Best WordPress Business Website - WP Honors 2011
Since 2004
 

Forums

 

Manuals

 

Videos

 

Live Support

 

WPMU.org

Adding user to a blog doesn't add the blog to their profile

Elite

When I add a user in the "dashboard" blog to a different blog the blog doesn't show up on their blogs lists

wordpress.com/members/username/blogs

If I go to the backend of that specific blog and add them from there it adds the blog to their list as it should. does anyone know why this is?

Does this happen to anyone else?

Everyday at WPMU DEV we help hundreds of WP Users. Become a member today to:

  • Download 250+ Premium Plugins and Themes
  • Get unlimited support from WordPress Experts
  • Get help with your WordPress or BuddyPress projects

Help & Support from WPMU DEV members and staff

Elite

Hi maxaud,

Given the url it sounds like you're using BuddyPress, is that correct? Are you adding the user to the blog via Network Admin or Site Admin?

If it's through the Site Admin, that would only allow you to add them to the particular site you're on.

And if you're in Network Admin, could you let us know how you're adding them?

Thanks,
David

Elite

My steps for user creation where the blog doesn't get added to their profile:

Log in and go to "network" admin.
Go to the blogs menu and find the blog I want to add the user to, click on it.
Click on the users tab.
Add the user using the form at the bottom of the page.
Blog doesn't show up on their profile.

Now, the steps that work.

Log in and navigate to the regular admin page of that blog. "domain.com/subblog/wp-admin"
Go to the users page on the left hand side.
Click "add new."
Add the user there.
Blog shows up on their profile.

Get personal, comprehensive and timely support and assistance
from WordPress Experts

Elite

This looks similar to my problem.
http://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/no-blogs-shown-in-admin-bars-my-blogs-unless-re-activating-buddypress/

Elite

It looks like records are not being added to the wp_bp_user_blogs on some occasions.. I manual add the record here and it shows the blog on the users profile.

Staff

Hiya,

Just checking if it was eventually resolved in another thread? Or by yourself separately to us? Or by us over email with you? Or using our live support?

If so, no need to reply, that's great news.

If not, could you let us know by re-opening this topic, and we'll get onto it and helping you out asap!
Otherwise, happy days, glad you got it sorted :)

Thanks!

Elite

Here's the code I wrote to fix this issue for others to use:

It gets the current users blogs and compares them to the entries in the database under BuddyPress and adds entries if it needs to.

Copy this code, add it to a file in your mu-plugins directory and you're good to go.

<?php
/*
Plugin Name: Reconcile Blog Differences
Plugin URI: http://playforward.net
Description: Makes sure the blogs recorded under BuddyPress are the same as the ones that the user belongs to.
Author: Dustin Dempsey
Version: 1.0
Author URI: http://playforward.net
*/

function check_users_apps() {

		// grab current user and the wordpress database instance
		global $current_user,$wpdb;

		// assign user ID
		$user_id = $current_user->ID;

		// get the current blogs of the user
		$blogs = get_blogs_of_user( $user_id );

		// init blank array
		$current_blogs = array();

		// loop through suers blogs adding them to array
		foreach ( $blogs as $blog ) {
			$current_blogs[] = $blog->userblog_id;
		}

		// get the users current recorded blogs
		$query_string = "
			SELECT blog_id
			FROM " . $wpdb->base_prefix . "bp_user_blogs
			WHERE user_id = '" . $user_id . "'
			";

		$results = $wpdb->get_results( $query_string );

		// init new array
		$recorded_blogs = array();

		// loop through recorded blogs
		foreach ( $results as $apps ) {
			$recorded_blogs[] = intval( $apps->blog_id );
		}

		// what do we have left over?
		$result = array_diff( $current_blogs, $recorded_blogs );

		// for ever blog that wasn't recorded, loop through
		foreach ( $result as $new_record ) {

			$data = array(
				'user_id' => $user_id,
				'blog_id' => $new_record
				);

			$format = array(
				'%d',
				'%d'
				);

			// insert new database record
			$wpdb->insert( "koch_bp_user_blogs", $data, $format );
		}

	}
	add_action( 'bp_init', 'check_users_apps', 1 );
?>

Get personal, comprehensive and timely support and assistance
from WordPress Experts

Elite

Also, I have over a million users so bp_blogs_record_existing_blogs() function would have taken some time and computing resources to do.

Staff

Epic maxaud :)

Thanks for sharing your solution with us. I'm sure this will be valuable for others who come along with the same issue.

We can help you out. Become a member today to:

  • Let our team help you out today and access to over 250+ Premium Plugins and Themes
  • Find out why people saying "it's like having your own developer"
  • WPMU DEV - The WordPress Experts