2

I was wondering is there a way to send the admin a notification (email or otherwise) whenever a user submits a post.

Currently, I have to log into the admin section to see if there was anything submitted. I need to review their post before actually publishing it, so I need to be notified via email whenever a post is submitted.

Does anyone know of a solution for this?

Thanks a lot

1 Answer 1

2

You could try this inside your themes functions.php:

its a function by dagon design

function dddn_process($id) {

global $wpdb;

$tp = $wpdb->prefix;

$result = $wpdb->get_row("
    SELECT post_status, post_title, user_login, user_nicename, display_name
    FROM {$tp}posts, {$tp}users
    WHERE {$tp}posts.post_author = {$tp}users.ID
    AND {$tp}posts.ID = '$id'
");

if ($result->post_status == "publish") {

    $message = "";
    $message .= "A new post was submitted on '" . get_bloginfo('name') . "'\n\n";
    $message .= "Title: " . $result->post_title . "\n\n";


    $message .= "Author: " . $result->display_name . "\n\n";

    $message .= "Link: " . get_permalink($id);

    $subject = "Post Submitted on '" . get_bloginfo('name') . "'";

    $recipient = get_bloginfo('admin_email');

    mail($recipient, $subject, $message);

}

}

add_action('publish_post', 'dddn_process');  
4
  • It works! What would I set post_status for published posts instead of pending?
    – user1893
    Jun 21, 2011 at 16:55
  • changing if ($result->post_status == "pending") { to if ($result->post_status == "publish") { should do it..
    – MartinJJ
    Jun 21, 2011 at 16:58
  • Marin, I "publish" but it didn't send the email...
    – user1893
    Jun 21, 2011 at 17:17
  • Have edited my original post with the changes, try that big block of code again, have added a little to it regarding the action hook
    – MartinJJ
    Jun 21, 2011 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.