The MU forums have moved to WordPress.org

Need help hacking WPMU (9 posts)

  1. zhaidarbek
    Member
    Posted 15 years ago #

    Good morning everyone! I need your help guys.
    We have a site which offers blogging engine as a feature. WPMU is installed on a separate domain (i.e. blog.domain.com). WPMU user must be created automatically when user is registered on our site (i.e. domain.com) and after logging in they can create a blog without going to blog.domain.com. To accomplish this i created following file and dropped on blog.domain.com.
    <?php
    if(isset($_REQUEST['function'])){
    $functionName = $_REQUEST['function'];
    $arguments = explode(",", $_REQUEST['args']);
    }

    /** Include the bootstrap for setting up WordPress environment */
    include('./wp-load.php');
    require_once( ABSPATH . WPINC . '/registration.php');

    require_once('FirePHPCore/FirePHP.class.php');
    $firephp = FirePHP::getInstance(true);

    if($functionName == "wpmu_create_blog"){
    $newdomain = $arguments[0].".".$current_site->domain;
    $blog_title = $arguments[1];
    $user_id = $arguments[2];
    $res = wpmu_create_blog($newdomain, $base, $blog_title, $user_id, array( "public" => 1 ), $current_site->id);
    $firephp->log($res);
    if ( is_wp_error($res) ) {
    $result["message"] = $res->get_error_messages();
    $result["status"] = false;
    } else {
    $blog_id = $res;
    $result["status"] = true;
    $result["blog_id"] = $blog_id;
    $result["blog_url"] = "http://".$newdomain.$base;
    add_user_to_blog( $blog_id, $user_id, 'author' );
    }
    $result = json_encode($result);
    } else if($functionName == "wpmu_create_user"){
    $res = wpmu_create_user(wp_specialchars( strtolower( $arguments[0] ) ), $arguments[1], wp_specialchars( $arguments[2] ) );
    if ( $res == false ) {
    $result["message"] = "Duplicated username or email address.";
    $result["status"] = false;
    } else {
    $result["status"] = true;
    $result["blog_user_id"] = $res;
    }
    $result = json_encode($result);
    } else {
    $result = json_encode(call_user_func_array($functionName, $arguments));
    }
    $firephp->log($result);

    echo $result;
    ?>

    And it works fine. The problem is that when i create testuser and testblog and login to my WP dashboard i see two blogs: testblog which is located at testblog.blog.domain.com and the main blog which is located at blog.domain.com. Also testuser has 'Administrator' role on testblog. But ideally we should have:

    1. testuser must not see our main blog
    2. testuser must have 'Author' role on his own blog

    Is it possible without changing WPMU code? If so, what should i change in my code to implement above 2 rules.
    Thanks in advance!

  2. parkstreet
    Member
    Posted 15 years ago #

    So, you are saying that testuser can see the Site Admin tab on testblog.blog.domain.com?

  3. zhaidarbek
    Member
    Posted 15 years ago #

    No he doesn't, but he sees 2 blogs at My Blogs tab. Ideally he must see only his own blog.
    The main problem is that call to add_user_to_blog( $blog_id, $user_id, 'author' ); after wpmu_create_blog function keeps adding user to main blog as author and on his own blog he remains as administrator. Ideally he must be author on his own blog and no role at main blog.

  4. parkstreet
    Member
    Posted 15 years ago #

    Oh, now I understand. I am not that good of a coder, but I think you need a function of some kind that will pull POST of the current blog being registered, so that it doesn't add administrator capabilities to the main blog. I hope that makes since.

  5. delayedinsanity
    Member
    Posted 15 years ago #

    What about remove_user_from_blog?

    remove_user_from_blog($user_id, get_site_option('dashboard_blog'));

  6. zhaidarbek
    Member
    Posted 15 years ago #

    @parkstreet:
    Man, thanks for your help. I hate to bother you, but can you clarify your statement "...that will pull POST of the current blog being registered".
    Does it mean call get_blog_post function?

  7. zhaidarbek
    Member
    Posted 15 years ago #

    @delayedinsanity:
    I'll try it, thanks. As i stated above the main problem is that call to add_user_to_blog( $blog_id, $user_id, 'author' ); after wpmu_create_blog function keeps adding user to main blog as author, instead of his own blog, although i am sure that $blog_id is the id of newly created blog.
    Maybe tip suggested by parkstreet will help, i'll try it.

  8. parkstreet
    Member
    Posted 15 years ago #

    @zhaidarbek
    Actually, scratch what I said before. What information is being pulled or looked at when using $arguments[0]? You have it in both wpmu_create_blog and wpmu_create_user.

  9. zhaidarbek
    Member
    Posted 15 years ago #

    It depends, in case of wpmu_create_blog it's a blog name and in case of wpmu_create_user it is a user name.

About this Topic

  • Started 15 years ago by zhaidarbek
  • Latest reply from zhaidarbek