ult:
/* translators: %1$s is replaced with the post title */
$this->message = sprintf( __( 'A new comment on the post "%1$s" is waiting for your approval:', 'yoast-comment-hacks' ), '' . esc_html( $this->post->post_title ) . '' ) . '
';
break;
}
$this->add_comment_basics();
$this->comment_moderation_actions();
$this->message .= ' | ' . sprintf( '%2$s', $this->comment->comment_author_IP, __( 'Whois', 'yoast-comment-hacks' ) );
$this->message .= '
';
$this->get_moderation_msg();
return $this->wrap_message( $this->message );
}
/**
* Adds the basics of the email.
*/
private function add_comment_basics() {
$this->add_author_line();
$this->add_url_line();
$this->message .= '
';
$this->add_content_line();
}
/**
* Adds the author line to the message.
*/
private function add_author_line() {
if ( '' === $this->comment->comment_type ) {
/* translators: %1$s is replaced with the comment author's name, %2$s is replaced with the comment author's email */
$this->message .= sprintf( __( 'Author: %1$s (%2$s)', 'yoast-comment-hacks' ), esc_html( $this->comment->comment_author ), '' . esc_html( $this->comment->comment_author_email ) . '' ) . '
';
}
else {
/* translators: %1$s is replaced with the website doing the ping or trackback */
$this->message .= sprintf( __( 'Website: %1$s', 'yoast-comment-hacks' ), esc_html( $this->comment->comment_author ) ) . '
';
}
}
/**
* Adds the content line to the message.
*/
private function add_content_line() {
if ( '' === $this->comment->comment_type ) {
$this->message .= __( 'Comment:', 'yoast-comment-hacks' );
}
else {
$this->message .= __( 'Excerpt:', 'yoast-comment-hacks' );
}
$this->message .= '
' . wpautop( $this->comment->comment_content ) . '
';
}
/**
* Adds the URL line to the message.
*/
private function add_url_line() {
if ( isset( $this->comment->comment_author_url ) && '' !== $this->comment->comment_author_url ) {
/* translators: %s is replaced with the URL */
$this->message .= sprintf( __( 'URL: %s', 'yoast-comment-hacks' ), '' . esc_html( $this->comment->comment_author_url ) . '' ) . '
';
}
}
/**
* Wraps the message in some styling.
*
* @return string
*/
private function wrap_message() {
return '
' . $this->message . '
';
}
/**
* Sets up class variables used with all emails.
*
* @param int $comment_id The comment we're setting up variables for.
*/
private function setup_data( $comment_id ) {
$this->comment_id = $comment_id;
$this->comment = get_comment( $this->comment_id );
$this->post = get_post( $this->comment->comment_post_ID );
if ( 'comment' === $this->comment->comment_type ) {
$this->comment->comment_type = '';
}
}
/**
* Adds a sentence about the number of comments awaiting moderation.
*/
private function get_moderation_msg() {
global $wpdb;
$comments_waiting = $wpdb->get_var( "SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'" );
if ( $comments_waiting > 1 ) {
$comments_waiting--;
/* translators: %s is replaced with the number of comments waiting for approval */
$this->message .= sprintf( __( 'Currently this and %s other comments are waiting for approval.', 'yoast-comment-hacks' ), number_format_i18n( $comments_waiting ) );
$this->message .= ' ';
/* translators: %1$s and %2$s are replaced with the HTML for a link to the moderation panel */
$this->message .= sprintf( __( 'Please visit the %1$smoderation panel%2$s.', 'yoast-comment-hacks' ), '', '' ) . '
';
}
}
/**
* Returns a string containing comment moderation links.
*/
private function comment_moderation_actions() {
$actions = array(
'approve' => __( 'Approve', 'yoast-comment-hacks' ),
'spam' => __( 'Spam', 'yoast-comment-hacks' ),
'trash' => __( 'Trash', 'yoast-comment-hacks' ),
'editcomment' => __( 'Edit', 'yoast-comment-hacks' ),
);
$this->comment_action_links( $actions );
}
/**
* Returns a string containing comment action links.
*/
private function comment_notification_actions() {
$actions = array(
'spam' => __( 'Spam', 'yoast-comment-hacks' ),
'trash' => __( 'Trash', 'yoast-comment-hacks' ),
'editcomment' => __( 'Edit', 'yoast-comment-hacks' ),
);
$this->comment_action_links( $actions );
}
/**
* Add action links to the message
*
* @param array $actions The array of actions we're adding our action for.
*/
private function comment_action_links( $actions ) {
$links = '';
foreach ( $actions as $action => $label ) {
$links .= $this->comment_action_link( $label, $action ) . ' | ';
}
$links = rtrim( $links, '| ' );
$this->message .= $links;
}
/**
* Creates a comment action link.
*
* @param string $label The label for the comment action link.
* @param string $action The action we're going to add.
*
* @return string
*/
private function comment_action_link( $label, $action ) {
$url = admin_url( sprintf( 'comment.php?action=%s&c=%d', $action, $this->comment_id ) );
return sprintf( '%2$s', esc_url( $url ), esc_html( $label ) );
}
}