Skip to content

Instantly share code, notes, and snippets.

@carstingaxion
Last active August 29, 2024 08:39
Show Gist options
  • Save carstingaxion/3426a677aa426eb24922dac98178d296 to your computer and use it in GitHub Desktop.
Save carstingaxion/3426a677aa426eb24922dac98178d296 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: GatherPress RSVP Action
Description: Sends an email, whenever someone sends an RSVP
Version: 0.0.1
Author: Carsten Bach
*/
/**
* Fires immediately after a comment is inserted into the database.
*
* @see https://developer.wordpress.org/reference/hooks/wp_insert_comment/
*
* @param int $id The comment ID.
* @param \WP_Comment $comment Comment object.
*/
function gatherpress_rsvp_on_wp_insert_comment_787( int $id, \WP_Comment $comment ): void {
if ( 'gatherpress_rsvp' !== $comment->comment_type ) {
return;
}
$mail = get_option( 'admin_email' );
$attendee = get_userdata( $comment->user_id );
$subject = sprintf(
'New RSVP by: %s',
$attendee->display_name
);
$event_title = get_the_title( $comment->comment_post_ID );
$message = sprintf(
'%s sent an RSVP for %s.',
$attendee->display_name,
$event_title
);
wp_mail( $mail, $subject, $message );
}
add_action( 'wp_insert_comment', 'gatherpress_rsvp_on_wp_insert_comment_787', 10, 2 );
@carstingaxion
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment