wordpress收费下载资源主题
wordpress付费下载资源插件

WordPress函数wp_notify_moderator详细用法教程解析

WordPress函数wp_notify_moderator用于向博客的管理员发送通知邮件,以便他们在有新评论时进行审核。下面是该函数的详细用法解析:

函数签名:

wp_notify_moderator( int $comment_id )

参数:
- `$comment_id`(必需):评论的ID。

返回值:
- 无。

使用示例:

function my_custom_notify_moderator( $comment_id ) {
// 获取评论对象
$comment = get_comment( $comment_id );

// 获取文章对象
$post = get_post( $comment->comment_post_ID );

// 获取管理员的电子邮件地址
$admin_email = get_option( 'admin_email' );

// 设置邮件主题
$subject = "[{$post->post_title}] New Comment Waiting for Moderation";

// 设置邮件内容
$message = "A new comment has been posted on your blog post: {$post->post_title}nn";
$message .= "Author: {$comment->comment_author}n";
$message .= "Email: {$comment->comment_author_email}n";
$message .= "URL: {$comment->comment_author_url}n";
$message .= "Comment: {$comment->comment_content}nn";
$message .= "You can moderate the comment here: ";
$message .= esc_url( get_edit_comment_link( $comment_id ) );

// 发送邮件
wp_mail( $admin_email, $subject, $message );
}
add_action( 'wp_set_comment_status', 'my_custom_notify_moderator', 10, 2 );

在上面的示例中,我们使用了`wp_set_comment_status`动作钩子,当评论的状态更改时,会触发`my_custom_notify_moderator`函数。该函数首先获取评论和文章对象,然后获取管理员的电子邮件地址。接下来,我们设置了邮件的主题和内容,最后使用`wp_mail`函数发送邮件。

请注意,`wp_notify_moderator`函数是在WordPress自动发送通知邮件之前调用的,因此我们可以使用它来自定义邮件的内容和格式。

0 个评论

定制开发
本站承接WordPress等系统建站仿站、二次开发、主题插件定制等开发服务
在线咨询
  • 请直接说明需求,勿问在否
    QQ:1-247-246-247

  • QQ一群:104228692(满)
  • QQ二群:64786792
在线咨询
本站承接WordPress建站仿站、二次开发、主题插件定制等PHP开发服务!

了解详情