不是每次 post 更新都发送一次电子邮件

Send email once not every time post updated

我正在使用“Front End PM”插件,下面的代码片段用于在 post 作者的 post 发布时向其发送消息,它工作正常但仍在发送每次 post 更新时的消息!我怎么能阻止它?

还有一点就是如何向所有注册用户发送同一条消息?

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 );  

    }