Skip to content

Instantly share code, notes, and snippets.

@1naveengiri
Created December 4, 2019 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1naveengiri/3c2d13f064a1d584af86133eab9a6f2a to your computer and use it in GitHub Desktop.
Save 1naveengiri/3c2d13f064a1d584af86133eab9a6f2a to your computer and use it in GitHub Desktop.
/**
* code to trigger comment email on comment submission.
*/
add_action( 'init', 'gd_custom_comment_post' );
function gd_custom_comment_post() {
remove_action( 'comment_post', 'geodir_new_comment_notify_postauthor', 99999, 1 );
add_filter( 'geodir_should_notify_comment_author', 'geodir_should_notify_comment_author_custom_callback', 10, 2);
add_filter( 'geodir_should_notify_listing_author', 'geodir_should_notify_listing_author_custom_callback', 10, 2 );
add_action( 'comment_post', 'geodir_custom_notify_on_comment_approved', 99999, 1 );
}
function geodir_should_notify_comment_author_custom_callback( $notify, $comment_id ){
return true;
}
function geodir_should_notify_listing_author_custom_callback( $notify, $comment_id ){
return true;
}
function geodir_custom_notify_on_comment_approved( $comment_ID ){
$comment = get_comment( $comment_ID );
if ( ! ( ! empty( $comment->comment_post_ID ) && geodir_is_gd_post_type( get_post_type( $comment->comment_post_ID ) ) ) ) {
return;
}
$notify_comment_author = geodir_should_notify_comment_author( $comment );
$notify_listing_author = geodir_should_notify_listing_author( $comment );
update_option('testme5', $notify_comment_author);
update_option('testme6', $notify_listing_author);
if ( ! ( $notify_comment_author || $notify_comment_author ) ) {
return;
}
// Notify to comment author
if ( $notify_comment_author ) {
update_comment_meta( $comment->comment_ID, 'gd_comment_author_notified', current_time( 'timestamp', 1 ) );
GeoDir_Email::send_owner_comment_approved_email( $comment );
}
// Notify to listing author
if ( $notify_listing_author ) {
update_comment_meta( $comment->comment_ID, 'gd_listing_author_notified', current_time( 'timestamp', 1 ) );
GeoDir_Email::send_author_comment_approved_email( $comment );
}
return $comment_ID;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment