前端评论管理

为管理员在前台评论中添加“删除”和“标识为垃圾”链接,无需进入后台即可管理评论。

插件安装

在 wp-content/plugins 目录下创建一个 wpexp-qdplgl.php 文件,将下方代码复制到文件里保存,然后在 WordPress 后台启用该插件,回到前端查看就会出现删除和标识为垃圾这两个按钮。

<?php
/*
Plugin Name: WPEXP - 前端评论管理
Plugin URI: https://wpexp.cn/plugins/qdplgl
Description: 前端评论管理 - 为管理员在前台评论中添加“删除”和“标识为垃圾”链接。
Version: 1.0
Author: wpexp
Author URI: https://wpexp.cn/
License: GPL2
Text Domain: wpexp-qdplgl
Domain Path: /languages
*/

// 防止直接访问
if (!defined('ABSPATH')) {
    exit;
}

/**
 * WordPress 前台评论添加“删除”和“标识为垃圾”链接(仅限管理员)
 */
function wpexp_comment_manage_link($link, $comment_id, $status) {
    // 检查是否为管理员
    if (current_user_can('administrator')) {
        $delete_url = admin_url("comment.php?action=cdc&c=" . $comment_id);
        $spam_url = admin_url("comment.php?action=cdc&dt=spam&c=" . $comment_id);

        $link .= ' | <a href="' . esc_url($delete_url) . '" title="' . __('删除评论', 'wpexp-qdplgl') . '">删除</a>';
        $link .= ' | <a href="' . esc_url($spam_url) . '" title="' . __('标识为垃圾', 'wpexp-qdplgl') . '">标识为垃圾</a>';
    }
    return $link;
}
add_filter('edit_comment_link', 'wpexp_comment_manage_link', 99, 3);