Last active
August 29, 2024 08:39
-
-
Save carstingaxion/3426a677aa426eb24922dac98178d296 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Author
carstingaxion
commented
Aug 29, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment