mass emailer

when i install the mass emailer,under my profile it list recieve admin emails but the selection box is empty.

in the admin section (where you write the mails) it says 380 out of 210 user(s) currently accepting emails.

how can 380 out of 210 user be accepting emails?

    aahinoam

    I had the same problem (selection box is empty in the user profile page). After debugging for a while here are my findings:

    There are two bugs the code, which cause the 'recieve_admin_emails' to be never set in the usermeta table. The first time the mass_mailer_user_install function is being called, the $current_user is not set and therefore the function mass_mailer_global_db_sync fails to set the user recieve_admin_emails value. The second bug is in the mass_mailer_global_db_sync itself, which tries to set the email_optout value in the wp_mass_mailer table based on the recieve_admin_emails value which was never set...

    the following fix these bugs and also install and update all users' data in the same time (which means that the mass_mailer_user_install is now useless):

    1. Delete the following lines:

    if ($_GET['page'] == 'mass_mailer_main'){
    mass_mailer_install();
    mass_mailer_upgrade();
    }
    if (get_site_option( "mass_mailer_installed" ) == "yes") {
    mass_mailer_user_install();
    }

    2. Add the following line:

    add_action('load-site-admin_page_mass_mailer_main', 'mass_mailer_install');

    3. Replace the processArrayUsersPopulate function with the following updated version:

    function processArrayUsersPopulate($arrayName) {
    global $wpdb, $wp_roles, $current_user, $user_ID;
    foreach ($arrayName as $arrayElement) {
    if (count($arrayElement) > 1) {
    processArrayUsersPopulate($arrayElement);
    } else {
    $intArrayCount = $intArrayCount + 1;
    if ($intArrayCount == 1) {
    $tmp_email_count = $wpdb->get_var("SELECT COUNT(*) FROM wp_mass_mailer WHERE email_user_id = '" . $arrayElement . "'");
    if ($tmp_email_count == '0') {
    $tmp_email_count2 = $wpdb->get_var("SELECT COUNT(*) FROM wp_usermeta WHERE user_id = '" . $arrayElement . "' AND meta_key = 'recieve_admin_emails'");
    if ($tmp_email_count2 == '0') {
    update_usermeta($arrayElement, 'recieve_admin_emails', 'yes');
    $wpdb->query( "INSERT INTO wp_mass_mailer (email_user_id, email_optout, email_status) VALUES ( '" . $arrayElement . "', 'yes', 'yes' )" );
    } else {
    $wpdb->query( "INSERT INTO wp_mass_mailer (email_user_id, email_optout, email_status) VALUES ( '" . $arrayElement . "', '" . get_usermeta($arrayElement, 'recieve_admin_emails') . "', 'yes' )" );
    }

    } else {
    $recieve_admin_emails = get_usermeta($arrayElement, 'recieve_admin_emails');
    if(!$recieve_admin_emails) {
    $recieve_admin_emails = 'yes';
    update_usermeta($arrayElement, 'recieve_admin_emails', $recieve_admin_emails);
    }

    $wpdb->query( "UPDATE wp_mass_mailer SET email_optout = '" . $recieve_admin_emails . "' WHERE email_user_id = '" . $arrayElementc . "'" );
    }
    }
    if ($intArrayCount == 2) {
    //echo "<td valign='top'>$arrayElement</td>";
    }
    }
    }
    }

    4. Update the mass_mailer_global_db_sync function to the following:

    function mass_mailer_global_db_sync() {
    global $wpdb, $wp_roles, $current_user;
    $tmp_email_count = $wpdb->get_var("SELECT COUNT(*) FROM wp_mass_mailer WHERE email_user_id = '" . $current_user->ID . "'");
    if ($tmp_email_count == '0') {
    $wpdb->query( "INSERT INTO wp_mass_mailer (email_user_id, email_optout, email_status) VALUES ( '" . $current_user->ID . "', 'yes', 'yes' )" );
    } else {
    $recieve_admin_emails = get_usermeta($current_user->ID, 'recieve_admin_emails');
    if(!$recieve_admin_emails) {
    $recieve_admin_emails = 'yes';
    update_usermeta($current_user->ID, 'recieve_admin_emails', $recieve_admin_emails);
    }
    $wpdb->query( "UPDATE wp_mass_mailer SET email_optout = '" . $recieve_admin_emails . "' WHERE email_user_id = '" . $current_user->ID . "'" );
    }
    }

    Hope it will get into the official version.

    Cheers,

    Amir

    aahinoam

    More:

    In order to support new users the following function should be updated to:

    function mass_mailer_global_db_sync() {
    global $wpdb, $wp_roles, $current_user;
    $tmp_email_count = $wpdb->get_var("SELECT COUNT(*) FROM wp_mass_mailer WHERE email_user_id = '" . $current_user->ID . "'");
    if ($tmp_email_count == '0') {
    $wpdb->query( "INSERT INTO wp_mass_mailer (email_user_id, email_optout, email_status) VALUES ( '" . $current_user->ID . "', 'yes', 'yes' )" );
    update_usermeta($current_user->ID, 'recieve_admin_emails', 'yes');
    } else {
    $recieve_admin_emails = get_usermeta($current_user->ID, 'recieve_admin_emails');
    if(!$recieve_admin_emails) {
    $recieve_admin_emails = 'yes';
    update_usermeta($current_user->ID, 'recieve_admin_emails', $recieve_admin_emails);
    }
    $wpdb->query( "UPDATE wp_mass_mailer SET email_optout = '" . $recieve_admin_emails . "' WHERE email_user_id = '" . $current_user->ID . "'" );
    }
    }

    and one more thing, users that are deleted from the site are not removed from the wp_mass_mailer table .

    Amir