我正试图创建一个函数,该函数会在帖子永久删除而不被删除时触发,并且我直接且永久地从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' );