默认情况下,WordPress前台评论只有“编辑”链接,如果我们要将评论删除或标识为垃圾,需要进入后台再操作,非常不方便,下面我们就来给 WordPress 前台评论添加“删除”和“标识为垃圾”链接。

将下面的代码添加到当前主题的 functions.php 文件即可:
/**
* WordPress 前台评论添加“删除”和“标识为垃圾”链接
* https://www.wpdaxue.com/add-delete-spam-links-to-comments.html
*/
function comment_manage_link($id) {
global $comment, $post;
$id = $comment->comment_ID;
if(current_user_can( 'moderate_comments', $post->ID )){
if ( null === $link ) $link = __('编辑');
$link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( '编辑评论' ) . '">' . $link . '</a>';
$link = $link . ' | <a href="'.admin_url("comment.php?action=cdc&c=$id").'">删除</a> ';
$link = $link . ' | <a href="'.admin_url("comment.php?action=cdc&dt=spam&c=$id").'">标识为垃圾</a>';
$link = $before . $link . $after;
return $link;
}
}
add_filter('edit_comment_link', 'comment_manage_link'); |
/**
* WordPress 前台评论添加“删除”和“标识为垃圾”链接
* https://www.wpdaxue.com/add-delete-spam-links-to-comments.html
*/
function comment_manage_link($id) {
global $comment, $post;
$id = $comment->comment_ID;
if(current_user_can( 'moderate_comments', $post->ID )){
if ( null === $link ) $link = __('编辑');
$link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( '编辑评论' ) . '">' . $link . '</a>';
$link = $link . ' | <a href="'.admin_url("comment.php?action=cdc&c=$id").'">删除</a> ';
$link = $link . ' | <a href="'.admin_url("comment.php?action=cdc&dt=spam&c=$id").'">标识为垃圾</a>';
$link = $before . $link . $after;
return $link;
}
}
add_filter('edit_comment_link', 'comment_manage_link');
注意看上面代码的第 8 行,设定了只有拥有 ‘moderate_comments’ 权限的用户(编辑、管理员)才可以看到“删除”和”标识为垃圾“这两个链接。如果你要限定其他用户级别,请参考 Roles and Capabilities 来修改 ‘moderate_comments’为其他权限即可。
来源:
https://www.wpdaxue.com/add-delete-spam-links-to-comments.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_33144.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57