我正在使用插件“ 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 );
}
答案 0 :(得分:1)
在适当的文本编辑器(如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('post_author' => 1);//change with message sender id
// Send message
fep_send_message( $message, $override );
}