Forums

How to add users to WP database (outside of WP env) (4 posts)

  1. syt
    Member
    Posted 3 years ago #

    I’m running into an issue where I want to register new users into my WP from another page on my site (from another function outside of the WP environment), how do I go about doing that. Meaning I am integrating the WP Blog into my site and I want to be able to have people who register for my site automatically register for the WP Blog at the same time. I tried the following from one of my functions:

    //this is declared OUTSIDE of any function for global scope
    require BASEDIR .”/blog/wp-includes/wp-blog-header.php”;
    $NiceName = $fname . ” ” . $lname;
    $newMem = array(
    ‘user_login’ => $uname,
    ‘user_pass’ => $password,
    ‘user_nicename’ => $NiceName,
    ‘nickname’ => $NiceName,
    ‘first_name’ => $fname,
    ‘last_name’ => $lname,
    ‘display_name’ => $NiceName,
    ‘user_registered’ => date(”Y-m-d H:i:s”),
    ‘user_email’ => $email
    );
    wp_insert_user($newMem);

    But it seems to conflict with my database for my site is throwing errors when I make any db calls after wp-blog-header.php has been included:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sytablev/public_html/index.php on line 109

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/sytablev/public_html/includes/classes/my_queries.class.php on line 734

    Any ideas what I could do to get this to work? Thanks.

  2. titkblog2008
    Member
    Posted 3 years ago #

    Hi,

    I am new to wordpress.org and php. I wonder if you have figured a way to do what you wanted.

    I am also trying to run blog within a web site. I wonder if there is a plugin that I can use to add user to the blog db automatically after a user sign up on the web site.

    Any feedback will be helpful.

    Thanks

  3. aelle
    Member
    Posted 3 years ago #

    Hi Syt i don't konw if you have resolve but if you want add user delete this line BASEDIR .”/blog/wp-includes/wp-blog-header.php”; and replace it with:

    @require_once('../blog/wp-config.php');
    @require_once('../blog/wp-includes/pluggable.php');
    @require_once('../blog/wp-includes/registration.php');

    naturally replace the ../blog/ path with your path

    bye

  4. rramlani
    Member
    Posted 2 years ago #

    Hi! I want my zencart members to be automatically added to the blog db. I tried the code above in the tpl_membership_checkout.php in my custom template but it does not seem to be working. Any ideas??
    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags