Php Wordpress-使用前端PM插件向用户发送消息(如果函数_存在)

Php Wordpress-使用前端PM插件向用户发送消息(如果函数_存在),php,wordpress,email,author,Php,Wordpress,Email,Author,我正在使用插件,下面有一段代码,用于在发布作者的帖子时将消息发送到前端,但对我不起作用,并且出现了意外的“T_字符串”错误,因此介于[“”]之间的问题,但很抱歉,我无法修复它 添加“发布帖子”、“用户发布消息”10,2; 函数fep_cus_user_publish_send_消息$ID,$post{ 如果!函数_存在“fep_发送_消息” 回来 $message=[];   $message['message\u to\u id']=$post->post\u author;/*post a

我正在使用插件,下面有一段代码,用于在发布作者的帖子时将消息发送到前端,但对我不起作用,并且出现了意外的“T_字符串”错误,因此介于[“”]之间的问题,但很抱歉,我无法修复它

添加“发布帖子”、“用户发布消息”10,2; 函数fep_cus_user_publish_send_消息$ID,$post{ 如果!函数_存在“fep_发送_消息” 回来 $message=[];   $message['message\u to\u id']=$post->post\u author;/*post author id*/ $name=get_the_author_meta‘display_name’,$post->post_author; $title=$post->post\u title; $permalink=get_permalink$ID; $message['message_title']=sprintf'已发布:%s',$title; $message['message\u content']=sprintf'祝贺您,%s!您的文章“%s”已发布。\n\n,$name,$title; $message['message_content'].=sprintf'视图:%s',$permalink;
 $override=array'post_author'=>1,//使用消息发送者id进行更改
     ; //发送消息 fep_发送_消息$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;
    $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_作者已被弃用并删除。改用mgs_author。

您在哪一行收到错误?日志应该会告诉你。我在你的代码片段中没有看到任何语法错误。在这一行$message['message\u to\u id']=$post->post\u author;注意:删除该行后,第二行出现错误,依此类推!这很有趣。我复制了你的片段,后面有一个奇怪的未定义字符;删除整行,然后再重写那行?啊,是你自己发现的。你从别的地方复制代码了吗?