User meta and author meta

Here’s what I have so far..

class emailer {
function notifyHeart($post_ID)  {

    $interests = get_user_meta( get_current_user_id(), 'interests', TRUE );
    $to = the_author_meta( 'user_email', get_current_user_id() );

    if(has_tag($interests[0])) {
        $email = $to;
        mail($email, "An article about Heart", 
          'A new post has been published about heart.');
        return $post_ID;
    }
}
}

add_action('publish_post', array('emailer', 'notifyHeart'));

What I need to do now, before actually sending the email, I need something that checks if the user has an $interest and if so, send them an email. Any help with this?

Related posts

Leave a Reply

1 comment

  1. class emailer {
      static function notifyHeart($post_ID)  {
        $interests = get_user_meta(get_current_user_id(), 'interests');
        $to = get_the_author_meta( 'user_email', get_current_user_id() );
        $post = get_post($post_ID);
    
        foreach($interests as $interest) {
          if(has_tag($interest, $post)) {
            $email = $to;
            mail($email, "An article about Heart", 'A new post has been published about heart.');
            break;
          }
        }
      }
    }
    add_action('publish_post', array('emailer', 'notifyHeart'));
    

    Here’s a reworked example. It retrieves all the tags you have in database as meta, checks each of them & if it matches the one in that post’s id, it will send the mail & break out of the loop.