Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding Users from Another Application


  • Vendetta
    Participant

    @vendetta66

    Hey All,

    I’m trying to figure out how to add users from another application, using the fields on my BP register form.

    Can somebody point me in the right direction please?

    Thanks.

    V

Viewing 18 replies - 1 through 18 (of 18 total)
  • What application are you coming from?

    And what direction would that be? What is the issue?

    You might to need to pad out your question with a little detail. What is the other application? Is the issue that the fields do not match between apps? Is it simply how to transfer a mass of users without having to manually enter each one?


    Vendetta
    Participant

    @vendetta66

    I’m adding users based on signup to my own application.

    For instance a new users signs up to my site, I then use curl posts to add them to additional pieces of software such as our support desk, mailing list, and in this case community.

    $fields_string = “”;
    $url = ‘http://community.mysite.com/no-idea-what-url-to-post-to.php’;
    $fields = array (‘signup_username’ => urlencode($username), ‘signup_email’ => urlencode($email), ‘signup_password’ => urlencode($password), ‘signup_password_confirm’ => urlencode($password), ‘field_1’ => urlencode($username), ‘signup_profile_field_ids’ => urlencode(1));
    foreach($fields as $key => $value) {
    $fields_string .= $key.’=’.$value.’&’;
    }
    rtrim ($fields_string, ‘&’);
    $ch = curl_init ();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_POST, count ($fields));
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $fields_string);
    $results = curl_exec ($ch);
    curl_close ($ch);

    If there’s a better way, please advise, everything is on the same server so I can include specific files to do a more API style function, just can’t seem to find any reference material that tells me what I need to know.

    I found a post on WordPress.org on using the

    wp_create_user ($username, $password, $email)

    function, but I can’t seem to find a way to implement it for an outside application.

    There really needs to be an external API.

    Anyway, appreciate the help :)

    V


    Vendetta
    Participant

    @vendetta66

    Uh …. anyone?

    Just need to know what url to post this script to … tried

    register/
    wp-register.php
    wp-login.php

    also the register page in the actual buddypress plugin, but no love there either.

    Thanks.


    techguy
    Participant

    @crashutah

    Wow. 30 minutes with no reply and you’re already bumping the thread?

    wp_create_user ($username, $password, $email) is the right direction. Take a look at the wp-fb-autoconnect to see the calls to create new users. Then, do a search for having the BP top bar appear on external sites. I’m not 100% sure, but it seems like the same way you can get the BP bar to appear on other pages you could tie into other WP functions like the wp_create_user () function. Basically requires you to include/require some WordPress files on your external page that’s making the calls. I can’t remember which.


    Vendetta
    Participant

    @vendetta66

    LOL, thanks man I appreciate it.

    V


    Vendetta
    Participant

    @vendetta66

    Yeah no love on that solution either.

    This is ridiculous.

    Where in the world to the registration form post to in BP?

    V


    r-a-y
    Keymaster

    @r-a-y

    I think techguy meant wp_insert_user:
    https://codex.wordpress.org/Function_Reference/wp_insert_user

    That should give you some good ideas.


    Vendetta
    Participant

    @vendetta66

    Yeah it would other than the fact that I can’t call those function from an external application.

    And including files from the wp installation doesn’t seem to work either.

    It seems that you’d be able to simply include the wp-header file:

    require_once (dirname (dirname (__FILE__)) . “/community/wp-blog-header.php”);

    and be able to access all the functions within the system, but apparently I’m missing something, because I keep getting invalid function errors.

    This is why I’m trying to use curl to simply post the few fields needed to sign people up.

    Pretty frustrating so far.

    Thanks

    V


    r-a-y
    Keymaster

    @r-a-y

    Have you double checked that you’re linking to the correct file path for wp-blog-header.php?


    Vendetta
    Participant

    @vendetta66

    Yes, the file path is correct.

    My application is in:

    /home/mysite/public_html/

    WP is in:

    /home/mysite/community/

    So yes this file path is correct.

    V


    r-a-y
    Keymaster

    @r-a-y

    Off-topic: Shouldn’t /community/ exist in the /public_html/ folder?
    Anyway… did you try using a simple WP function after integrating the wp-blog-header.php file like a query_posts loop?

    Read this for more info:
    https://codex.wordpress.org/Integrating_WordPress_with_Your_Website


    Vendetta
    Participant

    @vendetta66

    No, I set up subdomains in their own root folder parallel with the public_html folder.

    I’ll check that out, thanks Ray.

    V


    Vendetta
    Participant

    @vendetta66

    Yeah this is exactly what I was trying earlier.

    The only difference being that have no need to loop through anything, I need only call wp_create_user ()

    I haven’t tried it turning off the themes, I’ll give that a shot and see if it flies.

    Thanks for the reference.

    V


    Vendetta
    Participant

    @vendetta66

    This is where it dies:

    Fatal error: Call to undefined method stdClass::set_prefix() in /home/netics/community/wp-settings.php on line 287

    Which is:

    $prefix = $wpdb->set_prefix($table_prefix);

    V


    r-a-y
    Keymaster

    @r-a-y

    Put the wp-blog-header.php line at the top of your script.

    Also try posting on the WordPress forums, as this isn’t really a BP issue.

    eg. https://wordpress.org/support/topic/288455
    https://wordpress.org/support/topic/285890

    Run a Loop Outside of WordPress


    Vendetta
    Participant

    @vendetta66

    Yeah I discovered that I needed to move the include outside of my class and now I’ve gotten rid of that error.

    But now we can’t find the individual functions.

    Fatal error: Call to undefined function wp_create_user() in /home/netics/public_html/test.php on line 33

    Cool thanks for the links Ray.

    V


    Vendetta
    Participant

    @vendetta66

    Ok.

    For anyone else that may suffer this frustration.

    Make sure you include files outside any classes or functions you are calling the wp functions from.

    define(‘WP_USE_THEMES’, false);
    require_once (dirname (dirname (__FILE__)) . “/community/wp-blog-header.php”);
    require_once (dirname (dirname (__FILE__)) . “/community/wp-includes/registration.php”);

    Then inside your class method or function you can call the wp function you need to run ie:

    $userid = wp_create_user ($username, $password, $email);

    echo $userid;

    Thanks for everyone’s help.

    V

Viewing 18 replies - 1 through 18 (of 18 total)
  • The topic ‘Adding Users from Another Application’ is closed to new replies.
Skip to toolbar