根据注册后的时间自动删除Wordpress用户? [英] Auto delete Wordpress users according to time since registering?

查看:498
本文介绍了根据注册后的时间自动删除Wordpress用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用User Access Manager的基本WordPress 3.1安装程序上,是否可以自动删除x天的用户?

On a basic Wordpress 3.1 setup with User Access Manager, is it possible to automatically delete users that are x days old?

我没有找到此功能的插件。如何实现这一点?我能够使用sql或php查询设置cron作业,例如3天的用户每天自动从数据库中删除一次吗?

I have found no plugins for this feature. How would one go about implementing this? Would I be able to set up a cron job with an sql or php query whereby users that are for example 3 days old are automatically deleted from the database once every day? If so, could someone please explain how?

任何帮助将非常感谢 - 提前感谢。

Any help would be greatly appreciated - thanks in advance.

推荐答案

您想查看 wp_users 表中的 user_registered 。因为你使用的是WordPress,我假设你也在使用MySQL - 在这种情况下,你可以使用 DATEDIFF()

You want to have a look at the user_registered column in the wp_users table. Since you're using WordPress, I'll assume that you're also using MySQL — in which case you can use the DATEDIFF() function in your SQL to work out how many days ago they registered.

删除30天(或更早)的所有人的SQL是:

The SQL to delete everyone who is 30 days old (or older) is:

DELETE FROM `wp_users` 
WHERE datediff(now(), `user_registered`) >= 30

您可以用 SELECT * FROM 替换 DELETE FROM 在查询中查看删除会影响哪些用户,如果您要预览将被查询删除的人。

You can replace the DELETE FROM with SELECT * FROM in that query to see which users the delete would affect, if you want to preview who will be deleted by the query.

您可以使用语言,这可能是一个PHP脚本,只是运行上面的SQL。

You could set this up as a cronjob using the language of your choice, which might be a PHP script that just runs the SQL above. You could then run that at midnight every day by putting the following into your crontab:

0 0 * * * php ~/delete_expired_users.php

如果你刚刚接触cronjobs,那么只需运行命令 php〜/ delete_expired_users.php 每天( * )表示小时 0 ,minute 0 (即午夜)。让我知道,如果你需要任何更详细的说明。

If you're new to cronjobs, then that will simply run the command php ~/delete_expired_users.php every day (that's that the * denotes) at hour 0, minute 0 (ie. midnight). Let me know if you need any more detailed instructions.

这篇关于根据注册后的时间自动删除Wordpress用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆