Code riddle

Hi guys,

Got a problem with assigning the correct user role for new users and keeping new users from getting user status on the main website.

Tried everything and finally found sollutions for both problems, only thing is that I have to choose which one because they don't play nice together.

These 2 are snippets of code, very much alike, which I have to put in a php and drop in mu-plugins.

Is there someone who can solve this riddle and merge them so I can have my way?

snippets

This one assignes the role of author to new users:

<?php
function ds_new_user_meta($blog_id, $user_id) {
add_user_to_blog( '1', $user_id, 'author' );
}
add_action( 'wpmu_new_blog', 'ds_new_user_meta', 10, 2 );
?>

and this one removes the user status for new accounts from the main website:

<?php

function ds_new_user_meta($blog_id, $user_id) {
remove_user_from_blog( $user_id, '1'); //removes new user from blog_id 1
}
add_action( 'wpmu_new_blog', 'ds_new_user_meta', 10, 2 );
?>

Help would be greatly appreciated!
Nick

  • aecnu
    • WP Unicorn

    Greetings Nick Happy New Year!

    Thank you for the great question and not being a coder I am once again subject to having to refer to the coding guru's and seek their input into this custom coding quandary.

    Though this may take a bit longer then a normal ticket, I will try to get one of them in here asap.

    Cheers, Joe

  • Nick vd Veerdonk
    • Site Builder, Child of Zeus

    (Joe: thanks!)

    Hi Cole,

    I'm making a diary for people to use online, through multisite people can sign up and have their own. When someone does they obviously receive a username to acces the new diary, lets say droomdagboek.net/username. When logged in, and visiting droomdagboek.net (the main page of the network), it turns out they can actually (through the admin bar) visit the superadmin administration site.

    In other words: on signing up they automaticly get user status for the main website as well!

    (Using the second snippet in mu-plugin this does not happen anymore, and get automaticly redirected to their own personal website.)

    Thanks for the quick reply!

  • Aaron
    • CTO

    Well your first snippet adds a user to the main blog as an author. The second completely removes them from the main blog. So they are obviously mutually exclusive. If you with the first one are trying to give them author access instead of admin access to their new blog, then it would need to be:
    `<?php
    function ds_new_user_meta($blog_id, $user_id) {
    add_user_to_blog($blog_id, $user_id, 'author' );
    }
    add_action( 'wpmu_new_blog', 'ds_new_user_meta', 10, 2 );
    ?>

  • Nick vd Veerdonk
    • Site Builder, Child of Zeus

    Aeron! thanks but I get the error message

    Fatal error: Cannot redeclare ds_new_user_meta() (previously declared in /home/touchingbodhi.com/public_html/wp-content/mu-plugins/newuser.php:2) in /home/touchingbodhi.com/public_html/wp-content/mu-plugins/newuserauthor.php on line 4 (bold for dramatic effect)

    Appreciate your help man!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.