BP_Signup::add_backcompat( string $user_login = '', string $user_password = '', string $user_email = '', array $usermeta = array() )
Create a WP user at signup.
Description
Since BP 2.0, non-multisite configurations have stored signups in the same way as Multisite configs traditionally have: in the wp_signups table. However, because some plugins may be looking directly in the wp_users table for non-activated signups, we mirror signups there by creating "phantom" users, mimicking WP’s default behavior.
Parameters
- $user_login
-
(Optional) User login string.
Default value: ''
- $user_password
-
(Optional) User password.
Default value: ''
- $user_email
-
(Optional) User email address.
Default value: ''
- $usermeta
-
(Optional) Metadata associated with the signup.
Default value: array()
Return
(int) User id.
Source
File: bp-members/classes/class-bp-signup.php
public static function add_backcompat( $user_login = '', $user_password = '', $user_email = '', $usermeta = array() ) { global $wpdb; $user_id = wp_insert_user( array( 'user_login' => $user_login, 'user_pass' => $user_password, 'display_name' => sanitize_title( $user_login ), 'user_email' => $user_email ) ); if ( is_wp_error( $user_id ) || empty( $user_id ) ) { return $user_id; } // Update the user status to '2', ie "not activated" // (0 = active, 1 = spam, 2 = not active). $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 2 WHERE ID = %d", $user_id ) ); // WordPress creates these options automatically on // wp_insert_user(), but we delete them so that inactive // signups don't appear in various user counts. delete_user_option( $user_id, 'capabilities' ); delete_user_option( $user_id, 'user_level' ); // Set any profile data. if ( bp_is_active( 'xprofile' ) ) { if ( ! empty( $usermeta['profile_field_ids'] ) ) { $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] ); foreach ( (array) $profile_field_ids as $field_id ) { if ( empty( $usermeta["field_{$field_id}"] ) ) { continue; } $current_field = $usermeta["field_{$field_id}"]; xprofile_set_field_data( $field_id, $user_id, $current_field ); /* * Save the visibility level. * * Use the field's default visibility if not present, and 'public' if a * default visibility is not defined. */ $key = "field_{$field_id}_visibility"; if ( isset( $usermeta[ $key ] ) ) { $visibility_level = $usermeta[ $key ]; } else { $vfield = xprofile_get_field( $field_id ); $visibility_level = isset( $vfield->default_visibility ) ? $vfield->default_visibility : 'public'; } xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level ); } } } /** * Filters the user ID for the backcompat functionality. * * @since BuddyPress 2.0.0 * * @param int $user_id User ID being registered. */ return apply_filters( 'bp_core_signups_add_backcompat', $user_id ); }
Changelog
Version | Description |
---|---|
BuddyPress 2.0.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.