Skip to:
Content

BuddyPress.org

Changeset 13165


Ignore:
Timestamp:
12/10/2021 04:13:57 PM (2 years ago)
Author:
dcavins
Message:

BP_Signup improvements.

On multisite, when resending actvation emails, send the
right kind (user or user + site). Also ensure that default
meta is set via wpmu meta filters.

introduce bp_members_get_signup_by() and
bp_members_site_requests_enabled().

Correct default value calculation in BP_Signup
to allow backcompat.

See #8540.

Location:
trunk/src
Files:
4 edited

Legend:

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

    r12912 r13165  
    474474    );
    475475
    476     $signups = BP_Signup::get(
    477         array(
    478             'user_login' => $user,
    479         )
    480     );
    481 
     476    $signup     = bp_members_get_signup_by( 'activation_key', $key );
    482477    $salutation = $user;
    483     if ( $signups && bp_is_active( 'xprofile' ) ) {
    484         $signup = $signups['signups'][0];
     478    if ( $signup && bp_is_active( 'xprofile' ) ) {
    485479        if ( isset( $signup->meta[ 'field_' . bp_xprofile_fullname_field_id() ] ) ) {
    486480            $salutation = $signup->meta[ 'field_' . bp_xprofile_fullname_field_id() ];
     
    563557}
    564558add_filter( 'wpmu_signup_user_notification', 'bp_core_activation_signup_user_notification', 1, 4 );
     559
     560/**
     561 * Ensure that some meta values are set for new multisite signups.
     562 *
     563 * @since 10.0.0
     564 *
     565 * @see wpmu_signup_user() for a full description of params.
     566 *
     567 * @param array $meta Signup meta data. Default empty array.
     568 * @return array Signup meta data.
     569 */
     570function bp_core_add_meta_to_multisite_signups( $meta ) {
     571
     572    // Ensure that sent_date and count_sent are set in meta.
     573    if ( ! isset( $meta['sent_date'] ) ) {
     574        $meta['sent_date'] = '0000-00-00 00:00:00';
     575    }
     576    if ( ! isset( $meta['count_sent'] ) ) {
     577        $meta['count_sent'] = 0;
     578    }
     579
     580    return $meta;
     581}
     582add_filter( 'signup_user_meta', 'bp_core_add_meta_to_multisite_signups' );
     583add_filter( 'signup_site_meta', 'bp_core_add_meta_to_multisite_signups' );
    565584
    566585/**
  • trunk/src/bp-members/bp-members-functions.php

    r13116 r13165  
    23892389
    23902390    // Record that the activation email has been sent.
    2391     $signups = BP_Signup::get(
    2392         array(
    2393             'activation_key' => $key,
    2394         )
    2395     );
    2396 
    2397     if ( ! empty( $signups['signups'] ) ) {
    2398         foreach ( $signups['signups'] as $signup ) {
    2399             $meta = array(
    2400                 'sent_date'  => current_time( 'mysql', true ),
    2401                 'count_sent' => $signup->count_sent + 1
    2402             );
    2403 
    2404             BP_Signup::update( array(
    2405                 'signup_id' => $signup->id,
    2406                 'meta'      => $meta,
    2407             ) );
    2408         }
     2391    $signup = bp_members_get_signup_by( 'activation_key', $key );
     2392
     2393    if ( $signup ) {
     2394        $meta = array(
     2395            'sent_date'  => current_time( 'mysql', true ),
     2396            'count_sent' => $signup->count_sent + 1
     2397        );
     2398
     2399        BP_Signup::update( array(
     2400            'signup_id' => $signup->id,
     2401            'meta'      => $meta,
     2402        ) );
    24092403    }
    24102404}
     
    36953689    return apply_filters( 'bp_get_members_invitation_from_request', $invite );
    36963690}
     3691
     3692/**
     3693 * Get WP_User object corresponding to a record in the signups table.
     3694 *
     3695 * @since 10.0.0
     3696 *
     3697 * @param string $field Which fields to search by. Possible values are
     3698 *                      activation_key, user_email, id.
     3699 * @param string $value Value to search by.
     3700 * @return bool|BP_Signup $signup Found signup, returns first found
     3701 *                                if more than one is found.
     3702 */
     3703function bp_members_get_signup_by( $field = 'activation_key', $value = '' ) {
     3704    switch ( $field ) {
     3705        case 'activation_key':
     3706        case 'user_email':
     3707            $key = $field;
     3708            break;
     3709
     3710        case 'id':
     3711        default:
     3712            $key = 'include';
     3713            break;
     3714    }
     3715
     3716    $signups = BP_Signup::get(
     3717        array(
     3718            $key => $value,
     3719        )
     3720    );
     3721
     3722    if ( ! empty( $signups['signups'] ) ) {
     3723        $signup = current( $signups['signups'] );
     3724    } else {
     3725        $signup = false;
     3726    }
     3727
     3728    return $signup;
     3729}
     3730
     3731/**
     3732 * Are site creation requests currently enabled?
     3733 *
     3734 * @since 10.0.0
     3735 *
     3736 * @return bool Whether site requests are currently enabled.
     3737 */
     3738function bp_members_site_requests_enabled() {
     3739
     3740    $matches = array( 'blog', 'all' );
     3741
     3742    return is_multisite() && in_array( bp_core_get_root_option( 'registration' ), $matches, true );
     3743}
  • trunk/src/bp-members/classes/class-bp-members-admin.php

    r13164 r13165  
    22052205
    22062206        $signups    = $signups_query['signups'];
    2207         $signup_ids = wp_list_pluck( $signups, 'signup_id' );
     2207        $signup_ids = wp_list_pluck( $signups, 'id' );
    22082208
    22092209        // Set up strings.
  • trunk/src/bp-members/classes/class-bp-signup.php

    r13117 r13165  
    215215        }
    216216
    217         /**
    218          * Calculate a diff between now & last time
    219          * an activation link has been resent.
    220          */
    221         $sent_at = mysql2date( 'U', $this->date_sent );
    222         $now     = current_time( 'timestamp', true );
    223         $diff    = $now - $sent_at;
    224 
    225         /**
    226          * Set a boolean to track whether an activation link
    227          * was sent in the last day.
    228          */
    229         $this->recently_sent = ( $diff < 1 * DAY_IN_SECONDS );
    230 
    231217        // How many times has the activation email been sent?
    232218        if ( isset( $this->meta['count_sent'] ) ) {
    233219            $this->count_sent = absint( $this->meta['count_sent'] );
    234220        } else {
    235             $this->count_sent = 0;
    236         }
     221            /**
     222             * Meta will not be set if this is a pre-10.0 signup.
     223             * In this case, we assume that the count is 1.
     224             */
     225            $this->count_sent = 1;
     226        }
     227
     228        /**
     229         * Calculate a diff between now & last time
     230         * an activation link has been resent.
     231         */
     232        $sent_at = mysql2date( 'U', $this->date_sent );
     233        $now     = current_time( 'timestamp', true );
     234        $diff    = $now - $sent_at;
     235
     236        /**
     237         * Set a boolean to track whether an activation link
     238         * was sent in the last day.
     239         */
     240        $this->recently_sent = $this->count_sent && ( $diff < 1 * DAY_IN_SECONDS );
     241
    237242    }
    238243
     
    815820        foreach ( $signups as $signup ) {
    816821
    817             $meta = array(
    818                 'sent_date'  => current_time( 'mysql', true ),
    819                 'count_sent' => $signup->count_sent + 1
    820             );
     822            $meta               = $signup->meta;
     823            $meta['sent_date']  = current_time( 'mysql', true );
     824            $meta['count_sent'] = $signup->count_sent + 1;
    821825
    822826            // Send activation email.
    823827            if ( is_multisite() ) {
    824                 wpmu_signup_user_notification( $signup->user_login, $signup->user_email, $signup->activation_key, serialize( $meta ) );
     828                // Should we send the user or blog activation email?
     829                if ( ! empty( $signup->domain ) || ! empty( $signup->path ) ) {
     830                    wpmu_signup_blog_notification( $signup->domain, $signup->path, $signup->title, $signup->user_login, $signup->user_email, $signup->activation_key, $meta );
     831                } else {
     832                    wpmu_signup_user_notification( $signup->user_login, $signup->user_email, $signup->activation_key, $meta );
     833                }
    825834            } else {
    826835
Note: See TracChangeset for help on using the changeset viewer.