Notify real time wordpress - wordpress

I have a wordpress site and I want to make a notify function. My issue is how to show the notification in realtime?
For example, when someone post a comment, it will show a popup for the owner immediately.
I am thinking of using ajax and recalling the request after x seconds but I don't know if this is a good idea.

For triggering a comment is done in WordPress, you can use this hook.
add_action( 'comment_post', 'show_message_function', 10, 2 );
function show_message_function( $comment_ID, $comment_approved ) {
//function logic goes here for showing your popup
}
Hope this will helps you.
for, more information.
Plugin API/Action Reference/comment post
Notification
Better Notifications for WordPress

Related

Send WooCommerce Email on Address Save using woocommerce_email_actions

I've been struggling with this for a couple days now and have been through every post/comment/discussion/etc... I could find trying to find a working solution.
I want to send an email via a custom class that extends WC_Email whenever a woocommerce user updates their address. I've found various resources explaining how to create custom wc emails (skyverge was most useful) and I have successfully done that. I have a plugin that adds a custom email in WP-Admin->WooCommerce->Settings->Emails.
If I use an action that is already part of the woocommerce_email_actions such as add_action( 'woocommerce_order_status_failed_to_processing_notification', array( $this, 'trigger' ) ); and manually change the order status in the backend everything works just fine.
Problem is I want to use add_action( 'woocommerce_customer_save_address', array( $this, 'trigger' ) ); and unfortunately it never fires.
Based on some other threads I've tried adding the following to my main plugin file
function new_woocommerce_email_actions( $actions ){
$actions[] = 'woocommerce_customer_save_address';
return $actions;
}
add_filter( 'woocommerce_email_actions', 'new_woocommerce_email_actions' );
Supposedly this should allow me to use the action in my custom class, but no luck. I've also tried adding other actions without any success. For instance using the filter to add woocommerce_order_status_cancelled won't fire when manually changing the order to cancelled. I'm struggling to figure out why this isn't working and most of the the threads I've found are 2+ years old and dead, so here I am. Any help or pointers would be greatly appreciated.
Posting as an answer in case others are trying to get this functionality working.
I found this article from Tyche Softwares after extensive digging and was able to create a plugin that will send a custom WC_Email whenever a customer updates their address information.
I'm still not 100% as to why the add_filter('woocommerce_email_actions'... wasn't working, and if anyone can tell me why I'd still be interested.
This plugin works by calling a custom action defined in my extended WC_Email class via do_action whenever the existing woocommerce_customer_save_address action happens.

call a function (actually an API call) whenever user place order

I need to call a function (actually an API call) whenever user place order(i.e after checkout).
I searched woo-commerce doc (https://docs.woothemes.com/wc-apidocs/hook-docs.html) but could not find proper hook.
Already i have wasted lot of time for this and client need this to be done.
If anyone can suggest anything then it will very helpful. I am new to woo-commerce.
Thanks for your time.
In your theme's function.php or in your custom plugin Place this:
add_action('woocommerce_payment_complete', 'my_function');
function my_function(){
// Whatever I want to do when payment is completed
// Like api call to external server etc
}
This action triggers when payment is completed. There are other actions available instead of woocommerce_payment_complete like woocommerce_order_status_pending , woocommerce_thankyou etc.
Hope that helps.

Notify email when someone's posted a review in WooCommerce

I noticed that Woocommerce's reviews are managed through Wordpress Comments. But why is it that Wordpress isn't notifying my email when someone posted a review to a product. I have set the "Email me whenever anyone posted a comment".
Is this function available in Woocommerce or i'm missing something?
Please advise, thanks everyone!
Regards, Ven
By default Wordpress sends a notification to the author of the product/post (the person who created the product in your instance). The suggested site owner (settings > general) is not the recipient of these notifications. This is where the trouble might start. This author information is in Woocommerce hidden and is hard to figure out who that is in your user database. It might be that the original author of the product doesn't exist anymore, and especially if the original author has been deleted from the database and you didn't move the contents of that user to a new user.
The default comment notifications are produced in this Wordpress file: wp-includes/pluggable.php
Below is a trick to override the recipient for the comment/review notification, put this code in your child-theme's functions.php and change the part example#example.com to your desired email recipient and you will receive a notification every time someone adds a comment/review to your site.
function new_comment_moderation_recipients( $emails, $comment_id ) {
return array( 'example#example.com' );
}
add_filter( 'comment_moderation_recipients', 'new_comment_moderation_recipients', 24, 2 );
add_filter( 'comment_notification_recipients', 'new_comment_moderation_recipients', 24, 2 );
I tested it and it works.
On the Wordpress Dashboard navigate to Settings > General and the Email address listed here is where you will get notifications.

WordPress: Stop spam posts programmatically

I have an image sharing site built on WordPress and recently I've had a lot of bots registering a user and creating a spam post with links to various sites.
After installing WP-reCAPTCHA the numbers have reduced but there are still 'attacks' every hour or so.
I'm trying to handle this programmatically now, by hooking into wp_insert_post_data (which is called whenever a post/revision is saved). I inspect the post data and if it contains a link I remove the post's content and set the status to draft so that it isn't published.
But it's still a nuisance to delete spam users and posts from the back end.
Is there a better hook I can use to stop the saving of the post even happening? i.e. can I reject the call to save the post?
Here is the code I'm currently using:
function block_spam_posts($data, $postarr) {
// if the post contains a link, set it to draft status
$post_content = $data['post_content'];
if (strpos($post_content,'http') !== false) {
$data['post_content'] = 'Post data removed by anti-spam measures.';
$data['post_status'] = 'draft';
}
}
add_filter('wp_insert_post_data', 'block_spam_posts',1,2);
Thanks for your help.
I found the answer here:
https://wordpress.stackexchange.com/questions/82354/how-can-i-hook-into-creating-a-new-post-and-execute-wp-die-before-the-post-is
I'm using the right hook. All I need to do is call wp_die() once the criteria for a spam post has been met.
Hope this helps others.

wordpress - catching save event with a plugin

i'm writing my first plugin for wordpress and i have some doubts regarding the hooks.
So i want an action to be executed when admin saves a post, and i'm using (inside a class):
add_action( 'save_post', array($this, 'save_post'));
function save_post(){
global $wp_query;
var_dump($wp_query);
}
the problem is that it prints the global variable when admin opens the "create a new post" and it doesn't when the user saves a post.
I want it to happen the other way around, but i can't find anything in the docs, and i'm completely alone here.
Any help? thanks
I think you're looking for the 'publish_post' action. There's also a 'draft_post' if you need it.

Resources