我的WordPress网站上有很多垃圾信息.他们链接到他们的垃圾网站使用他们的个人资料(主页和描述).

这是一个很好的识别它们的方法.普通用户不会写长的人工智能生成的文本,在他们的个人资料上有链接.

如何使用SQL批量删除它们(或首先找到它们)?

数据可以在META_KEY描述中的wp_USERMETA表中找到.

我试过这个:

SELECT meta_key FROM `wp_usermeta` WHERE description != '';

但得到了这个错误消息:

#1054 -"where clause"中的未知列"description"

看来我现在不太明白这张桌子的 struct .

你能帮帮我吗?

谢谢.

推荐答案

正确的工作SQL查询为:

SELECT * FROM `wp_usermeta` WHERE `meta_key` = 'description' AND `meta_value` != '';

您可以从管理员用户列表中筛选具有描述的用户,然后批量删除它们,而不是在数据库中进行搜索.

该代码在管理员用户列表中显示一个名为"Spam"的新按钮,用于过滤具有描述(see the screenshot below)的用户.

try 以下操作:

add_action( 'restrict_manage_users', 'add_filter_users_has_description', 20 );
function add_filter_users_has_description() {
    echo '<input id="post-query-submit" type="submit" class="button" value="'.__('Spam').'" name="has_description">';
}

add_filter( 'pre_get_users', 'filter_users_with_description' );
function filter_users_with_description( $query ) {
    global $pagenow;

    if ( is_admin() && 'users.php' == $pagenow && isset($_GET['has_description']) && !empty($_GET['has_description']) ) {
        $meta_query = array(
            array(
                'key'     => 'description',
                'value'   => '',
                'compare' => '!=',
            )
        );
        $query->set( 'meta_query', $meta_query );
    }
}

代码放在子主题的functions.php文件中(或插件中).测试和作品.

enter image description here


Addition:在WordPress用户列表自定义列中显示裁切的说明

// add a custom column admin users list
add_filter( 'manage_users_columns', 'add_spam_column_to_users_list' );
function add_spam_column_to_users_list( $columns ) {
    $columns['description'] = __('Spam');
    return $columns;
}

// Users custom column: Display user description (trimmed)
add_filter( 'manage_users_custom_column', 'add_description_to_users_list_spam_column', 10, 3 );
function add_description_to_users_list_spam_column( $output, $column, $user_id ) {
    if ( 'description' === $column ) {
        if ( $description = get_user_meta( $user_id, 'description', true ) ) {
            $output = '<small style="word-break:break-word;">'.wp_trim_words( $description, 5 ).' ...</small>';
        }
    }
    return $output;
}

代码放在子主题的functions.php文件中(或插件中).测试和作品.

Php相关问答推荐

通过激活模板在数据库中创建表

Symfony/Panther Web抓取不适用于登录后的内容(云功能)

从含有特殊字符的ANSI文本文件中读取数据是在移值,为什么?

在冲突和几何上插入的Postgres参数化查询在PHP中不起作用

如何在Livewire 3 Form类中做依赖注入?

如何在execute语句中使用存储过程参数?

允许客户定义特定WooCommerce产品的价格

基于自定义域的每个购物车项目的WooCommerce定制数量输入步骤

从字符串转换日期和/或时间时,Laravel转换失败

WordPress:今天的计数';修改和发布的帖子

使用 secure 和 httponly 选项删除 php 中的 cookie 值得吗?

根据所选付款方式启用/禁用 WooCommerce 所需的 checkout 字段

从图像URL中获取文件扩展名?

在WooCommerce购物车和 checkout 页面中更改总计文本

PHP使用三元运算符进行null合并(再次)

MySQLI bind_param导致的Cannot modify readonly property错误

使用来自 PHP 表单的数据更新 xml 命名空间

WooCommerce 按 ID 限制产品

WordPress 函数 get_post(post_id) 是否查询数据库?

为什么非贪婪匹配会消耗整个模式,即使后面跟着另一个非贪婪匹配