I have a question about user authentication in my WordPress Multisite site.

My site is http://www.drezzy.it that has its own user db with a login and logout system. This is a non-WP website. When you login, it gives a cookie which include the email and the password of the user.

I created a WordPress Multisite website inside this one, http://www.drezzy.it/community/speciale/ that can have access to the cookie.

My questions are:

  1. How can I allow WordPress to log in users by using the main site's cookie, so that they don't have to register or log in again? A sort of bridge between the main site and WP that would enable to log in only once for all.

  2. How can I create a new user in WP for each user logged in the main website?

P.S. I'm sorry for my English, if you have some troubles with understand it, ask me, I will explain better! :D

1 Answer 1


Here is a quick function I had lying around that does exactly what your talking about. It uses some core WP functions to get the job done and you'll have to modify it to fit your needs, maybe double-check on the security of the thing but it should give you a head start.

function auto_function() {
    if ( isset( $_GET['username'] ) && isset( $_GET['email'] ) ){

        $user_name   = $_GET['username'];
        $user_email  = $_GET['email'];

        $user_id = username_exists( $user_name );
        if ( ! $user_id and email_exists( $user_email ) == false ) {
            $random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
            $user_id         = wp_create_user( $user_name, $random_password, $user_email );

            $creds = array();
            $creds['user_login'] = $user_name;
            $creds['user_password'] = $random_password;
            $creds['remember'] = true;
            $user = wp_signon( $creds, false );

            $meta_key = 'some_meta_key';
            $meta =& get_user_meta($user, $meta_key, true);
            $site_allowance = 3;

            add_user_meta( $user->id, $meta_key, $site_allowance , TRUE );

            #Redirect to help page
            wp_redirect( site_url('/user-profile/') ); exit;

        } else {
            $random_password = __('User already exists.  Password inherited.');
  • I only edited the question; @user3091886 asked it, initially. ;)
    – Pat J
    Commented Dec 11, 2013 at 19:51
  • Thanx Pat and Krzysiek for help my question to be more readable XD My english is so bad XD Commented Dec 12, 2013 at 8:12
  • Thanx for your answer Mountaininja, but can you explain me one thing? In the answer before where can I control the existence of the cookie? And how can I make his value be the user_email and password? The cookie doesn't give me the username but only the email and the password. I'm not a master in php, I'm a really beginner, but need to make this, so if you can tell me how to make a really complete function, you'll be my rescuer! In case of the name of the cookie is 'drezzy' how can I write the complete function? Thanx a lot! Commented Dec 12, 2013 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.