Email notification whenever a comment is created via WP REST API - ajax

I'm building a custom comment form for my Vue.js & WordPress Single Page Application theme and was able to post a comment via ajax POST request to the WP REST API. But I don't get any admin notifications on a new comment even the settings in Settings-->Reading are set to notify the admin each time a comment is created/added.
So how can I get email notifications on WP REST API comment creation?

For any reason the WP REST API team didn't use the function wp_new_comment whenever a comment is added/created. This function includes the comment_post action hook which, in turn, is used by WordPress to send admin notifications in wp-includes/default-filters.php.
Instead they've used the wp_insert_comment() function which is defined in wp-includes/comments.php and which also includes an action hook of the same name wp_insert_comment at the very end of the function. This hook we can use to trigger the notification function wp_new_comment_notify_moderator(). Just add the following snippet into your theme's / plugin's functions.php
add_action( 'wp_insert_comment', 'wp_new_comment_notify_moderator' );
see also:
https://core.trac.wordpress.org/ticket/40352
https://wordpress.org/support/topic/wp-api-comments-not-sending-notifications/#post-8987973

Related

Save data through the controller after an event has been fired in laravel

I'm allowing a user to upload a post which includes an image and some related information as well as select the promotion fee[bronze,silver or gold].In my /post controller i'm validating the request and then sending a request to another API[third party api for performing payments].The API takes the user phone number and the promotion fee selected and does the payment transaction.So i made the Transaction model[used to save details concerning the completed transaction]to dispatch a created event since i want to save the other post related information only if the payment is successful.
I've tried to create the listener for the TransactionCreatedEvent but i can't find a way to pass the post related data into the listener in order to save them. I also tried to use the closure by calling the listen method on the Event Facade inside the post controller to no avail.
Mh, i'm not quite sure if i undestood you question correctly, but in you case, you could either relate the Transaction with the post, or pass the Transaction and the Post Model to any event or to a job, and then do whatever you want with the data in the event handler or job

How to build external HTTPS webhook for Google Action builder

I want to build a simple conversation with a scene calling an external webhook :
https://ipaddress/Serveur_Cron.php?cmd=ActionOnGoogle
In action Builder, "Scene" tells me to link with a webhook name :
Action Builder Scene
but in the webhook tab I can give the https url, but not any name ?
What did I miss ?
How do i manage to call an external API from Actions Builder ???
First of all, you are right on your way. Just confused.
Now, It is asking you to name your webhook for the current scenario so that later you can take action according to that scenario.
A webhook can be called multiple times in different scenes.
It helps us to handle at backend like.
Let's say you have used webhook at three scenes named respectively
example1,
example2,
example3
Following code can be useful at your webhook
app.handle('example1'); // For 'A' actions
app.handle('example2'); // For 'B' actions
app.handle('example3'); // For 'C' actions
That is why it is asking to name it.
you can call external API(s) inside your webhook.

Stripe webhook for laravel

Please ask if you don't understand anything....I am creating stripe subscription payment. i need to handle stripe customer.subscription.deleted event. i have created a webhook for it in my laravel app. but the thing is whenever i send test data from stripe it shows webhook handled. but i am sending email whenever payment is unsuccessful and also logging this it is not showing in log or sending email. I am hosting my website for now using ngrok.. which is build in in laragon.
My controller method
use Laravel\Cashier\Http\Controllers\WebhookController;
class SubscriptionController extends WebhookController
{
public function handleCustomerSubscriptionDeleted($payload){
\Log::info("Webhook is working");
dd($payload);
}
}
my route file is like this
Route::get('/stripe/webhook','SubscriptionController#handleWebhook');
it is not showing in log file this neither it is sending email.
i am following this article please check if it is right way to do this??
Click here
I have added dd() here how does this webhook will be successful?

Alternate option for call a function in all controller in spring

I have a notification section in my user area in my project. For the users there is lot of pages actually and each page i need to show the notification on top but each page calling different controller function. So my question is there any option for me to get this notification list on each user pages without calling the same notification fetching function on all controller or on all request mapping function.

Joomla v1.6 - How & Where to set Custom Success Messages in Controller?

In Joomla! 1.6 Contact Form submission, I want to set a custom successful message, so that the front-end user can view that message after he submits the contact form.
There are 2 problems basically:-
I am using the default Contact Form component (com_contact), as provided by the Joomla! v1.6. But I am unable to find the proper area from where the contact form is submitted & the mail is being sent. So I need to know the page name & the method name of this component, firing the mail from the front-end.
How to set the custom messages (just like in the administrator panel) in the particular method of contact form component, to let the front-end user know that he has been able to successfully send the mail to the concerned staff?
Thanks in advance to all who can help.
To show Message
use $this->setMessage(JText::_('COM_YOURCOMPONENT_MESSAGE')); if you are in controller.
or use
JFactory::getApplication()->enqueueMessage(JText::_('COM_YOURCOMPONENT_MESSAGE'));
And Email is sent through JoomlaRoot / components / com_contact / controllers / contact.php
find the function submit(), the mailing code is written here.

Resources