Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Disable activation email and auto-activate users in BuddyPress
- function wbcom_disable_activation_email() {
- remove_action( 'bp_core_signup_send_validation_email', 'bp_core_signup_send_validation_email' );
- error_log( "Activation email disabled." );
- }
- add_action( 'bp_init', 'wbcom_disable_activation_email' );
- // Automatically activate user signups
- function wbcom_auto_activate_user( $user_login ) {
- global $wpdb;
- // Get the signup entry using BP_Signup class
- $signup_data = BP_Signup::get(
- array(
- 'user_login' => $user_login,
- 'active' => 0, // Only look for inactive users
- )
- );
- // Check if the signup exists
- if ( ! empty( $signup_data['signups'] ) ) {
- $signup = $signup_data['signups'][0]; // Assuming the first result is correct
- // Activate the signup using BuddyPress' activation method
- $activation_result = BP_Signup::activate( array( $signup->signup_id ) );
- if ( isset( $activation_result['activated'] ) && ! empty( $activation_result['activated'] ) ) {
- $activated_user = $activation_result['activated'][0];
- // Log the successful activation
- error_log( "User successfully activated: " . $activated_user->ID );
- // Automatically log in the user after activation
- wp_set_auth_cookie( $activated_user->ID, false, is_ssl() );
- wp_set_current_user( $activated_user->ID );
- error_log( "User logged in: " . $activated_user->ID );
- // Redirect the user to their profile page
- bp_core_redirect( bp_core_get_user_domain( $activated_user->ID ) );
- } else {
- error_log( "Error activating user: " . $signup->user_login );
- }
- } else {
- error_log( "User signup not found or already activated: " . $user_login );
- }
- }
- // Hook into the registration process
- add_action( 'bp_core_signup_user', function( $user_id, $user_login, $user_password, $user_email, $usermeta ) {
- wbcom_auto_activate_user( $user_login );
- }, 10, 5 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement