• Resolved supernova42

    (@supernova42)


    [insert_php]
    /*
    Basically I want to transfer the username, email, first_name,
    last_name from WordPress to Participants Database. Rather than export CSV files from WordPress and import them into Participants Database I thought something like this would work. I can just run the routine and it will do the transfer for me.
    */
    for ($id=1; $id<=1000; $id++) {
    $user = get_user_by( ‘id’, $id );
    $wp_id = $user->id;
    $wp_name = $user->user_login;
    $wp_email = $user->user_email;
    $wp_first_name = $user->user_firstname;
    $wp_last_name = $user->user_lastname;

    if ($wp_name != ”) {
    $user_id = Participants_Db::get_record_id_by_term(‘username’, $wp_name);

    if ($user_id != ”) {
    echo ‘Record Exists – do nothing <br />’;
    }
    else {
    echo ‘Create New Record <br />’;
    /* WHAT GOES HERE */
    }
    }
    }
    [/insert_php]

    All works well. Records that exist in the WP and PD database are echoed as Record Exists. Records that exist in WP but not PD are echoed as Create New Record.

    Two questions
    1. Is there an easier way to do this and if so can you give me a few pointers.
    2. I have the username, email, first_name, last_name for the records, but how do I create the NEW Records in PD with these values?

    Many Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter supernova42

    (@supernova42)

    I have refined this a little and it can be used to pass all WordPress user records to the Participants Database. However, the one thing I’m still stuck on is how do I create the actual Participants Database Record.
    Many Thanks

    `[insert_php]
    echo ‘<b>Creating New PD Records for the following WordPress Users</b><br /> ‘;
    for ($id=1; $id<=1000; $id++) {
    $user = get_user_by( ‘id’, $id );
    $wp_id = $user->id;
    $wp_username = $user->user_login;
    $wp_email = $user->user_email;
    $wp_first_name = $user->user_firstname;
    $wp_last_name = $user->user_lastname;
    if (!empty($wp_username)) {
    $user_id = Participants_Db::get_record_id_by_term(‘username’, $wp_username);
    if (empty($user_id)) {
    echo $wp_id.’ : ‘.$wp_username.’ : ‘.$wp_email.’ : ‘.$wp_first_name.’ ‘.$wp_last_name.'<br />’;
    /*Create New PD Record Here*/
    }
    }
    }
    [/insert_php]

    Plugin Author xnau webdesign

    (@xnau)

    The easiest way is to use Participants_Db::write_participant($data) where $data is an associative array of values that you could set up like this:

    $data = array(
       'user_id' => $wp_id,
       'user_login' => $wp_username,
       'email' => $wp_email,
       // etc.....
    );

    and so forth until you have all your data in the array. This assumes that the fields named in the keys of your $data array are already defined.

    Thread Starter supernova42

    (@supernova42)

    Absolutely fantastic – I can now transfer all my WordPress users to the Participants Database without using csv exports and imports. As new users join the WordPress site, I can just run this function to transfer their data to the Participants Database.

    Many Thanks Roland, I really appreciate your assistance…

    [insert_php]
    echo ‘<b>Creating New PD Records for the following WordPress Users</b><br /> ‘;
    for ($id=1; $id<=1000; $id++) {
    $user = get_user_by( ‘id’, $id );
    $wp_id = $user->id;
    $wp_username = $user->user_login;
    $wp_email = $user->user_email;
    $wp_first_name = $user->user_firstname;
    $wp_last_name = $user->user_lastname;

    if (!empty($wp_username)) {
    $user_id = Participants_Db::get_record_id_by_term(‘username’, $wp_username);
    if (empty($user_id)) {
    echo $wp_id.’ : ‘.$wp_username.’ : ‘.$wp_email.’ : ‘.$wp_first_name.’ ‘.$wp_last_name.'<br />’;
    $data=array(‘wp_id’ => $wp_id,’username’ => $wp_username,’email’ => $wp_email,’first_name’ => $wp_first_name, ‘last_name’ => $wp_last_name);
    Participants_Db::write_participant($data);
    }
    }
    }
    [/insert_php]

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Transferring Records from WordPress to PD’ is closed to new replies.