我试图只在删除已发布的帖子时创建通知,但当我更新任何已发布的帖子时会触发通知?
我做错了什么!谢谢
function deleted_published_post_notify_author( $post ) {
global $post;
$send_published = get_post_meta( $post->ID, \'published_send_once\', true );
if ( ! empty( $send_published ) ) return;
if( current_user_can(\'administrator\')) {
if( get_post_status($post) == \'publish\' ) {
$post = get_post($post->ID);
$author = $post->post_author;
$author_name = get_the_author_meta( \'display_name\', $author );
$link = \'https://www.cgartzone.com/submission-rules\';
$image = \'https://www.cgartzone.com/wp-content/themes/hitmag-child/assets/images/sad-icon-01.svg\';
$title = \'<strong>\'.$author_name.\'</strong> \' . __(\'We are sorry to inform you that your artwork has been deleted. We recommended you to re-read our rules or contact us for more informations\', \'dw-notifications\'). \' <strong>\'.$post->post_title.\'</strong>\';
$notif = array(\'title\'=>$title, \'link\' => $link, \'image\' => $image);
update_post_meta( $post->ID, \'published_send_once\', \'1\' );
dwnotif_add_notification($author, $notif);
}
}
}
add_action( \'before_delete_post\', \'deleted_published_post_notify_author\' );
Edit 1
我试图添加if ( wp_is_post_revision( $post ) ) return;
但什么都没有发生,当我更新发布的帖子时,如何避免此通知?它应该只有在我删除帖子的时候才会开火!请帮忙。function deleted_published_post_notify_author( $post ) {
global $post;
$send_published = get_post_meta( $post->ID, \'published_send_once\', true );
if ( ! empty( $send_published ) ) return;
if( current_user_can(\'administrator\')) {
if( get_post_status($post) == \'publish\' ) {
if ( wp_is_post_revision( $post ) )
return;
$post = get_post($post->ID);
$author = $post->post_author;
$author_name = get_the_author_meta( \'display_name\', $author );
$link = \'https://www.cgartzone.com/submission-rules\';
$image = \'https://www.cgartzone.com/wp-content/themes/hitmag-child/assets/images/sad-icon-01.svg\';
$title = \'<strong>\'.$author_name.\'</strong> \' . __(\'We are sorry to inform you that your artwork has been deleted. We recommended you to re-read our rules or contact us for more informations\', \'dw-notifications\'). \' <strong>\'.$post->post_title.\'</strong>\';
$notif = array(\'title\'=>$title, \'link\' => $link, \'image\' => $image);
update_post_meta( $post->ID, \'published_send_once\', \'1\' );
dwnotif_add_notification($author, $notif);
}
}
}
add_action( \'before_delete_post\', \'deleted_published_post_notify_author\' );
Edit 2
我将空垃圾桶返回到wp配置中的0。像这样的phpdefine(\'EMPTY_TRASH_DAYS\', 0);
那是因为我根本不需要保存它们!我需要使用此操作永久删除带有帖子附件的任何帖子的原始目的
add_action( \'before_delete_post\', function( $id ) {
$attachments = get_attached_media( \'\', $id );
foreach ($attachments as $attachment) {
wp_delete_attachment( $attachment->ID, \'true\' );
}
} );
我的艺术家博客,他们上传了更多图片,所以我删除了带有附件的帖子,以节省主机存储空间