The MU forums have moved to WordPress.org

Multiple blogs same users as authors only (15 posts)

  1. dixyantar
    Member
    Posted 18 years ago #

    I want a site with many blogs which only I can create.
    I want that when someone registers in my site, he should be added as a author to all the blogs i.e he can only write posts, give comments and edit his posts.

    Can anyone point me in the right direction as to how I can achieve this. I am new to wordpress but I have achieved the same thing in "nucleus".

  2. dsader
    Member
    Posted 18 years ago #

    1) SiteAdmin-->Options registration Disabled by default, allow users -no blogs, duh.
    2) Now, from wpmu-includes/wpmu-functions.php, the needles in that haystack are:

    get_blogs_of_user($user_id);

    then

    add_user_to_blog( $blog_id, $user_id, $role );

    when hooked onto this action

    do_action( 'wpmu_new_user', $user_id );

    Plugin API

    3) Drop your new plugin into mu-plugins.

  3. dsader
    Member
    Posted 18 years ago #

    Of course you can add users manually at SiteAdmin-->Blogs-->Edit. But if you have many blogs . . . plugin.

  4. dixyantar
    Member
    Posted 18 years ago #

    Well i did not get you. I found the function get_blogs_of_user but what do I do so that the user registers and is added to all blog teams as an author. And is the registration site wide or only in that blog.

  5. dsader
    Member
    Posted 18 years ago #

    I'll try again, working backwards:

    First, you'll need to know how to write a plugin.(mu-plugins are not much different, except they fire 24/7 every page, no activation step required)

    The hook at signup for your request is 'wpmu_new_user', a line in your plugin, before your function starts, must be
    add_action('wpmu_new_user', 'my_new_plugin_function');

    Now in that new plugin file you'll need a
    function my_new_plugin_function($user_id) {

    Where betwixt the {} you figure out how to
    add_user_to_blog( $blog_id, $user_id, $role );

    after you

    get_blogs_of_user($user_id);

    where

    $user_id = your id#;
    $role = 'author';

    BTW user signup is sitewide.

  6. dixyantar
    Member
    Posted 18 years ago #

    Ok lemme explain what I have understood.

    1> In the plugin that I will create, i will write a function which first gets all the blogs which I own by
    get_blogs_of_user(my id)

    2> After that I will add the new user to my blogs by
    add_user_to_blog($blogid, $userid , 'author')

    I think i am right .. please do confirm and also mention how can I get my own id.

    here is what i could do

    <?php
    add_action('wpmu_new_user', 'reg_user_as_author');

    function reg_user_as_author($user_id){
    get_blogs_of_user(1);
    add_user_to_blog( $blog_id, $user_id, 'author' );}
    ?>

    provided my id is 1

  7. dixyantar
    Member
    Posted 18 years ago #

    or may be it is this:

    <?php
    add_action('wpmu_new_user', 'reg_user_as_author');

    function reg_user_as_author($user_id){
    $all_of_my_blogs = get_blogs_of_user(1);
    add_user_to_blog( $all_of_my_blogs, $user_id, 'author' );}
    ?>

    provided my id is 1

  8. MrBrian
    Member
    Posted 18 years ago #

    This should add the user to all the admin's blogs.

    <?php
    add_action('wpmu_new_user', 'reg_user_as_author');
    
    function reg_user_as_author($user_id){
    $blog_array = get_blogs_of_user(1);
    foreach($blog_array as $admin_blog){
    add_user_to_blog( $admin_blog->userblog_id, $user_id, 'author' );
    }
    }
    ?>
  9. dsader
    Member
    Posted 18 years ago #

  10. MrBrian
    Member
    Posted 18 years ago #

    Hehe, well I was thinking he was close anyway. He tried more than most of the knuckleheads on here.

  11. dixyantar
    Member
    Posted 18 years ago #

    That was funny and u have a real sense of humour ->dsader.
    Well I was just gonna go for the foreach loop. I was trying.

    And MrBrian thanks a lot for feeding me for a day. (sarcasm not meant !).
    Seriously You guys are really cool. I am gonna learn wordpress completely one day and I am gonna distribute fishing rods for free.

    Well uh sorry... Mrbrian is my id really "1" or is the admin's id by default "1".

  12. dsader
    Member
    Posted 18 years ago #

    This worm must have wriggled off the hook:

    SiteAdmin-->Users

    See the column ID?

  13. cafespain
    Member
    Posted 18 years ago #

    betwixt - strange how a single word can bring flooding back memories of long repressed English lessons.

  14. boonika
    Member
    Posted 18 years ago #

    favorite topic:)

  15. dsader
    Member
    Posted 18 years ago #

    cafespain, you'll need Dr Eliza for the repressed memories.

About this Topic

  • Started 18 years ago by dixyantar
  • Latest reply from dsader