很多WordPress网站都有被恶意注册的经历,就会有很多假用户,手动删除是很麻烦的,有很多WordPress函数可以自由添加、编辑、删除、修改WordPress网站的数据,用户也是一样。今天我们就一起看看WordPress定时任务删除从未登录的用户方法。

将下面代码放在主题目录下的functions.php文件中即可。

//定时任务

add_filter( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’cron_schedules\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’salong_add_every_time\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ );

function salong_add_every_time( $schedules ) {

$schedules[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’every_time\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’] = array(

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’interval\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => 600,

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’display\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => __( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’每隔10分钟\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’salong\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ )

);

return $schedules;

}

if ( ! wp_next_scheduled( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’salong_add_every_time\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ) ) {

wp_schedule_event( time(), \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’every_time\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’salong_add_every_time\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ );

}

add_action( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’salong_add_every_time\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’salong_every_time_update_douban_average\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ );

function salong_every_time_update_douban_average() {

$blogusers = get_users(array( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’meta_key\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’jh\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ,\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’meta_value\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ));//我这里检查jh字段为空的用户,大家可以自由修改

foreach ( $blogusers as $user ) {

wp_delete_user( $user->ID );//删除用户

}

}

需要注意的是,如果被删除用户有发表过文章等内容,不指定删除后由谁继承,将会全部删除。当然,这里是恶意注册用户,都没登录过,不存在这个问题,直接删就行了。

相关新闻

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

联系我们

联系我们

151-1101-0018

在线咨询:
邮件:30115776@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
关注微信
分享本页
返回顶部