Skip to:
Content

BuddyPress.org

Changeset 13798


Ignore:
Timestamp:
04/21/2024 06:37:13 AM (11 months ago)
Author:
imath
Message:

Stop creating a user when a signup is performed on regular WP configs

Since version 2.0, we are using the $wpdb->signups table to manage pending accounts. We kept on creating a user as well as a user meta to store the activation key for regular WP configs.

This user creation step is now deprecated and by default no user will be created on any WordPress config once a user signs up. In next BP major version we'll fully remove the code but until then you can always use the bp_signups_create_user filter (returning true) or define the deprecated constant BP_SIGNUPS_SKIP_USER_CREATION to false to carry on creating the user on regular WP configs.

This move allows us to fix a 9 years old ticket and is more consistent: signups are becoming users only when they validate their account.

Props johnjamesjacoby, DJPaul, espellcaste

Fixes #6123
Closes https://github.com/buddypress/buddypress/pull/271

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/admin/bp-core-admin-tools.php

    r13775 r13798  
    928928            ),
    929929            'BP_SIGNUPS_SKIP_USER_CREATION' => array(
    930                 'label' => 'BP_SIGNUPS_SKIP_USER_CREATION',
     930                'label' => 'BP_SIGNUPS_SKIP_USER_CREATION (deprecated)',
    931931                'value' => defined( 'BP_SIGNUPS_SKIP_USER_CREATION' ) && BP_SIGNUPS_SKIP_USER_CREATION ? __( 'Enabled', 'buddypress' ) : __( 'Disabled', 'buddypress' ),
    932932                'debug' => defined( 'BP_SIGNUPS_SKIP_USER_CREATION' ) ? BP_SIGNUPS_SKIP_USER_CREATION : 'undefined',
  • trunk/src/bp-members/bp-members-functions.php

    r13743 r13798  
    18591859        $user_email     = sanitize_email( $user_email );
    18601860        $activation_key = wp_generate_password( 32, false );
     1861        $create_user    = false;
     1862
     1863        // @deprecated.
     1864        if ( defined( 'BP_SIGNUPS_SKIP_USER_CREATION' ) ) {
     1865            _doing_it_wrong( 'BP_SIGNUPS_SKIP_USER_CREATION', esc_html__( 'the `BP_SIGNUPS_SKIP_USER_CREATION` constant is deprecated as skipping user creation is now the default behavior.', 'buddypress' ), 'BuddyPress 14.0.0' );
     1866
     1867            // Creating a user is the opposite of skipping user creation.
     1868            $create_user = ! BP_SIGNUPS_SKIP_USER_CREATION;
     1869        }
    18611870
    18621871        /**
    1863          * WordPress's default behavior is to create user accounts
    1864          * immediately at registration time. BuddyPress uses a system
    1865          * borrowed from WordPress Multisite, where signups are stored
    1866          * separately and accounts are only created at the time of
    1867          * activation. For backward compatibility with plugins that may
    1868          * be anticipating WP's default behavior, BP silently creates
    1869          * accounts for registrations (though it does not use them). If
    1870          * you know that you are not running any plugins dependent on
    1871          * these pending accounts, you may want to save a little DB
    1872          * clutter by defining setting the BP_SIGNUPS_SKIP_USER_CREATION
    1873          * to true in your wp-config.php file.
     1872         * Filter here to keep creating a user when a registration is performed on regular WordPress configs.
     1873         *
     1874         * @since 14.0.0
     1875         * @todo Fully deprecate in 15.0.0
     1876         *
     1877         * @param boolean $create_user True to carry on creating a user when a registration is performed.
     1878         *                             False otherwise.
    18741879         */
    1875         if ( ! defined( 'BP_SIGNUPS_SKIP_USER_CREATION' ) || ! BP_SIGNUPS_SKIP_USER_CREATION ) {
     1880        if ( apply_filters( 'bp_signups_create_user', $create_user ) ) {
    18761881            $user_id = BP_Signup::add_backcompat( $user_login, $user_password, $user_email, $usermeta );
    18771882
     
    20182023            $user_id = wp_create_user( $signup->user_login, $password, $signup->user_email );
    20192024
    2020         // Otherwise, update the existing user's status.
     2025            /*
     2026             * @todo Remove this `elseif` statement in version 15.0.0.
     2027             *
     2028             * Since 2.0.0 BuddyPress is using the $wpdb->signups table even in regular WordPress configs.
     2029             * In 14.0.0, we are deprecating the `BP_SIGNUPS_SKIP_USER_CREATION` as well as creating a user
     2030             * each time a registration is performed.
     2031             */
    20212032        } elseif ( $key === bp_get_user_meta( $user_id, 'activation_key', true ) || $key === wp_hash( $user_id ) ) {
    20222033
  • trunk/src/bp-members/classes/class-bp-signup.php

    r13499 r13798  
    534534     *
    535535     * @since 2.0.0
     536     * @deprecated 14.0.0
    536537     *
    537538     * @global wpdb $wpdb The WordPress database object.
     
    544545     */
    545546    public static function add_backcompat( $user_login = '', $user_password = '', $user_email = '', $usermeta = array() ) {
     547        _deprecated_function( __METHOD__, '14.0.0' );
     548
    546549        global $wpdb;
    547550
     
    604607         *
    605608         * @since 10.0.0
     609         * @deprecated 14.0.0
    606610         *
    607611         * @param int $user_id ID of the WP_User just added.
    608612         */
    609         do_action( 'bp_core_signups_after_add_backcompat', $user_id );
     613        do_action_deprecated( 'bp_core_signups_after_add_backcompat', array( $user_id ), '14.0.0' );
    610614
    611615        /**
     
    613617         *
    614618         * @since 2.0.0
     619         * @deprecated 14.0.0
    615620         *
    616621         * @param int $user_id User ID being registered.
    617622         */
    618         return apply_filters( 'bp_core_signups_add_backcompat', $user_id );
     623        return apply_filters_deprecated( 'bp_core_signups_add_backcompat', array( $user_id ), '14.0.0' );
    619624    }
    620625
Note: See TracChangeset for help on using the changeset viewer.