Skip to content

Commit

Permalink
Send review moderation email to admin
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed May 13, 2015
1 parent 0aef556 commit 4311055
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions includes/class-wc-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class WC_Comments {
* Hook in methods.
*/
public static function init() {

// Rating posts
add_filter( 'preprocess_comment', array( __CLASS__, 'check_comment_rating' ), 0 );
add_action( 'comment_post', array( __CLASS__, 'add_comment_rating' ), 1 );
add_action( 'comment_moderation_recipients', array( __CLASS__, 'comment_moderation_recipients' ), 10, 2 );

// Clear transients
add_action( 'wp_update_comment_count', array( __CLASS__, 'clear_transients' ) );
Expand Down Expand Up @@ -197,11 +197,24 @@ public static function add_comment_rating( $comment_id ) {
if ( ! $_POST['rating'] || $_POST['rating'] > 5 || $_POST['rating'] < 0 ) {
return;
}

add_comment_meta( $comment_id, 'rating', (int) esc_attr( $_POST['rating'] ), true );
}
}

/**
* Modify recipient of review email.
* @return array
*/
public static function comment_moderation_recipients( $emails, $comment_id ) {
$comment = get_comment( $comment_id );

if ( $comment && 'product' === get_post_type( $comment->comment_post_ID ) ) {
$emails = array( get_option( 'admin_email' ) );
}

return $emails;
}

/**
* Clear transients for a review.
* @param int $post_id
Expand Down

0 comments on commit 4311055

Please sign in to comment.