Add listing approval messages to Directory Press

I recently did a project that required Directory Press for a vendor directory. The DIrectory press system sends out emails for various site events but was lacking in one area. The site required that all listings that are submitted must be approved and published be an administrator. This also required an email to be sent to the post author which is something that Directory Press did not facilitate.

In order to sent the post author a message when their directory listing was published I had to add this block to the functions.php in the theme.

function post_published_notification( $new_status, $old_status, $post ) {
if ( $old_status == 'publish' && $new_status != 'publish' ) {
$author = $post->post_author; /* Post author ID. */

$name = get_the_author_meta( 'display_name', $author );
$email = get_the_author_meta( 'user_email', $author );
$title = $post->post_title;
$permalink = get_permalink( $post );
$edit = get_edit_post_link( $post, '' );
$to[] = sprintf( '%s <%s>', $name, $email );
$subject = sprintf( 'Your Post %s has been published', $title );
$message = sprintf ('Congratulations, %s! Your post ā€œ%sā€ has been published. Please return to verify that your listing appears as you\'d like and make adjustments if necessary.' . "\n\n", $name, $title );
$message .= sprintf( 'View and edit if necessary: %s', $permalink );
//add information here if you want to change the send from address
//$headers[] = 'From: Site Admin <info@example.com>';

wp_mail( $to, $subject, $message, $headers );
}
}
add_action( 'transition_post_status', 'post_published_notification', 10, 3 );

Be Sociable, Share!

Published by

Chris Malpass

I'm a web developer, photographer, casual gamer, and technophile from Virginia, USA.