LearnDash: Add New Users to a Group
Puts every newly registered user into a LearnDash group automatically, giving them the group's courses and placing them under its group leaders.
Opens WPIDE on
Code
if ( ! defined( 'LEARNDASH_VERSION' ) ) {
return;
}
// LearnDash group ID.
$wpide_ld_new_user_group = 0;
add_action( 'user_register', function ( $user_id ) use ( $wpide_ld_new_user_group ) {
if ( $wpide_ld_new_user_group && 'groups' === get_post_type( $wpide_ld_new_user_group ) ) {
ld_update_group_access( $user_id, $wpide_ld_new_user_group );
}
}, 20 );
Notes
Set the group ID at the top. Users created by an administrator are included too.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.