我应该使用什么Add_action引用,还是应该使用do_action?

时间:2015-04-27 作者:JediTricks007

我正在处理一些自动电子邮件。我对add\\u action和do\\u action相当陌生。我很难理解它。该网站设定了许多目标,人们可以随着时间的推移达到这些目标。我想在他们进球时给他们发一封电子邮件。下面的代码将在帖子更新时发送该电子邮件,但这不起作用。我把它放在那里只是为了确保邮件发出。我不知道应该使用什么add\\u操作。要做到这一点,我应该寻找什么样的参考资料?

function emailNotificationSuccess($post_id) {

  if( ( $_POST[\'post_status\'] == \'publish\' ) && ( $goalsupport === $totalsupport ) ) {

   $post = get_post($post_id);
   $author = get_userdata($post->post_author);
   $totalsupport = countSupportForAll($post->ID);
   $goalsupport = get_post_meta( $post->ID, \'sj_campaign_goal\', true );
   $supporter_email = get_post_meta( $post_id, \'sj_campaign_email\', true );
   $message = "Hi ".$author->display_name.",


Congrats! You have reached your goal!

Your , ".$post->post_title." is a success!

".get_permalink( $post_id )."


   ";
   wp_mail($supporter_email, "You just reached your goal!", $message);

  } 
} 
add_action(\'post_updated\', \'emailNotificationSuccess\');

1 个回复
SO网友:cybmeta

你的问题是有条件的,而不是用过的动作(我想)。

该行可能在任何情况下都不会验证:

if( ( $_POST[\'post_status\'] == \'publish\' ) && ( $goalsupport === $totalsupport ) ) {
我现在不知道$goalsupport和$goalsupport是什么,这两个变量在您的代码中都没有定义,所以我将删除它们。用这一行更改该行:

if( get_post_status( $post_id ) == \'publish\' ) {
因此,代码应为:

function emailNotificationSuccess($post_id) {

  if( get_post_status( $post_id ) == \'publish\' ) {

   $post = get_post($post_id);
   $author = get_userdata($post->post_author);
   $totalsupport = countSupportForAll($post->ID);
   $goalsupport = get_post_meta( $post->ID, \'sj_campaign_goal\', true );
   $supporter_email = get_post_meta( $post_id, \'sj_campaign_email\', true );
   $message = "Hi ".$author->display_name.",


Congrats! You have reached your goal!

Your , ".$post->post_title." is a success!

".get_permalink( $post_id )."


   ";
   wp_mail($supporter_email, "You just reached your goal!", $message);

  } 
} 
add_action(\'post_updated\', \'emailNotificationSuccess\');

结束

相关推荐

Child theme functions.php

我不知道如何改变我的孩子主题的功能。php。在woothemes文档中,它说“子主题中的functions.php应该是空的,并且不包括父主题functions.php中的任何内容。”我需要使用此功能来不显示产品类别,但我不确定如何在我的子主题中执行此操作。也许有人能给我提供一些指示?add_action( \'pre_get_posts\', \'custom_pre_get_posts_query\' ); function custom_pre_get_posts_query( $