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');
".$wpmuBaseTablePrefix."spam
if($T===null and $T!='0')
$wpdb->query("CREATE TABLE (
id
INT NOT NULL AUTO_INCREMENT ,
user_email
VARCHAR( 255 ) NOT NULL ,
id
PRIMARY KEY ( )
user_email
) TYPE = MYISAM ;");
$wpdb->show_errors();
}
function get_current_user_email() {
global $wpdb;
return $wpdb->get_var( "SELECT 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().'"');
wp_spam
} elseif (!user_recieve_spam(get_current_user_email()) && $_POST['recieve_spam']==true) {
$wpdb->query('INSERT INTO (
id ,
user_email )
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 as
mail,
ID as
id,
user_url as
url,
user_login as
login,
display_name as
name
".$wpmuBaseTablePrefix."users
FROM 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;');
user_email
?>
<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 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> </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>
<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
}
?>