Skip to:
Content
Pages
Categories
Search
Top
Bottom

ListMessenger (or PHPlist) integration – plugin?


  • peterverkooijen
    Participant

    @peterverkooijen

    I need to integrate my mailing list with Buddypress registration. In the current version of my site I use ListMessenger; when someone registers with the site their name + email address is also automatically added to a mailing list.

    ListMessenger can’t tap into existing WordPress users tables in MySQL, it has its own users table. The integration challenge is to keep them somewhat synchronized; add name + email address to ListMessenger’s users table to start with, but it would be nice if changes in name + email address would also be synchronized with the ListMessenger data.

    I’ve tried to use this plugin as a starting point: WordPress PHPList Dual Registration.

    I started this thread about it on the ListMessenger forum.

    The key apparently is to get the plugin to execute (?) the following URL on registration:

    http://mysite.com/mailinglist/public/listmessenger.php?group_ids[/url][]=1&email_address=random@whatever.com&firstname=John&lastname=Smith

    …which could be achieved by a line like this in the plugin:

    $post_data = 'action=subscribe&group_ids[]='.$this->lid.'&email_address='.$this->email_id.'&firstname='.$this->name_id;

    So far I have not been able to make that work. :-(

    The next few days I’ll try to learn how to write a plugin for WordPress, but I need all the help I can get. I’m not a programmer, but after messing with this stuff for ten years I have some general ideas how things work. I will need help on things like what are the right names for what, where to find information and code examples and how to get syntax etc. right.

    Integration is further complicated by Buddypress lack of consistency in storing firstname + lastname, which I have complained about a lot in this forum – sorry…

    I post this issue here and not on the WPMU forum because adding members to a mailing list really is a social networking function and it needs to work with Buddypress’ registration and xprofile etc.

Viewing 9 replies - 1 through 9 (of 9 total)

  • peterverkooijen
    Participant

    @peterverkooijen

    I am now going through the How to Write a WordPress Plugin tutorial on DevLounge.net.

    It says you can hook into WordPress to execute pieces of code using WordPress actions. I assume in my case I should use this action:

    register_post

    So I should write a function that somehow forms and executes that URL – http://mysite.com/…/listmessenger.php?etc. – and trigger that on registration using register_post?

    And to construct the function I can use WordPress filters? The available ‘database writes’ filters are only for WordPress tables of course…

    How would I add data to tables outside WordPress, in this case the ListMessenger tables?

    Edit 1: Stupid question; that is done by that URL created by $post_data=… in the PHPList code.

    Or is there a better way to add data to the database directly from the plugin?

    Edit 2: This page has more information on creating/updating tables outside regular WordPress. Would that approach be better than that URL?


    peterverkooijen
    Participant

    @peterverkooijen

    I’m now trying to add firstname, lastname and email address straight to the database tables of my mailing list. I’ve added the queries to the function I had put together here:

    function synchro_wp_usermeta($user_id, $password, $meta) {
    global $bp, $wpdb;

    ...

    $wpdb->query("INSERT mailingusers SET users_id='$user_id', group_id='1', signup_date= UNIX_TIMESTAMP(), firstname= '$firstname', lastname= '$lastname', email_address= '$user_email'");
    $wpdb->query("INSERT mailingcdata SET cdata_id=NULL, user_id='$user_id', cfield_id='1', value='$company'");

    }
    add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 3);

    This mostly works, except the for the email address. $firstname, $lastname and $user_id are all correctly added to the table, but the email_address field stays empty.

    Can anyone spot the problem?

    How can I “call” the user’s email address upon ‘wpmu_activate_user’?

    Adding a $user_email argument only produces missing argument errors. I’m out of guesses…

    $current_user->user_email doesn’t work either:

    $wpdb->query("INSERT mailingusers SET users_id='$user_id', group_id='1', signup_date= UNIX_TIMESTAMP(), firstname= '$firstname', lastname= '$lastname', email_address= '$current_user->user_email'");


    peterverkooijen
    Participant

    @peterverkooijen

    Even this doesn’t work:

    $email = $wpdb->query("SELECT user_email FROM $wpdb->signups WHERE activation_key = %s", $key);

    And this also does not work:

    $email = $wpdb->query("SELECT user_email FROM $wpdb->users WHERE ID = %s", $user_id);

    ?? :-(


    peterverkooijen
    Participant

    @peterverkooijen

    This works:

    function synchro_mailinglist($user_id, $password, $meta) {
    global $bp, $wpdb;

    $email = $wpdb->get_var("SELECT user_email FROM $wpdb->users WHERE ID='$user_id'");

    $fullname = $meta[field_1];
    $space = strpos( $fullname, ' ' );

    $company = $meta[field_2];

    if ( false === $space ) {
    $firstname = $fullname;
    $lastname = '';
    } else {
    $firstname = substr( $fullname, 0, $space );
    $lastname = trim( substr( $fullname, $space, strlen($fullname) ) );
    }

    $firstname = nameize($firstname);
    $lastname = nameize($lastname);

    ...

    $wpdb->query("INSERT mailingusers SET users_id='$user_id', group_id='1', signup_date= UNIX_TIMESTAMP(), firstname= '$firstname', lastname= '$lastname', email_address = '$email' ");
    $wpdb->query("INSERT mailingcdata SET cdata_id=NULL, user_id='$user_id', cfield_id='1', value='$company'");

    }
    add_action( 'wpmu_activate_user', 'synchro_mailinglist', 10, 3);

    I used it as part of this function. This should work other mailinglist scripts as well, just change the table and field names.

    I don’t understand why $user_email didn’t work. I had to pull the user_email from the database. Is there a cleaner way?


    nicolagreco
    Participant

    @nicolagreco

    i think is better use built-in function that queries the db to get user info.

    Try with

    function synchro_mailinglist($user_id, $password, $meta) {

    $uid = get_userdata($user_id);

    […….]

    $uid->user_email is the e-mail

    It’s better use built-in functions because they are safer and they apply the filters and wp actions


    peterverkooijen
    Participant

    @peterverkooijen

    Thanks Nicola Greco!

    I knew there had to be a better solution, something like this, but couldn’t put it together.

    So I replaced that database line with this:

    $uid = get_userdata($user_id);
    $email = $uid->user_email;

    Works fine. :-)


    Mike Pratt
    Participant

    @mikepratt

    Peter – I use “Big Tie”support for MadMimi http://support.hfconcepts.com/. It auto syncs my BP member list like a champ and is well worth the $40


    Mike Pratt
    Participant

    @mikepratt

    sorry this is the link: http://bigtie.hfconcepts.com/


    peterverkooijen
    Participant

    @peterverkooijen

    Correction to the code above: In most cases it’s probably safer to just remove this from the INSERT query for ‘mailingusers’ (or whatever your mailing list uses):

    users_id='$user_id',

    In ListMessenger this ID is incremental. If you force it take the same ID as used in WordPress you may get nasty errors.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘ListMessenger (or PHPlist) integration – plugin?’ is closed to new replies.
Skip to toolbar