Skip to:
Content

BuddyPress.org

Ticket #8582: 85582.11.signups-changes.patch

File 85582.11.signups-changes.patch, 6.6 KB (added by dcavins, 22 months ago)

Changes to BP Signups found by working with them. Coninues earlier work on signups class.

  • src/bp-core/bp-core-filters.php

    diff --git src/bp-core/bp-core-filters.php src/bp-core/bp-core-filters.php
    index 85a8978d2..2f8a196de 100644
    function bp_core_activation_signup_blog_notification( $domain, $path, $title, $u 
    473473                ),
    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() ];
    487481                }
    function bp_core_activation_signup_user_notification( $user, $user_email, $key, 
    563557}
    564558add_filter( 'wpmu_signup_user_notification', 'bp_core_activation_signup_user_notification', 1, 4 );
    565559
     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' );
     584
    566585/**
    567586 * Filter the page title for BuddyPress pages.
    568587 *
  • src/bp-members/bp-members-functions.php

    diff --git src/bp-members/bp-members-functions.php src/bp-members/bp-members-functions.php
    index 93fd7cafd..ec4e651ed 100644
    function bp_core_signup_send_validation_email( $user_id, $user_email, $key, $sal 
    23882388        bp_send_email( 'core-user-registration', $to, $args );
    23892389
    23902390        // Record that the activation email has been sent.
    2391         $signups = BP_Signup::get(
    2392                 array(
    2393                         'activation_key' => $key,
    2394                 )
    2395         );
     2391        $signup = bp_members_get_signup_by( 'activation_key', $key );
    23962392
    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                         );
     2393        if ( $signup ) {
     2394                $meta = array(
     2395                        'sent_date'  => current_time( 'mysql', true ),
     2396                        'count_sent' => $signup->count_sent + 1
     2397                );
    24032398
    2404                         BP_Signup::update( array(
    2405                                 'signup_id' => $signup->id,
    2406                                 'meta'      => $meta,
    2407                         ) );
    2408                 }
     2399                BP_Signup::update( array(
     2400                        'signup_id' => $signup->id,
     2401                        'meta'      => $meta,
     2402                ) );
    24092403        }
    24102404}
    24112405
    function bp_get_members_invitation_from_request() { 
    36943688         */
    36953689        return apply_filters( 'bp_get_members_invitation_from_request', $invite );
    36963690}
     3691
     3692/**
     3693 * Get BP_Signup 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}
  • src/bp-members/classes/class-bp-members-admin.php

    diff --git src/bp-members/classes/class-bp-members-admin.php src/bp-members/classes/class-bp-members-admin.php
    index 979847a18..eadd2572a 100644
    class BP_Members_Admin { 
    22042204                ) );
    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.
    22102210                switch ( $action ) {
  • src/bp-members/classes/class-bp-signup.php

    diff --git src/bp-members/classes/class-bp-signup.php src/bp-members/classes/class-bp-signup.php
    index 9de2af9fe..e48d21da4 100644
    class BP_Signup { 
    214214                        $this->date_sent = $signup->registered;
    215215                }
    216216
     217                // How many times has the activation email been sent?
     218                if ( isset( $this->meta['count_sent'] ) ) {
     219                        $this->count_sent = absint( $this->meta['count_sent'] );
     220                } else {
     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
    217228                /**
    218229                 * Calculate a diff between now & last time
    219230                 * an activation link has been resent.
    class BP_Signup { 
    226237                 * Set a boolean to track whether an activation link
    227238                 * was sent in the last day.
    228239                 */
    229                 $this->recently_sent = ( $diff < 1 * DAY_IN_SECONDS );
     240                $this->recently_sent = $this->count_sent && ( $diff < 1 * DAY_IN_SECONDS );
    230241
    231                 // How many times has the activation email been sent?
    232                 if ( isset( $this->meta['count_sent'] ) ) {
    233                         $this->count_sent = absint( $this->meta['count_sent'] );
    234                 } else {
    235                         $this->count_sent = 0;
    236                 }
    237242        }
    238243
    239244        /** Static Methods *******************************************************/
    class BP_Signup { 
    814819
    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
    827836                                // Check user status before sending email.