How to expire user registration?

admin2025-06-04  2

I have a membership wordpress site. I want to suspend user after sixth month from the registration date. So that user purchase our plan/subscription. I want everything without any plugin.

How can i do this?

I have a membership wordpress site. I want to suspend user after sixth month from the registration date. So that user purchase our plan/subscription. I want everything without any plugin.

How can i do this?

Share Improve this question edited Nov 16, 2017 at 11:54 Husain Ahmed asked Nov 16, 2017 at 11:22 Husain AhmedHusain Ahmed 731 silver badge13 bronze badges 1
  • You have to create a plugin to do this. You cannot have that without plugin. – mmm Commented Nov 16, 2017 at 11:56
Add a comment  | 

1 Answer 1

Reset to default 1

You would need to do a Cron. Get all user who where registered before 6 months ago and change their role to something else. in this example i have user 'expired' but you would need the create this role before you could use it.

add_action('wp', function() {
   if ( !wp_next_scheduled( 'check_for_expired_users' ) ) {
      wp_schedule_event( time(), 'daily', 'check_for_expired_users');
   }
});

function check_for_expired_users() {
  $users = get_users([
    'role__not_in' => array('expired'),
     'date_query' => array(
       array(
         'before' => '6 months ago',
       )
    )
  ]);

  foreach ($users as $u) {
    $u->set_role( 'expired' );
  }

}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748983447a315377.html

最新回复(0)