post_author);
$myname = $user->display_name;
$myemailadd = $user->user_email;
$cats = wp_get_post_cats('1', $post_ID);
foreach ($cats as $cat) {
$c2e_cat = get_option("c2e_$cat");
if ( ('' != $c2e_cat) && (is_email($c2e_cat)) ) {
if ('' == $to) {
$to = $c2e_cat;
} else {
$to .= ", " . $c2e_cat;
}
}
}
if ('' == $to) {
// no one to send to!
return $post_ID;
}
// Set sender details
$headers = "From: \"$myname\" <$myemailadd>\n";
$headers .= "MIME-Version: 1.0\n";
// Set email subject
$subject = '[' . get_settings('blogname') . '] ' . $post->post_title;
$mailtext = '';
if ('html' == get_option('c2e_format')) {
// To send HTML mail, the Content-type header must be set
// http://us2.php.net/manual/en/function.mail.php
$headers .= "Content-type: " . get_bloginfo('html_type') . "; charset=\"" . get_bloginfo('charset') . "\"\n";
$mailtext = "
$subject";
$content = $post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$mailtext .= $content;
$mailtext .= "";
} else {
$headers .= "Content-type: text/plain; charset=\"" . get_bloginfo('charset') . "\"\n";
$mailtext = wordwrap(strip_tags($post->post_content));
}
// And away we go...
wp_mail($to, $subject, $mailtext, $headers);
return $post_ID;
} // end cat2email
////////////////////
function c2e_manage() {
global $wpdb;
if (isset($_POST['c2e_action'])) {
$c2e_action = $_POST['c2e_action'];
}
if ('delete' == $c2e_action) {
c2e_delete();
} elseif ('add' == $c2e_action) {
c2e_add();
} elseif ('format' == $c2e_action) {
c2e_format();
}
$c2e_list = array();
$cats = $wpdb->get_col("SELECT cat_ID from $wpdb->categories");
$c2e_format = get_option('c2e_format');
if (FALSE === $c2e_format) {
$c2e_format = 'plain';
}
// get the list of defined addresses
foreach ($cats as $cat) {
$foo = get_option("c2e_$cat");
if ( (FALSE != $foo) && (is_email($foo)) ) {
$c2e_list[$cat] = $foo;
}
}
echo "
\r\n";
echo "\r\n";
echo "";
echo "\r\n";
echo "
";
include(ABSPATH . '/wp-admin/admin-footer.php');
// just to be sure
die;
} // end c2e_manage
//////////////////
function c2e_add() {
if ( (isset($_POST['cat'])) && (isset($_POST['email'])) && (is_email($_POST['email'])) ) {
// first check to see if it exists
$cat = $_POST['cat'];
$email = $_POST['email'];
$foo = get_option("c2e_$cat");
if (FALSE !== $foo) {
// now see if it's different
if ($foo != $email) {
update_option("c2e_$cat", $email);
}
} else {
add_option("c2e_$cat", $email);
}
}
// clear the $_POST variable, and go back to manage
$_POST['c2e_action'] = '';
//c2e_manage();
} // c2e_add
/////////////////////
function c2e_delete() {
if (isset($_POST['cat'])) {
$cat = $_POST['cat'];
// make sure this exists in the DB
$foo = get_option("c2e_$cat");
if (FALSE != $foo) {
update_option("c2e_$cat", '');
}
}
$_POST['c2e_action'] = '';
//c2e_manage();
} // c2e_delete
/////////////////////
function c2e_format() {
if (isset($_POST['c2e_format'])) {
update_option('c2e_format', $_POST['c2e_format']);
}
$_POST['c2e_action'] = '';
} // c2e_format
function c2e_edit($ID = 0) {
if (0 == $ID) { return; }
global $c2e_token;
$c2e_token = 1;
return $ID;
}
/////////////////////
// main program block
global $c2e_token;
add_action('admin_menu', 'cat2email_menu');
add_action('edit_post', 'c2e_edit');
add_action('publish_post', 'cat2email');
add_action('private_to_published', 'cat2email');
?>