• Resolved kraigg

    (@kraigg)


    Hi there,

    I’m trying to customise the email notification that the administrator receives whenever there is a new forum topic or reply to moderate.

    I’d like to add the author’s name and the title of the topic it is being posted to. Can this be done?

    I modified line 280 in bbpressmoderation.php from:
    $message .= "'" . $post->post_content . "'\r\n\r\n";

    to this:
    $message .= $post->post_author . "posted in " . $post->topic_title . "(" . $post->author_title . "): '" . $post->post_content . "'\r\n\r\n";

    But it doesn’t seem to work. Am I doing something wrong?

    http://wordpress.org/extend/plugins/bbpressmoderation/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author ianhaycox

    (@ianhaycox)

    I don’t believe there are fields in $post called topic_title and author_title and the post_author is just an ID which you need to use to pass to get_userdata($id)

    I would suggest changing the code to:

    $message .= print_r($post, true) . "\r\n\r\n";

    then add a topic/reply that will be moderated and your notification email will have debug info from print_r() in it.

    To get the topic/reply title you may need to look at the post metadata but I’m not sure where bbPress stores that info.

    Ian.

    Thread Starter kraigg

    (@kraigg)

    Thanks Ian. I did what you said and added the print_r, which displays a list of available objects in the moderation email.

    I can now retrieve the topic/reply title by doing:
    $message .= $post->post_title;

    The only thing is I can’t retrieve is the post_author. I’m able to get the author ID by doing:
    $message .= $post->post_author;

    But I’m not able to convert the author ID into the author’s name using get_userdata($id). The error I get is “Catchable fatal error: Object of class WP_User could not be converted to string” when I try to do:
    $author_id = $post->post_author ;
    $author_name = get_userdata($author_id);

    I’m assuming it’s because one is a string and one is number.

    function notify_admin($post_id) {
    
    if (get_option(self::TD . 'notify')) {
    
    $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    $message  = sprintf(__('New topic/reply awaiting moderation on your site %s: %s', self::TD), $blogname, $blogurl) . "\r\n\r\n";
    
    /* Add body of topic/reply to email */
    $post = get_post($post_id);
    
    if ($post) {
    $author_id = $post->post_author ;
    $author_name = get_userdata($author_id);
    $message .= "<strong>The following content was posted:</strong>\r\n";
    $message .= "'" . $author_name . ":\r\n";
    $message .= "'" . $post->post_title . ":\r\n" . $post->post_content . "'\r\n\r\n";
    // $message .= print_r($post, true) . "\r\n\r\n";
    			}
    @wp_mail(get_option('admin_email'), sprintf(__('[%s] Moderation required', self::TD), $blogname), $message);
    		}
    	}
    Thread Starter kraigg

    (@kraigg)

    I think I’ve found a way to get the author name! This seems to work.

    Change my current code above to:

    function notify_admin($post_id) {
    
    if (get_option(self::TD . 'notify')) {
    
    $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    $message  = sprintf(__('New topic/reply awaiting moderation on your site %s: %s', self::TD), $blogname, $blogurl) . "\r\n\r\n";
    
    /* Add body of topic/reply to email */
    $post = get_post($post_id);
    
    if ($post) {
    $author_id = $post->post_author ;
    $author_name = get_userdata($author_id);
    $message .= "<strong>The following content was posted:</strong>\r\n";
    $message .= "Posted by " . $author_name->user_firstname . " " . $author_name->user_lastname . ":\r\n";
    $message .= "'" . $post->post_title . ":\r\n" . $post->post_content . "'\r\n\r\n";
    			}
    @wp_mail(get_option('admin_email'), sprintf(__('[%s] Moderation required', self::TD), $blogname), $message);
    		}
    	}

    Plugin Author ianhaycox

    (@ianhaycox)

    Glad you got it working.

    I have not checked, but for an anonymous user you may find that $author_id is 0 or null.

    Either way – I’ll merge in those changes for the next version and add a check for anonymous users just in case.

    Ian.

    Thread Starter kraigg

    (@kraigg)

    Thanks again for all your help, and for the great plugin. You rock!

    Plugin Author ianhaycox

    (@ianhaycox)

    Added the above to V1.4 of the plugin.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: bbPressModeration] Adding author and forum topic/reply to admin email notification’ is closed to new replies.