Php 发送电子邮件一次,而不是每次更新帖子

Php 发送电子邮件一次,而不是每次更新帖子,php,wordpress,email,message,Php,Wordpress,Email,Message,我正在使用插件,下面有一段代码,用于在发布帖子时向帖子作者发送消息,它工作正常,但每次更新帖子时仍会发送消息!我怎么能阻止它 另一点是如何向所有注册用户发送相同的消息 add_action( 'publish_post', 'fep_cus_user_publish_send_messaage', 10, 2 ); function fep_cus_user_publish_send_messaage( $ID, $post ){ if ( ! function_exists( 'f

我正在使用插件,下面有一段代码,用于在发布帖子时向帖子作者发送消息,它工作正常,但每次更新帖子时仍会发送消息!我怎么能阻止它

另一点是如何向所有注册用户发送相同的消息

add_action( 'publish_post', 'fep_cus_user_publish_send_messaage', 10, 2 );

function fep_cus_user_publish_send_messaage( $ID, $post ){

    if ( ! function_exists( 'fep_send_message' ) )
    return;

    $message = [];

    $message['message_to_id'] = $post->post_author; // Post author ID. 
    $name = get_the_author_meta( 'display_name', $post->post_author );
    $title = $post->post_title;
    $permalink = get_permalink( $ID ); 
    $message['message_title'] = sprintf( 'Published: %s', $title );
    $message['message_content'] = sprintf ('Congratulations, %s! Your article “%s” has been published.', $name, $title );
    $message['message_content'] .= sprintf( 'View: %s', $permalink );
    $message['message_content'] .= sprintf( 'This is an automatic message, to let you know your post is published, and qualified for our quality standard!' );
    $override = array('post_author' => 1);//change with message sender id  


    // Send message
    fep_send_message( $message, $override );  

}
使用此方法:

 add_action( 'publish_post', 'fep_cus_user_publish_send_messaage', 10, 2 );

    function fep_cus_user_publish_send_messaage( $ID, $post ){

        if ( ! function_exists( 'fep_send_message' ) )
        return;


    //Check Send
    $send_email = get_post_meta( $post->ID, 'fep_send_email', true );
    if ( ! empty( $send_email ) ) return;


        $message = [];

        $message['message_to_id'] = $post->post_author; // Post author ID. 
        $name = get_the_author_meta( 'display_name', $post->post_author );
        $title = $post->post_title;
        $permalink = get_permalink( $ID ); 
        $message['message_title'] = sprintf( 'Published: %s', $title );
        $message['message_content'] = sprintf ('Congratulations, %s! Your article “%s” has been published.', $name, $title );
        $message['message_content'] .= sprintf( 'View: %s', $permalink );
        $message['message_content'] .= sprintf( 'This is an automatic message, to let you know your post is published, and qualified for our quality standard!' );
        $override = array('post_author' => 1);//change with message sender id  

    //Set Post Meta
    update_post_meta( $post->ID, 'fep_send_email', '1' );

        // Send message
        fep_send_message( $message, $override );  

    }

谢谢@Mehrshad的回答,非常感谢,但是我怎么能检查帖子之前是否已经发布?第二点呢,向所有注册用户发送消息?只有在帖子创建时才会创建Meta,因此Meta的存在意味着发布帖子。第二次,你可以添加新的值,例如,2。如果你不明白,我会给你代码。现在我明白了,谢谢兄弟,有没有办法像我们在fep_send_message中那样通知所有用户,当然不包括作者,因为我们不需要再通知他两次。