php - WordPress:当帖子从 wp admin 永久删除时,哪个钩子起作用
问题描述
我正在尝试创建一个功能,该功能会在帖子被永久删除而不是被删除时触发,并且我会直接永久地从 wp admin 中删除所有帖子!
它正在工作,但有时会发送一个通知,有时会发送两个通知,有时会同时发送所有通知!
我更新帖子时有时也会触发!
我如何确保每个帖子状态只发送一个通知,并且只有在我永久删除帖子时才有效?
function deleted_post_notify_author( $post ) {
global $post;
$post = get_post($post->ID);
$author = $post->post_author;
$author_name = get_the_author_meta( 'display_name', $author );
$link = '#';
$image = '/images/sad-icon-01.svg';
if( current_user_can('administrator')) {
if( $post->post_status == 'pending' ) {
$title = '<strong>'.$author_name.'</strong> ' . __('We are sorry to inform you that your artwork has been declined', 'dw-notifications'). ' <strong>'.$post->post_title.'</strong>';
} elseif ( $post->post_status == 'publish' ) {
$title = '<strong>'.$author_name.'</strong> ' . __('We are sorry to inform you that your artwork has been deleted because did not reached after 4 days 100 views at least', 'dw-notifications'). ' <strong>'.$post->post_title.'</strong>';
} else {
$title = '<strong>'.$author_name.'</strong> ' . __('We are sorry to inform you that all draft posts will be delete. if you want to publish your project click submit for review', 'dw-notifications'). ' <strong>'.$post->post_title.'</strong>';
}
$notif = array('title'=>$title, 'link' => $link, 'image' => $image);
dwnotif_add_notification($author, $notif);
}
}
add_action( 'after_delete_post', 'deleted_post_notify_author' );
解决方案
推荐阅读
- django - 本地 -> Github 工作 | 本地-> Heroku 不工作
- javascript - 更新 Javascript 中的按钮
- python - 元素树无法访问没有命名空间的元素
- javascript - 使用 jquery.inline-edit.js 对 Textarea 进行内联编辑 - 获取 id 并保存
- python - f.readlines():如何在没有额外数字的情况下打印
- powerbi - 首次响应时间计算
- r - R - 以变量为条件的两行之间的差异
- c++ - OpenGL 调试上下文警告 - “将使用 VIDEO 内存作为缓冲区反对的来源
- python - 如何使用 websocket 客户端 python 发送二进制数据使用 WebSocketApp(不是 create_connection)
- python - 游戏 AI 一方面很强大,另一方面在井字游戏中变得愚蠢