简体   繁体   English

根据不同的wordpress注册页面将新注册的用户添加到不同的leardash组

[英]Adding newly registered users to different leardash groups depending on different wordpress registration page

I have two WordPress registration pages eg https://example.com/adult-register-url and https://example.com/youth-register-url .我有两个 WordPress 注册页面,例如https://example.com/adult-register-urlhttps://example.com/youth-register-url I have created 2 learndash groups with different courses one group is the adult group and the other group is the youth group.我创建了 2 个不同课程的 learndash 组,一组是成人组,另一组是青年组。 I am now trying to automatically add users that register with the adult-register-url to the adult group and the youth-register-url to the youth group.我现在正在尝试自动将使用成人注册 URL 注册的用户添加到成人组,将青年注册 URL 注册到青年组。 However, on registration users are not being added to the correct group.但是,在注册时,用户没有被添加到正确的组中。 Below is the code that I added to the functions.php下面是我添加到functions.php的代码

add_action( 'user_register', function ( $user_id = 0 ){
        
    global $post;
    
        $current_slug = $post->name;
        
    
    if(isset($current_slug) and $current_slug =='youth-register-url'){
        if ( !empty( $user_id ) ) {
        $LD_GROUP_IDS = array( 5822 );
        learndash_set_users_group_ids( $user_id, $LD_GROUP_IDS );
        $courses = array(2399,2392,2387,2039);
        foreach($courses as $course){
            ld_update_course_access($user_id, $course, $remove=true);
        }
    }
        
    }else{
    if ( !empty( $user_id ) ) {
        $LD_GROUP_IDS = array( 5410 );
        learndash_set_users_group_ids( $user_id, $LD_GROUP_IDS );
        $courses = array(2399,2392,2387,2039);
        foreach($courses as $course){
            ld_update_course_access($user_id, $course, $remove=true);
        }
    }}
});

Used the $_REQUEST variable to get the meta data using that I used the referrer key to load courses使用 $_REQUEST 变量来获取元数据,使用我使用推荐人键加载课程

add_action( 'user_register', function ( $user_id = 0 ){

    if(isset($_REQUEST['referrer']) and $_REQUEST['referrer'] =='https://example.com/youth-register-url/'){
        if ( !empty( $user_id ) ) {
        $LD_GROUP_IDS = array( 5822 );
        learndash_set_users_group_ids( $user_id, $LD_GROUP_IDS );
        $courses = array(2399,2392,2387,2039);
        foreach($courses as $course){
            ld_update_course_access($user_id, $course, $remove=true);
        }
    }
        
    }else{
    if ( !empty( $user_id ) ) {
        $LD_GROUP_IDS = array( 5410 );
        learndash_set_users_group_ids( $user_id, $LD_GROUP_IDS );
        $courses = array(2399,2392,2387,2039);
        foreach($courses as $course){
            ld_update_course_access($user_id, $course, $remove=true);
        }
    }}
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM