Trying to change user role based on points. This is working seems fine till it keep increasing points.
The problem happens when if we decrease points it is not changing role back to below stage.
Means if I have 600 points for administrator role and if user earn and role changed to administrator. After than if points goes down to 500 due to some type of negative system it should change role back to below administrator respecting to the point value in condition but this is not happening.
Once role set to upper it is never going down even if point decrease.
global $wpdb;
$pref = self::qa_prefix();
$u = new WP_User($u_id);
$user_point = $wpdb->get_row("SELECT userid, points FROM {$pref}userpoints WHERE userid = {$u_id}");
if(!is_super_admin()) {
if($user_point->points >= 600) {
$u->set_role('administrator');
} elseif($user_point->points >= 150 && $user_point->points < 600) {
$u->set_role('editor');
} elseif($user_point->points >= 100 && $user_point->points < 150) {
$u->set_role('contributor');
} else {
$u->set_role('subscriber');
}
}
Any suggestion or idea please.... :)
$u
? Where does this hook?self
so that is a class. To quote myself, "Where does this hook?"