首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我可以删除表wp_comments来阻止任何人的评论吗?

我可以删除表wp_comments来阻止任何人的评论吗?
EN

Stack Overflow用户
提问于 2014-07-31 03:13:28
回答 3查看 238关注 0票数 1

我在网上有一个Wordpress网站。一些垃圾邮件发送者在我的Wordpress上发表了许多垃圾评论。我可以把wp_comments表放到我的Wordpress数据库中吗?我不想让任何人发表评论。当我删除wp_comments表时,Wordpress站点会崩溃吗?如果我删除wp_comments表,当有人在我的文章上写评论,然后点击发布它,在这种情况下,wordpress会崩溃吗?drop table wp_comments对我来说很好。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-08-01 21:26:39

这是我过去使用过的一段代码。它将重定向用户远离您的评论部分,并隐藏在您的后端的评论部分。选择您想要的片段,并将它们放在主题的functions.php文件中。

代码语言:javascript
复制
// Disable support for comments and trackbacks in post types
function df_disable_comments_post_types_support() {
    $post_types = get_post_types();
    foreach ($post_types as $post_type) {
        if(post_type_supports($post_type, 'comments')) {
            remove_post_type_support($post_type, 'comments');
            remove_post_type_support($post_type, 'trackbacks');
        }
    }
}
add_action('admin_init', 'df_disable_comments_post_types_support');

// Close comments on the front-end
function df_disable_comments_status() {
    return false;
}
add_filter('comments_open', 'df_disable_comments_status', 20, 2);
add_filter('pings_open', 'df_disable_comments_status', 20, 2);

// Hide existing comments
function df_disable_comments_hide_existing_comments($comments) {
    $comments = array();
    return $comments;
}
add_filter('comments_array', 'df_disable_comments_hide_existing_comments', 10, 2);

// Remove comments page in menu
function df_disable_comments_admin_menu() {
    remove_menu_page('edit-comments.php');
}
add_action('admin_menu', 'df_disable_comments_admin_menu');

// Redirect any user trying to access comments page
    function df_disable_comments_admin_menu_redirect() {
    global $pagenow;
    if ($pagenow === 'edit-comments.php') {
        wp_redirect(admin_url()); exit;
    }
}
add_action('admin_init', 'df_disable_comments_admin_menu_redirect');

// Remove comments metabox from dashboard
function df_disable_comments_dashboard() {
    remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
}
add_action('admin_init', 'df_disable_comments_dashboard');

// Remove comments links from admin bar
function df_disable_comments_admin_bar() {
    if (is_admin_bar_showing()) {
        remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
    }
}
add_action('init', 'df_disable_comments_admin_bar');
票数 0
EN

Stack Overflow用户

发布于 2014-07-31 03:16:11

我建议你使用Akismet自动过滤那些可能是真实的评论,而99%的评论只是垃圾邮件链接到不可靠的网站,而不是从wordpress中删除评论表。

删除表有时会导致许多问题,..But使用像Akismet这样的插件将是防止垃圾评论的最佳解决方案。

票数 0
EN

Stack Overflow用户

发布于 2014-07-31 03:19:13

我可以想象,这会造成许多问题/错误。最好从插入注释的特定代码中禁用注释。

您可以在发现wp_insert_comment($data);的任何地方进行注释,这将允许您维护现有代码,以防有一天您希望它返回。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25050250

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档