The MU forums have moved to WordPress.org

wpmu_create_blog bug? (12 posts)

  1. Brad101
    Member
    Posted 16 years ago #

    I’m using the wpmu_create_blog function to creates blogs within a plug-in.

    However, as noted my Vimm ( http://mu.wordpress.org/forums/topic.php?id=5720&page&replies=6 ), the function doesn’t seem to work properly: it creates the first blog fine, but all subsequent blogs fail. Vimm’s comments: “The queries to create the new blog's tables are loaded into $wp_queries in upgrade-schema.php but it's loaded in-line, not via a function. This means it's only set once, so when you call wpmu_create_blog() a second time it still has the table values from the first time.”

    I’ve checked Vimm’s solution ( http://trac.mu.wordpress.org/ticket/394
    ), but I can’t follow it or it’s not compatible with the latest version of MU. Can anyone help please, as this is holding up a large project in our company.

    Many thanks.

  2. mqrasi
    Member
    Posted 16 years ago #

    Thank you. I thought i am the only one with this problem. I downloaded WP-Mu this evening and its now 5am and I am on the brink of killing myself.

    Someone please help !

  3. Brad101
    Member
    Posted 16 years ago #

    LOL! I'm not on the brink of killing myself...yet!

  4. mqrasi
    Member
    Posted 16 years ago #

    may be the problem is here :

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule . - [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    RewriteRule . index.php [L]

    in the .htaccess file ... but don't know how to fix it.

    --------------------

    So when a user signs up for a blog normally they should get

    http://www.mysite.com/blog/James

    But unfortunately the error in htaccess makes it be

    james.mysite.com/blog ... which is fatal :-(

  5. Brad101
    Member
    Posted 16 years ago #

    The wpmu_create_blog bug has nothing to do with the .htaccess file. It's related to the creation and implementation of blogs in core code.

  6. andrea_r
    Moderator
    Posted 16 years ago #

    mqrasi - the problem you're having could be you've chosen the wrong option on install.

    Brad, I'm not exactly sure, but there may be other functions to go along with the create_blog one that you'll need. Did you follow the code in wpmu-functions.php?

  7. Brad101
    Member
    Posted 16 years ago #

    Yep, followed the code. It works for the first blog, but does not for subsequent blogs, so it's definitely a bug.

    I'll try to get hold of Vimm.

  8. andrewbillits
    Member
    Posted 16 years ago #

    Just have the plugin create one blog per page load.

    There's a reason it only creates the first blog but I can't remember it at the moment.

    Thanks,
    Andrew

  9. Brad101
    Member
    Posted 16 years ago #

    Here's the code:

    $wpdb->hide_errors();
    		$blog_id = wpmu_create_blog($newdomain, $path, wp_specialchars( $blog['title'] ), $user_id ,'', $current_site->id);
    		$wpdb->show_errors();
    		if( !is_wp_error($blog_id) ) {
    			if( get_user_option( $user_id, 'primary_blog' ) == 1 )
    				update_user_option( $user_id, 'primary_blog', $blog_id, true );
    			$content_mail = sprintf(__("New blog created by %1s\n\nAddress: http://%2s\nName: %3s"), $current_user->user_login , $newdomain.$path, wp_specialchars($blog['title']) );
    			wp_mail( get_site_option('admin_email'),  sprintf(__('[%s] New Blog Created'), $current_site->site_name), $content_mail, 'From: "Site Admin" <' . get_site_option( 'admin_email' ) . '>' );
    			wp_redirect( add_query_arg( array('updated' => 'true', 'action' => 'add-blog'), $_SERVER['HTTP_REFERER'] ) );
    			exit();

    Something happens following the creation of a blog, but I can't pin it down.

  10. Brad101
    Member
    Posted 16 years ago #

    Any one with any ideas to solve this?

  11. Vimm
    Member
    Posted 16 years ago #

    I think the fix would still apply to WPMU 1.3, however that code in upgrade-schema.php was moved to /wp-admin/includes/schema.php and the functions make_db_current() and make_db_current_silent() were moved to /wp-admin/includes/upgrade.php so the changes would need to be made there.

    As I recall the core of the problem is that the code to generate the query string for a new blog is only run once, so when you call wpmu_create_blog() a second time it tries to create the same tables again, which of course doesn't work. By generating the string in a function and calling that function before creating a blog, the query gets updated each time so you can make as many blogs as you like.

    I've updated the ticket with a patch for WPMU 1.3, though I haven't tested it.

  12. Brad101
    Member
    Posted 16 years ago #

    Vimm,

    After following your solution, I'm close to solving this - many thanks!

    I've got it working by creating blogs via a plug-in user interface, HOWEVER, if I set up the plug-in to create blogs using a wp_schedule_event, it doesn't work????

    I think the problem may be related to some globals not being defined or required functions???? Can you help?

About this Topic