The MU forums have moved to WordPress.org

wp-mailer - editing Inviz's 'mail all users' plugin (9 posts)

  1. Farms
    Member
    Posted 16 years ago #

    A while back the most excellent Inviz developed and released a wpmu-mailer plugin (code below)... now this still works like a dream but unfortunately the page on which the 'unsubscribe from the newsletter' option used to appear no longer does!

    (I think it was the 'General' options area)

    So... could anyone help me out (and it would be most enourmously appreciated!) by telling me what I need to edit for the 'Do not recieve' option to automatically apprear on the 'My Account' page?

    Thanks for your time! James

    <?

    /*
    Plugin Name: WPMU Mailer
    Description: Mass emailer for WPMU
    Version: 2
    License: GPL
    Author: Inviz
    Author URI: http://inviz.personart.ru
    */

    /*
    FOR ALL THOSE WHO WANT TO EDIT THIS:
    Folks, okay, i accept editing, edit it for your own purposes.
    BUT
    If u edited only some lines:
    DO NOT RELEASE IT WITH YOUR OWN COPYRIGHTS.

    Inviz, With luv.
    */
    add_action('admin_menu', 'mailer_menu');
    add_action('admin_head', 'mailer_installation');
    add_action('personal_options_table','mailer_user_options');
    add_action('personal_options_update','mailer_user_options_update');

    function mailer_menu() {
    if (is_site_admin()) {
    add_submenu_page('post.php', 'Spam', 'Spam', 0, 'mailer', 'mailer');
    }
    }

    function user_recieve_spam($email) {
    global $wpmuBaseTablePrefix,$wpdb,$no_spam;
    if (!$no_spam) //not selected
    $no_spam=$wpdb->get_col('SELECT
    user_email FROM '.$wpmuBaseTablePrefix."spam");
    if (!$no_spam) //selected, but nothing in the table
    return false;
    else
    return in_array($email,$no_spam) ? true : false;
    }

    function mailer_installation() {
    global $wpdb,$wpmuBaseTablePrefix,$url;
    $wpdb->hide_errors();
    //checking if table exists -> installation is okay
    $T= $wpdb->get_var('select 1 from
    '.$wpmuBaseTablePrefix.'spam');
    if($T===null and $T!='0')
    $wpdb->query("CREATE TABLE
    ".$wpmuBaseTablePrefix."spam(
    id INT NOT NULL AUTO_INCREMENT ,
    user_email VARCHAR( 255 ) NOT NULL ,
    PRIMARY KEY (
    id )
    ) TYPE = MYISAM ;");
    $wpdb->show_errors();
    }
    function get_current_user_email() {
    global $wpdb;
    return $wpdb->get_var( "SELECT
    user_email FROM $wpdb->users WHERE ID = '".get_current_user_id()."'" );
    }

    function mailer_user_options_update() {
    global $wpdb,$wpmuBaseTablePrefix;
    if (user_recieve_spam(get_current_user_email()) && $_POST['recieve_spam']==false && $_POST['page_options']) {
    $delete=$wpdb->query('DELETE FROM
    wp_spam WHERE user_email = "'.get_current_user_email().'"');
    } elseif (!user_recieve_spam(get_current_user_email()) && $_POST['recieve_spam']==true) {
    $wpdb->query('INSERT INTO
    wp_spam ( id , user_email )
    VALUES (
    "", "'.get_current_user_email().'"
    );');
    }
    }
    function mailer_user_options() {
    global $wpdb,$wpmuBaseTablePrefix;
    ?>
    <tr valign="top">
    <th scope="row">Newsletter:</th>
    <td><label for="recieve_spam">
    <input name="recieve_spam" type="checkbox" id="recieve_spam" <?php if (!$delete && user_recieve_spam(get_current_user_email())) echo 'checked="checked"'?>/>
    Do not recieve edublogs.org email newsletter</label></p></td>
    </tr>
    <?php
    }
    function mailer() {
    global $wpdb,$wpmuBaseTablePrefix,$current_site;
    if ($_POST && $_POST['from'] && $_POST['subject'] && $_POST['content']) {
    $users = $wpdb->get_results("SELECT
    user_email as mail, ID as id,user_url as url,user_login as login, display_name as name
    FROM
    ".$wpmuBaseTablePrefix."users GROUP BY user_email;",ARRAY_A);

    $headers = "From: ".$_POST['from']."rn" .
    'X-Mailer: PHP/' . phpversion() . "rn" .
    "MIME-Version: 1.0rn" .
    "Content-Type: text/html; charset=utf-8rn" .
    "Content-Transfer-Encoding: 8bitrnrn";
    $url=$current_site->domain . $current_site->path;
    $from=$_POST['from'];

    foreach ($users as $user) {
    if (!user_recieve_spam($user['mail'])) {
    $subject=$_POST['subject'];
    $message=$_POST['content'];
    $search[]='%%MYURL%%';
    $replace[]=$url;
    $search[]='%%NAME%%';
    $replace[]=$user['name'];
    $search[]='%%URL%%';
    $replace[]=$user['url'];
    $search[]='%%LOGIN%%';
    $replace[]=$user['login'];
    $search[]='%%MAIL%%';
    $replace[]=$user['mail'];
    $message=nl2br($message);
    $subject=str_replace($search,$replace,$subject);
    $message=str_replace($search,$replace,$message);
    if ($_POST['debug'])
    echo "<hr /><strong>TO:</strong>".$user['mail']."<BR /><strong>SUBJ:</strong>".$subject."<BR /><strong>BODY:</strong>".$message."<BR /><strong>HDRS:</strong>".$headers."<BR /><hr />";
    else
    mail ($user['mail'],$subject,$message,$headers);
    $sent++;
    unset($search,$replace);
    }
    }
    }
    ?>
    <div class='wrap'>
    <?php
    if ($sent) {
    $unspammed=$wpdb->get_var('SELECT count(
    id) FROM '.$wpmuBaseTablePrefix.'spam;');
    ?>
    <h2>Spam attempt successful</h2>
    <div class="updated fade" id="message">
    <table class='editform'>
    <tr><th scope='row' valign='top' width="150">Users spammed: </th><td><?=$sent?></td></tr>
    <tr><th scope='row' valign='top'>Users unspammed: </th><td><?=$unspammed?></td></tr>
    <tr><th scope='row' valign='top'>Users total: </th><td><?=$sent+$unspammed?></td></tr>
    <tr><th scope='row' valign='top'>Spammed subj: </th><td><?=$subject?></td></tr>
    <tr><th scope='row' valign='top'>Spammed body: </th><td><?=$message?></td></tr>
    </table>
    </div>
    <?php
    } elseif ($_POST) {
    ?>
    <h2>Spam attempt failed</h2>
    <div class="error fade" id="message">
    Noone wants your spam :p
    </div>
    <?php
    }
    ?>
    <h2>Spam form</h2>
    <form method="POST">
    <table class='editform'>
    <tr><th scope='row' valign='top' width="150">From: </th><td><input type='text' name='from' value="<?=$wpdb->get_var("SELECT
    user_email FROM ".$wpmuBaseTablePrefix."users WHERE ID=1;")?>"/></td></tr>
    <tr><th scope='row' valign='top'>Mail Subject: </th><td><input type='text' name='subject' /></td></tr>
    <tr><th scope='row' valign='top'>Mail Body: </th><td>
    <textarea name="content" id="content" title="true" rows="7" style="width:500px "></textarea>
    <?php the_quicktags(); ?>
    <script type="text/javascript">
    <!--
    edCanvas = document.getElementById('content');
    //-->
    </script>
    </td></tr>
    <tr><td>&nbsp;</td><td><strong>You can use variables: </strong><br>%%NAME%% - for user's full name (Phedin Yaroslaff)<br />%%LOGIN%% - for user login (inviz)<br />%%MAIL%% - for user's mail (inviz@personart.ru)<br />%%URL%% - for blog url (http://inviz.blawg.ru)<br />%%MYURL%% - for blog system URL (http://blawg.ru)</td></tr&gt;
    <tr><th>Test message</th><td><input type="checkbox" name="debug" checked /> </td></tr>
    <tr><th valign='top'><input type='submit' value="Spam'em all!" onClick="(confirm('Sure?')=='false') return false;" /></th></tr>
    </table>
    </form>

    </div>
    <?php
    }
    ?>

  2. quenting
    Member
    Posted 16 years ago #

    hey, i've run into the same problem.
    here's what i've done to solve it:

    replaced
    add_submenu_page('post.php', 'Spam', 'Spam', 0, 'mailer', 'mailer');
    with
    add_submenu_page('post-new.php', 'Spam', 'Spam', 0, 'mailer', 'mailer');

    somehow in the distribution i got, "post.php" isn't used but it is post-new.php which holds the write menu. without this change the option didn't appear.

    replace:
    add_action('personal_options_table','mailer_user_options');
    with:
    add_action('profile_personal_options','mailer_user_options');

    The checkbox actually appears in the profile editing page, not the options. I haven't found any action in the options page, so i think it's not possible right now to do it there. It's fine enough for me to have the checkbox in the profile options though.

    I also had to replace:
    if (user_recieve_spam(get_current_user_email()) && $_POST['recieve_spam']==false && $_POST['page_options']) {
    with
    if (user_recieve_spam(get_current_user_email()) && $_POST['recieve_spam']==false) {

    the "page_options" thin doesn't appear in the profile page, and so it wasn't possible to switch back to accepting emails anymore.

  3. samchng
    Member
    Posted 16 years ago #

    Tried copying the codes from Farm's post and uploaded it to plugins directory. But it's not working. Activated plugin, but don't see any options. Did BBpress strip anything again?

  4. quenting
    Member
    Posted 16 years ago #

    did you add the modifications i posted as well ? it won't work without them. which plugins directory did you add it to ? I use it with bbpress and it works great.

  5. samchng
    Member
    Posted 16 years ago #

    Yes showing on admin panel now! But when I tried sending. It says it successful, but no mail received on any account. Weird. ANy ideas?

  6. quenting
    Member
    Posted 16 years ago #

    did you uncheck the "test" textbox ?

  7. samchng
    Member
    Posted 16 years ago #

    Oh I did! Lolx... Success! Thanks quenting! You have been of reat help. :))

  8. mrjcleaver
    Member
    Posted 16 years ago #

    Would you mind uploading a completed version of this to wpmuplugins.org? Thx.

  9. topherrosado
    Member
    Posted 16 years ago #

    I've uploaded my version to wpmudev.org if anyone wants to use it.

About this Topic

  • Started 16 years ago by Farms
  • Latest reply from topherrosado