Wordpress - 如果 function_exists 使用前端 PM 插件向用户发送消息

Wordpress - Send message to users if function_exists by using Front End PM plugin

我正在使用插件“Front End PM”并且我有下面的代码片段用于在作者发布帖子时向前端发送消息,但对我不起作用并且我得到错误“意外的' ' (T_STRING)”,所以问题在 [' '] 之间,但很抱歉我无法修复它。

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.' . "\n\n", $name, $title );
    $message['message_content'] .= sprintf( 'View: %s', $permalink );

    $override = array('post_author' => 1, //change with message sender id
        
    );

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

在适当的文本编辑器中编辑您的代码段,例如 sublime text, notepad++, Vim(仅举几例)。在某些行的后面,您有一些字符是从站点或非用于编写代码的工具中从格式不正确的代码块中复制的。如果您删除这些字符,您的代码将不会产生语法错误。

像这样的代码片段应该有效:

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.' . '\n\n', $name, $title );
    $message['message_content'] .= sprintf( 'View: %s', $permalink );
    $override = array('mgs_author' => 1);//change with message sender id  
    

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

编辑:post_author 已弃用并删除。请改用 mgs_author