Page 1 of 1

Automatically Upgrade Membership Level

PostPosted: November 6th, 2011, 2:02 am
by groomie
I would like to write a cron job (in functions.php) that finds users meeting certain criteria (criteria resides in multiple database tables) and automatically upgrades their membership level. I know that this can be done in bulk manually, but obviously want a solution that does this automatically on a certain schedule.

Is there a hook where you can easily change a user's membership level?

Or, can you simply alter a field in the wp_usermeta table to accomplish this? So far my attempts at going this route have not been successful. Before writing the function, I attempted a test via a MySQL Update Query, but this did not work:

/* Update Member Level When Application Submitted */
UPDATE wp_usermeta
INNER JOIN wp_users ON wp_usermeta.user_id = wp_users.ID
LEFT JOIN wp_frm_items ON wp_usermeta.user_id = wp_frm_items.user_id
LEFT JOIN wp_frm_item_metas ON wp_frm_items.id = wp_frm_item_metas.item_id
SET wp_usermeta.meta_value = 'a:1:{s:15:"s2Member_level1";s:1:"1";}'
WHERE wp_usermeta.meta_value = 'a:1:{s:10:"subscriber";s:1:"1";}'
AND wp_frm_item_metas.meta_value = 'Lock my application and submit.'

Re: Automatically Upgrade Membership Level

PostPosted: November 6th, 2011, 9:38 am
by Eduan
You could try to integrate something like what's on this page:
viewtopic.php?f=4&t=15715

Hope this helps. :)
P.S. Don't forget to report back. ;)

Re: Automatically Upgrade Membership Level

PostPosted: November 6th, 2011, 12:53 pm
by groomie
I'll give it a go and keep you posted. Thanks so much! :)

Re: Automatically Upgrade Membership Level

PostPosted: November 6th, 2011, 6:04 pm
by groomie
I think I may be able to do a workaround using Custom Capabilities...programming-wise, it would be a ton easier (and much faster) if I could automatically update a user's access role via an update_user_role function or something of that kind. I've been combing through the documentation and so far have not found a way to do this. :(

Does anyone know of a hack to do this?

Re: Automatically Upgrade Membership Level

PostPosted: November 7th, 2011, 2:42 am
by Jason Caldwell
Thanks for the heads up on this thread.

This functionality is already built into WordPress as part of WP_User class.
Code: Select all
<?php
$user_id 
= 123;
$user = new WP_User($user_id);
$user->set_role("s2member_level1");
?>
The most common Roles are:
Code: Select all
subscriber
s2member_level1
s2member_level1
s2member_level1
s2member_level1
administrator
author
contributor
editor

Re: Automatically Upgrade Membership Level

PostPosted: November 8th, 2011, 1:40 am
by Cristián Lávaque
Thanks Jason!

groomie, here you have some more examples viewtopic.php?f=36&t=2599

I hope that helps. :)

Re: Automatically Upgrade Membership Level

PostPosted: November 20th, 2011, 5:01 am
by groomie
Thanks Jason! Exactly what I needed!
-groomie