Hi,
I need to disable drip content for old users that I am importing from another LMS. I have tried to add the code below, based on users IDs (old users have id smaller than 8863) but it is not working. Can you please take a look and help me?
add_filter('wplms_course_drip_legacy_users','dripLegacy',10,2);
function dripLegacy($drip,$course_id){
if(!is_user_logged_in())
return $drip;
$user = wp_get_current_user();
if(wplms_user_course_active_check($user_id,$course_id) && $user_id <= '8863'){
$drip = 'H';
}
return $drip;
};
Thanks,
Erick
Hello guys,
I found the solution. I made two mistakes:
- Used a non-existent filter name;
- Used $user_id instead of $user->ID.
Can you please explain to me why it didn't work with $user_id but worked with $user->ID ?
Thank you!
PS: Below is the code that is working
===============
add_filter('wplms_course_drip_switch','dripLegacy');
function dripLegacy($drip,$course_id){
if(!is_user_logged_in())
return $drip;
$user = wp_get_current_user();
if(wplms_user_course_active_check($user_id,$course_id) && $user->ID <= 8862){
$drip = 'H';
}
return $drip;
};
Hello,
refer this:
https://codex.wordpress.org/Function_Reference/wp_get_current_user
because
$user = wp_get_current_user();
returns an object. if you want to access any of its value then you have to write it in a correct form by passing a valid parameter or key.
$user->ID: here user is a whole variable containing a list of objects. if you want to access any of its element, then you have to pass its respective key.
As this issue is well explained, listened to and understood by the user. on his confirmation, I am closing this topic.