• I use this piece of code to send notifications to the author of a post when it gets published. The problem is that everytime something changes, the e-mail is fired. I would like this code to be executed only the first time it gets published. Since I lack a serious amount of programming experience, i would be grateful to any kind of help

    function authorNotification ($post_id) {
    global $wpdb;
    $post = get_post($post_id);
    $author = get_userdata($post->post_author);
    $message = “
    Hallo “.$author->display_name.”,

    De door u geregistreerde winkel, “.$post->post_title.” is gepubliceerd op Scanjevoordeel.nl, u kunt nu uw aanbiedingen toevoegen.

    Met vriendelijke groet,

    Scanjevoordeel.nl”;
    wp_mail($author->user_email, “Uw winkel op Scanjevoordeel.nl is gepubliceerd”, $message);}
    add_action(‘publish_winkel’, ‘authorNotification’);

    Thanks
    Luit

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Change the action on last line from ‘publish_winkel’ to what would be in your language equivalent to English ‘draft_to_publish’. This works because all new posts are instantly auto-saved to draft.

    The main difference is the whole post object is passed as a parameter, so you don’t need to get_post(), so your first four lines become these three:

    function authorNotification ($post) {
    global $wpdb;
    $author = get_userdata($post->post_author);

Viewing 1 replies (of 1 total)
  • The topic ‘making author notification condtional’ is closed to new replies.