Results 1 to 1 of 1

Thread: Login/Register a user to Wordpress from External Website

  1. #1
    Join Date
    Oct 2007
    Location
    India
    Beans
    103
    Distro
    Ubuntu 12.04 Precise Pangolin

    Smile Login/Register a user to Wordpress from External Website

    PHP Code:
    <?php ob_start();

    require(
    $_SERVER['DOCUMENT_ROOT']."/index.php"); /* Include wordpress main index file,we get access to "all wp-function(not tested)" in our external file.*/

    define('WP_USE_THEMES'false); // Do not show themes

    header("HTTP/1.1 200 OK"); /* Sometimes error occurs,so to fix we set headers */


    $email 'someuser@somewhere.com'/* Get username or password from form */
        
    if (!email_exists($email))
    {
     echo 
    'That E-mail doesn\'t belong to any registered users on   this site,So registering....<br>';

    // Creating WP User
    wp_create_user'someuser''passme''someuser@somewhere.com'); 
    echo 
    'This email id is now registered thanks--->'.$email;
            
    }
    else
    {
     echo 
    "That E-mail id is already registered !! So, automatically signing in...";        

        
    $creds = array();
        
    $creds['user_login'] = 'someuser';
        
    $creds['user_password'] = 'passme';
        
    $creds['remember'] = true;

            
    // Sigining in a WP User
        
    $user wp_signon$credsfalse ); 

        if( 
    is_wp_error($user))
        {

          echo 
    'oops!! we got some error in sigining in '.$user->get_error_message();

        }
        else
        {
           echo 
    '<br>User is now logged in !!<br>';
       }        
    }
    ob_end_flush();
    ?>
    Last edited by lisati; August 6th, 2012 at 12:20 PM. Reason: Formatting

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •