根据邮件内容查找,可以定位留言审核发送的函数位于:
wp-includes/pluggable.php
函数名为:
wp_notify_moderator
通过搜索了解到,这个函数是插件API,支持插件完整劫持。
修改留言审核的邮件格式的方法如下:
找个自己装的很久不更新的插件,修改插件的php文件,置入wp_notify_moderator函数,并修改其中的格式为自己所需的格式。
之后就会自动生效了。
示例代码:
function wp_notify_moderator( $comment_id ) {
global $wpdb;
$maybe_notify = get_option( 'moderation_notify' );
$maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_id );
if ( ! $maybe_notify ) {
return true;
}
$comment = get_comment( $comment_id );
$post = get_post( $comment->comment_post_ID );
$user = get_userdata( $post->post_author );
$emails = array( get_option( 'admin_email' ) );
if ( $user && user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) {
if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) {
$emails[] = $user->user_email;
}
}
$switched_locale = switch_to_locale( get_locale() );
$comment_author_domain = @gethostbyaddr( $comment->comment_author_IP );
$comments_waiting = $wpdb->get_var( "SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'" );
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
$comment_content = wp_specialchars_decode( $comment->comment_content );
switch ( $comment->comment_type ) {
case 'trackback':
$notify_message = sprintf( __( 'A new trackback on the post "%s" is waiting for your approval' ), $post->post_title ) . "rn";
$notify_message .= get_permalink( $comment->comment_post_ID ) . "rnrn";
$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "rn";
$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "rn";
$notify_message .= __( 'Trackback excerpt: ' ) . "rn" . $comment_content . "rnrn";
break;
case 'pingback':
$notify_message = sprintf( __( 'A new pingback on the post "%s" is waiting for your approval' ), $post->post_title ) . "rn";
$notify_message .= get_permalink( $comment->comment_post_ID ) . "rnrn";
$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "rn";
$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "rn";
$notify_message .= __( 'Pingback excerpt: ' ) . "rn" . $comment_content . "rnrn";
break;
default: // Comments
$notify_message = "留言内容:({$comment_content})待审核。rn";
$notify_message .= "博客链接:".get_permalink( $comment->comment_post_ID )."rn";
$notify_message .= sprintf( __( '用户名: %1$s (%2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "rn";
$notify_message .= sprintf( __( '邮箱: %s' ), $comment->comment_author_email ) . "rn";
break;
}
$notify_message .= sprintf( __( '通过: %s' ), admin_url( "comment.php action=approve&c={$comment_id}#wpbody-content" ) ) . "rn";
if ( EMPTY_TRASH_DAYS ) {
$notify_message .= sprintf( __( '丢弃: %s' ), admin_url( "comment.php action=trash&c={$comment_id}#wpbody-content" ) ) . "rn";
} else {
$notify_message .= sprintf( __( '删除: %s' ), admin_url( "comment.php action=delete&c={$comment_id}#wpbody-content" ) ) . "rn";
}
$notify_message .= sprintf( __( 'Spam: %s' ), admin_url( "comment.php action=spam&c={$comment_id}#wpbody-content" ) ) . "rn";
$notify_message .= sprintf(
_n(
'Currently %s comment is waiting for approval. Please visit the moderation panel:',
'Currently %s comments are waiting for approval. Please visit the moderation panel:',
$comments_waiting
),
number_format_i18n( $comments_waiting )
) . "rn";
$notify_message .= admin_url( 'edit-comments.php comment_status=moderated#wpbody-content' ) . "rn";
$subject = "{$post->post_title} 有留言待审核";
$message_headers = '';
$emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id );
$notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id );
$subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id );
$message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id );
foreach ( $emails as $email ) {
@wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
}
if ( $switched_locale ) {
restore_previous_locale();
}
return true;
}
如您从本文得到了有价值的信息或帮助,请考虑扫描文末二维码捐赠和鼓励。
如本文对您有用,捐赠和留言 将是对我最好的支持~(捐赠可转为站内积分)
如愿意,请向朋友推荐本站,谢谢。
尊重他人劳动成果。转载请务必附上原文链接,我将感激不尽。
留言