我仅在删除已发布的帖子时才尝试创建通知,但是当我更新任何已发布的帖子时会触发通知吗?
我做错了!谢谢。
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' );
修改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' );