首页 > 解决方案 > 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' );

标签: phpwordpresspostnotificationshook

解决方案


推荐阅读