Hi Thomas,
this function won’t add anything to the DB, it is designed to create and submit notifications on the fly, not store them.
There is a way to create a notification in the code and save it to the database, but I’m not sure if this is what you’re looking for.
Would you mind sharing your use case?
Sure,
I would like that users have the ability to create custom notifications on their profile based on chosen words.
Eg : The user choose ‘animal’ as custom notification. A notification is sent to the user every time ‘animal’ appears on a post, a news, … This notification can be viewed and edited by admin on the dashboard.
Oh, that’s nice thinking and a great use case! We plan to deliver the Subscriptions extension in the future, but at the moment you indeed need to code it.
In this case, I’d recommend storing the data in one place, ie User meta or somewhere in the central repository, and just use the mentioned function to send the notification. This might save you all the CRUD hassle of maintaining the data in two places.
You could store it as regular notifications, but those created programmatically will be mixed with those added manually, and I expect there will be lots of them.
In case you want to create the notification and store it, you’d do it like so: https://pastebin.com/Lm7yMXXf
Many thanks for your answer. Indeed, this method will need to maintain data in two places. Having reflected on that and for the V1, I’m going to use notifications created on the fly.
Hi Kuba,
I’m trying to use the automatic trigger testing as indicated here https://docs.bracketspace.com/notification/developer/snippets/general/automatic-trigger-testing. I get the email when a new post is added, but some informations are missing, like the id or the content of the post as you can see
on this copy/paste of the email :
News ID: 0
News permalink: https://***/news/notif-test-2/
News title: Notif test 2
News slug:
News content:
News content HTML:
...
Is it a plugin issue ?
Hmm, looks like the post might be a draft? The ID 0 is concerning, though.
May I ask which trigger produces this and what post are you testing? Is it a draft or otherwise “incomplete” entity?
The trigger that produced that notification was for a custom post type : post/news/published
I’ve also tried with post/page/updated, here’s the notif I’ve received :
Page ID: 0
Page permalink: https://***/test-4/
Page title: Test 44673
Page slug:
Page content:
Page content HTML:
Page excerpt: Test 43
Page status: publish
...
Those tests were done with all plugins deactivated and the twenty twenty theme.
I also tried the plugin/activated trigger, this is the notif I received :
Plugin name:
Plugin author name:
Plugin version:
Plugin website address:
Plugin activation date and time: 7 October 2022 12 h 15 min
WordPress version : 6.02
-
This reply was modified 3 years, 7 months ago by
djacksounds.
-
This reply was modified 3 years, 7 months ago by
djacksounds.
-
This reply was modified 3 years, 7 months ago by
djacksounds.
Thanks for the confirmation.
Does the same notification work if defined in admin via UI?
In the meantime, we’ll try to replicate this issue on our end.