Trying to hook into comment_post—fail!
-
Okay… so I’m a newb (I just learned about this forum at the Portland WordCamp last week).
My site is a directory, and all of the posts only have one author (me). Each post does have a contact email field—most of those (not all) have an email address in them.
When a comment is posted about one of the listings, I want the notice to go to the contact email, if there is one.
I’ve cludged together this code:
<?php
/**
* Plugin Name: TRT Custom Functions
* Description: code snippets to add trt-specific functionality.
* Version: 1.0
**/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
//// Send comment notifications to listings email contact address if it exists
function trt_custom_comment_notification($comment_id) {
// Get the comment details
$comment = get_comment($comment_id);
$post_id = $comment->comment_post_ID;
$post = get_post($post_id);
$meta_key = 'contact_email';
$meta_value = get_post_meta($post_id, $meta_key, true);
// Email to notify
if (!empty($meta_value)) {
$to = $meta_value;
} else {
$to = get_option('admin_email');
}
$subject = ‘People are commenting on’ . $post->post_title;
// Construct email message
$message = sprintf(
"A new customer comment has been posted about '%s'.\n\n" .
"Comment:\n%s\n\n" .
"You can view it here: %s\n",
$post->post_title,
$comment->comment_content,
get_comment_link($comment_id)
);
// Send the email
wp_mail($to, $subject, $message);
}
add_action('comment_post', ‘trt_custom_comment_notification', 10, 1);Not only doesn’t it work, it won’t activate (because it has a fatal error)!
What am I doing wrong?
Thanks!
–don
Viewing 12 replies - 1 through 12 (of 12 total)
Viewing 12 replies - 1 through 12 (of 12 total)
- You must be logged in to reply to this topic.