• Knowledge Base
    • All Articles
    • BuddyBoss Platform
    • BuddyBoss Theme
    • BuddyBoss App
    • Integrations
    • Advanced Setup
    • Troubleshooting
    • Release Notes
      • BuddyBoss Platform
      • BuddyBoss Platform Pro
      • BuddyBoss Theme
      • BuddyBoss App
      • BuddyBoss App Plugin
      • Other Products
  • Developers
    • Developer Tutorials
      • Web Development
      • App Development
    • Code Reference
      • Functions
      • Hooks
      • Classes
      • Methods
      • Commands
      • App Codex
    • REST API
      • BuddyBoss Platform
      • BuddyBoss App
    • Font Cheatsheet
    • Github Project
  • Roadmap
  • Go to BuddyBoss
    Contact Support
    Filter
    • Knowledge Base
      • All Articles
      • BuddyBoss Platform
      • BuddyBoss Theme
      • BuddyBoss App
      • Integrations
      • Advanced Setup
      • Troubleshooting
      • Release Notes
        • BuddyBoss Platform
        • BuddyBoss Platform Pro
        • BuddyBoss Theme
        • BuddyBoss App
        • BuddyBoss App Plugin
        • Other Products
    • Developers
      • Developer Tutorials
        • Web Development
        • App Development
      • Code Reference
        • Functions
        • Hooks
        • Classes
        • Methods
        • Commands
        • App Codex
      • REST API
        • BuddyBoss Platform
        • BuddyBoss App
      • Font Cheatsheet
      • Github Project
    • Roadmap
    • Go to BuddyBoss
    Filter
    Filter

    Contents

    • Description
    • Parameters
    • Return
    • Source
    • Changelog
    • Related
    Code Reference Classes BP_Signup BP_Signup::add_backcompat()

    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

    (string) (Optional) User login string.

    Default value: ''

    $user_password

    (string) (Optional) User password.

    Default value: ''

    $user_email

    (string) (Optional) User email address.

    Default value: ''

    $usermeta

    (array) (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 );
    	}
    

    Expand full source code Collapse full source code

    Changelog

    Changelog
    Version Description
    BuddyPress 2.0.0 Introduced.

    Related

    Uses

    Uses
    Uses Description
    bp-xprofile/bp-xprofile-functions.php: xprofile_set_field_visibility_level()

    Set the visibility level for this field.

    bp-xprofile/bp-xprofile-functions.php: xprofile_set_field_data()

    A simple function to set profile data for a specific field for a specific user.

    bp-xprofile/bp-xprofile-functions.php: xprofile_get_field()

    Get a profile field object.

    bp-members/classes/class-bp-signup.php: bp_core_signups_add_backcompat

    Filters the user ID for the backcompat functionality.

    bp-core/bp-core-template.php: bp_is_active()

    Check whether a given component (or feature of a component) is active.

    Used By
    Used By Description
    bp-members/bp-members-functions.php: bp_core_signup_user()

    Process data submitted at user registration and convert to a signup object.

    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.

    © 2023 • BuddyBoss