php - Wordpress - 如果 function_exists 使用 Front End PM 插件向用户发送消息
问题描述
我正在使用插件“前端 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
。
推荐阅读
- python - pyqt5 覆盖 dropEvent python
- node.js - 即使使用了 export 和 require 也无法在另一个 js 文件中返回值
- excel - VBA - 如何加快过滤过程
- laravel - 为什么在 Laravel 5.7.12 中将我的路由类型从 POST 更改为 GET 以注销?
- c# - 两个 Nuget 包引用了冲突的反应库
- angular - 如何将 Angular 应用程序与超过 1 个服务器连接?
- jmeter - 为什么我们在执行时在 blazemeter 中的 NonGUIDriver java.lang.IllegalArgumentException 中出现错误?
- postgresql - postgres - CASE 评估任何不需要确定结果的子表达式
- ios - Bundle id 以 `org` 开头
- kubernetes - 无法使用 NodePort 访问本地 kubernetes 集群中的服务