The MU forums have moved to WordPress.org

User 1 (Admin) added to all blogs (26 posts)

  1. Xen
    Member
    Posted 17 years ago #

    Hey WPMU users,

    I spent hours trawling these forums for the ability to add myself (the default user) as admin on all blogs on the system, I know it's not neccesary because I have the power on all blogs but it's an added deterrent for possible spammers if the site admin is registered on their blog... It's also quite useful to keep track of all the blogs on the system by using

    <?php
    $blogs = get_blogs_of_user(X);
    if ( ! empty($blogs) ) foreach ( $blogs as $blog ) {
    echo "<li><a href='" . $blog->domain . $blog->path . "'>" . $blog->domain . $blog->path . "</a></li>";
    }
    ?>

    Where X is the user you want to show blogs for

    So I took it upon myself to make it so that when a new blog is created, it adds the admin user to that blog! and just after I did this I thought....

    Why not allow other people to do this?

    So here's how!

    OPEN:

    wp-includes/wpmu-functions.php

    FIND:

    function wpmu_create_blog($domain, $path, $title, $user_id, $meta = '', $site_id = 1) {
    $domain = addslashes( $domain );
    $title = addslashes( $title );
    $user_id = (int) $user_id;'

    Then, A little bit further down FIND:

    add_user_to_blog($blog_id, $user_id, 'administrator');

    after this line ADD:

    add_user_to_blog($blog_id, X, 'administrator');`

    where X is the userid of the user you wish to add, this can be repeated if you have multiple site admins ^_^

    Enjoy!

    Note that neither myself nor wordpress are responsible for the effects of this "hack". You utilise it at your own risk! By using this solution you agree to indemnify all parties against any legal action arising!

  2. andrewbillits
    Member
    Posted 17 years ago #

    I honestly doubt it will deter any spammers. :(

  3. Xen
    Member
    Posted 17 years ago #

    ^_^ it's quite useful still :-D

    The reason I did it was to be able to list all my blogs on the homepage

    Bloggi - Free Blogs, Simple Really

    The example is my site ^_^

  4. andrewbillits
    Member
    Posted 17 years ago #

    Nice work :)

    Quick question though. Since each user is the admin of their blog, isn't it possible for them to remove you (the admin) from their blog?

  5. drmike
    Member
    Posted 17 years ago #

    Was thinking that as well.... :)

  6. andrea_r
    Moderator
    Posted 17 years ago #

    Hmmm.. I've been needing something similar to this. Not to add the admin on signups, but I want the user automatically aded to a support blog. :)

    Care to puzzle that one out for me? :D

  7. Xen
    Member
    Posted 17 years ago #

    Ooooh
    It's gonna be the same file, but on user_add or something just make it add them into the blog....

    Lol

    I'll work on it, it sounds pretty cool :-p

    and I'll test for the "owner remove admin" thing :-p

  8. Xen
    Member
    Posted 17 years ago #

    Nope, the owner can't remove the "admin" user(s).

  9. Xen
    Member
    Posted 17 years ago #

    Just playing with the support blog option, it'd only work for users who register after the hack is done.

    Lol it's a lot harder than one would think...

  10. andrea_r
    Moderator
    Posted 17 years ago #

    AHA! Thanks for playing around with it - good to know.

  11. drmike
    Member
    Posted 17 years ago #

    To add a user to a support blog, I would think it would be:

    add_user_to_blog(x, $user_id, y);

    Where 'x' is the support blog's id and 'y' is the level you want them to be. (ie Figure that out and put it in there when you copy and paste.)

    For example:

    add_user_to_blog('16', $user_id, 'subscriber');

    I haven't tried it but I don't see any reason why it wouldn't.

  12. Xen
    Member
    Posted 17 years ago #

    *nods* that's the code alrighty lol it's just finding a function to put it with lol.

  13. drmike
    Member
    Posted 17 years ago #

    Hold on, they moved it on me. (I do something simular to add in links for the support forums and my sites.)

    wp_insert_user in /wp-includes/registration.php maybe?

  14. Xen
    Member
    Posted 17 years ago #

    I'll have a look, thanks dude ^_^

  15. Xen
    Member
    Posted 17 years ago #

    Okay We have it,

    Credit to DrMike for the placement of the new line!
    Credit to Andrea_R for the idea!

    OPEN:

    wp-includes/registration.php

    FIND:

    function wp_insert_user($userdata) {

    FURTHER DOWN, FIND:

    if ( $update )
    do_action('profile_update', $user_id);
    else
    do_action('user_register', $user_id);

    AFTER, ADD:

    add_user_to_blog('X', $user_id, 'XXroleXX');

    Where:

    X = The Blog ID you want to add the user to
    XXroleXX = The role for the user

  16. andrea_r
    Moderator
    Posted 17 years ago #

    High fives all around then. And cookies! :D

  17. Xen
    Member
    Posted 17 years ago #

    w00t cookies :-D

  18. drmike
    Member
    Posted 17 years ago #

    booo diet :(

  19. Xen
    Member
    Posted 17 years ago #

    *giggles* Haha sucks to be you

    <3 Metabolism ^_^

  20. drmike
    Member
    Posted 17 years ago #

    Actually got a dozen "homemade" chocolate chip cookies this morning. I helped out in the student center cleaning up after the incoming students had lunch as I was walking by and they gave me some.

    *YUM!* :)

  21. andrea_r
    Moderator
    Posted 17 years ago #

    Well, how 'bout some BBQ from the other thread? I make a killer macaroni salad with no mayo. ;)

  22. drmike
    Member
    Posted 17 years ago #

    Can't eat onions. It's on my restricted list due to my tyroid.

  23. andrea_r
    Moderator
    Posted 17 years ago #

    No onions either. (hubby can't eat 'em as well.) :D Man, we're turning this place into a party...

  24. akorelc
    Member
    Posted 17 years ago #

    I just found this, thanks for the idea! I just edited my registration.php file as per above, but will have to wait until another of my testers creates an account. So far, I haven't seen 'admin' as a user added to an existing account.

    "Regimen" is, IMHO, preferable to a word that begins with 'die' - LOL! :o)

  25. drmike
    Member
    Posted 17 years ago #

    Do remember though that as Admin (and any other account you assign to be as Site Admins, they do have access to all of the blogs in question)

  26. erinther
    Member
    Posted 17 years ago #

    hi,
    I have 5 blogs that i want all the users will be added to them, then I tried to add five lines of
    add_user_to_blog('X', $user_id, 'XXroleXX'); with different blog IDs, but only the last one works, that means users are added only to one blog( the last one). how is it posiible to do it for all 5 blogs?

About this Topic