0

这是我的功能,

class emailer {
function notifyHeart($post_ID)  {
$interests = get_user_meta(get_current_user_id(), 'interests');
$to = 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'));

发布帖子后出现错误,并且仅在我包含

$to = the_author_meta( 'user_email', get_current_user_id() );

如果我包括这个,

$to = "email@email.com";

不会出现警告。有人想吗?

4

1 回答 1

0

您只需要使用不同的 WP 功能:

// This actually echos the result right to the page, hence the headers error.
the_author_meta()

// Whereas this lets you capture the value into your $to variable:
get_the_author_meta()
于 2012-12-20T20:48:07.487 回答