Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save seventhqueen/aa0bcd3e51620ec7163c56a056365d6a to your computer and use it in GitHub Desktop.
Save seventhqueen/aa0bcd3e51620ec7163c56a056365d6a to your computer and use it in GitHub Desktop.
bbPress - send an auto-reply email to the bbPress topic author when a new topic is created
<?php
/**
* Send an auto-reply email to the bbPress topic author when a new topic is created
* @param int $topic_id The ID of this topic
* @param object $topic The object of this topic
* @return mixed
*/
function kleo_bbp_email_new_topic( $topic_id = 0, $topic ) {
// Bail if this isn't a topic
if ( $topic->post_type != 'topic' ) {
return;
}
$author_id = bbp_get_topic_author_id($topic_id);
$author_name = get_the_author_meta( 'display_name', $author_id );
$author_email = get_the_author_meta( 'user_email', $author_id );
$url = bbp_get_topic_permalink( $topic_id );
$headers = array();
$headers[] = 'Content-Type: text/html; charset=UTF-8';
$to = array();
$to[] = $author_email;
$message = "Hello {$author_name},<br>";
$message .= "This email is to alert you that your ticket titled <strong><a href='{$url}'>{$topic->post_title}</a></strong> has been created.<br><br>";
$message .= "If you believe this is an error or you are still needing assistance with this issue please contact us. <br>";
$message .= "Ticket URL: <a href='{$url}'>{$url}</a><br><br>";
$message .= "-----------<br>Do not reply to this email!";
wp_mail( $to, 'Your topic was successfully created', $message, $headers );
}
add_action( 'wp_insert_post', 'kleo_bbp_email_new_topic', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment