CGArtZone
asked 3 months ago

Hello,

I don’t know why DW Notifications stopped working when a new post is published, after the last WordPress update!
I created this snippet to send a custom new post publish between followers/following users, and It was working perfectly without any problems!
But after the last WordPress update Stopped 🙁 
There are any explanation, Thanks.
Snippet here : https://jsfiddle.net/gbk8hde1/

3 Answers
DominicStaff
answered 3 months ago

Please send me username & password of your site for further checking.

Adham Mohamed
replied 3 months ago

Hello, Which email can i send to you?

Dominic Staff
replied 3 months ago

You can use the private option under the answer box.
See the screenshot: http://prntscr.com/n40hr8

DominicStaff
answered 3 months ago

We have checked and see that the plugin still work fine with new Editor. 
About the filter, you can add the following code to the functions.php file.

add_filter('dwnotif_insert_wp_post_to', 'custom_dwnotif_insert_wp_post_to', 10, 3);
function custom_dwnotif_insert_wp_post_to($to, $post_ID, $post){
if($post->post_author){
$user = get_userdata( $post->post_author );
$user_roles = $user->roles;
if ( in_array( 'administrator', $user_roles ) ) {
   return 'all';
}
}
return false;
}
Adham Mohamed
replied 3 months ago

Thanks so much it work 🙂
But please I need you to think about make DW Notifications plugin to push notifications on Desktop and mobile, I really can’t imagine what will happen if your plugin working to push Notifications! It will be the best plugin ever for WordPress, Thank you again & Regards.

Dominic Staff
replied 3 months ago

Thank for your feedback. We will check and discuss about it.

Adham Mohamed
replied 3 months ago

Hello, Can I ask another question please.
I’m trying to create a function that fires whenever a post is deleted permanently not trashed, and I deleting all the posts from wp admin directly and permanently!

it’s working but sometimes sends one notification, sometimes two and sometimes sends all of them at the same time!

also sometimes fires when I updating the post!!

How can i be sure to send only one notification for each post status, and working only when I deleted the post permanently?

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 = ‘https://www.cgartzone.com/submission-rules’;
$image = ‘https://www.cgartzone.com/wp-content/themes/hitmag-child/assets/images/sad-icon-01.svg’;

if( current_user_can(‘administrator’)) {

if( $post->post_status == ‘pending’ ) {

$title = ‘‘.$author_name.’ ‘ . __(‘We are sorry to inform you that your artwork has been declined’, ‘dw-notifications’). ‘ ‘.$post->post_title.’‘;

} elseif ( $post->post_status == ‘publish’ ) {

$title = ‘‘.$author_name.’ ‘ . __(‘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’). ‘ ‘.$post->post_title.’‘;

} else {

$title = ‘‘.$author_name.’ ‘ . __(‘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’). ‘ ‘.$post->post_title.’‘;

}
$notif = array(‘title’=>$title, ‘link’ => $link, ‘image’ => $image);
dwnotif_add_notification($author, $notif);
}
}
add_action( ‘after_delete_post’, ‘deleted_post_notify_author’ );

DominicStaff
answered 3 months ago

You can use the following code: 
function deleted_post_notify_author( $post_id ) {
 
 
$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’;
 
if( current_user_can(‘administrator’)) {
 
if( $post->post_status == ‘pending’ ) {
 
$title = $author_name.’ ‘ . __(‘We are sorry to inform you that your artwork has been declined’, ‘dw-notifications’). ‘ ‘.$post->post_title;
 
} elseif ( $post->post_status == ‘publish’ ) {
 
$title = $author_name.’ ‘ . __(‘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’). ‘ ‘.$post->post_title;
 
} else {
 
$title = $author_name.’ ‘ . __(‘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’). ‘ ‘.$post->post_title;
 
}
 
$notif = array(‘title’=>$title, ‘link’ => $link, ‘image’ => $image);
dwnotif_add_notification($author, $notif);
}
}
add_action( ‘before_delete_post’, ‘deleted_post_notify_author’ );

Adham Mohamed
replied 3 months ago

Thanks so much brother, But it sending multiple notifications, I mean when i deleted a pending post! It sending multi title for pending and draft?
And if i deleted an published post sending all title at once! 🙁

Dominic Staff
replied 3 months ago

Please let me know detail about this issue.
Or you can try the following code: http://snippi.com/s/pbvlncm

Powered by DW Question & Answer Pro