Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/03/2024 06:44:17 PM (22 months ago)
Author:
espellcaste
Message:

Misc changes to the signups and pending accounts.

We are improving how signups and pending accounts are handled in BuddyPress.

  • activation emails resend are blocked for one hour, by default;
  • emails are checked if they are already in use in a signup;
  • signup endpoint (https://developer.buddypress.org/bp-rest-api/reference/signup/) returns a useful error when feature is disabled;
  • Signup::resend: Added the ability to resend to a single ID, instead of an array of IDs.

Props niftythree and imath.

Closes https://github.com/buddypress/buddypress/pull/396
See #9229 and #9145
Fixes #9137

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/classes/class-bp-signup.php

    r13989 r14071  
    44 *
    55 * @package BuddyPress
    6  * @subpackage coreClasses
     6 * @subpackage Signup
    77 * @since 2.0.0
    88 */
     
    160160         * @since 2.0.0
    161161         *
    162          * @param integer $signup_id The ID for the signup being queried.
     162         * @param int $signup_id The ID for the signup being queried.
    163163         */
    164164        public function __construct( $signup_id = 0 ) {
     
    249249                 * was sent in the last day.
    250250                 */
    251                 $this->recently_sent = $this->count_sent && ( $diff < 1 * DAY_IN_SECONDS );
    252 
     251                $this->recently_sent = $this->count_sent && ( $diff < DAY_IN_SECONDS );
    253252        }
    254253
     
    827826         *
    828827         * @since 2.0.0
    829          *
    830          * @param array $signup_ids Single ID or list of IDs to resend.
     828         * @since 15.0.0 Added the ability to resend to a single ID.
     829         *
     830         * @param array|int $signup_ids Single ID or list of IDs to resend.
    831831         * @return array
    832832         */
    833833        public static function resend( $signup_ids = array() ) {
    834                 if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) {
    835                         return false;
     834                if ( empty( $signup_ids ) ) {
     835                        return array();
     836                }
     837
     838                if ( ! is_array( $signup_ids ) ) {
     839                        $signup_ids = array( $signup_ids );
    836840                }
    837841
    838842                $to_resend = self::get(
    839843                        array(
    840                                 'include' => $signup_ids,
     844                                'include' => wp_parse_id_list( $signup_ids ),
    841845                        )
    842846                );
    843847
    844                 if ( ! $signups = $to_resend['signups'] ) {
    845                         return false;
     848                $signups = $to_resend['signups'];
     849
     850                if ( ! $signups ) {
     851                        return array();
    846852                }
    847853
     
    876882                                $user_id = email_exists( $signup->user_email );
    877883
    878                                 if ( ! empty( $user_id ) && 2 != self::check_user_status( $user_id ) ) {
     884                                if ( ! empty( $user_id ) && 2 !== self::check_user_status( $user_id ) ) {
    879885
    880886                                        // Status is not 2, so user's account has been activated.
     
    886892                                        continue;
    887893
    888                                 // Send the validation email.
     894                                        // Send the validation email.
    889895                                } else {
    890896                                        $salutation = $signup->user_login;
     
    907913
    908914                /**
    909                  * Fires after activation emails are resent.
     915                 * Fires after activation email(s) are/is resent.
    910916                 *
    911917                 * @since 2.0.0
     
    924930                 */
    925931                return apply_filters( 'bp_core_signup_resend', $result );
     932        }
     933
     934        /**
     935         * Check if an activation email can be resent.
     936         *
     937         * @since 15.0.0
     938         *
     939         * @param BP_Signup $signup The signup object.
     940         * @return bool
     941         */
     942        public static function allow_activation_resend( $signup ) {
     943
     944                // Bail if the signup is not a BP_Signup object.
     945                if ( ! $signup instanceof BP_Signup ) {
     946                        return false;
     947                }
     948
     949                // Allow the activation email to be sent if not already.
     950                if ( ! $signup->recently_sent || ! $signup->count_sent ) {
     951                        return true;
     952                }
     953
     954                $sent_at = mysql2date( 'U', $signup->date_sent );
     955                $now     = time();
     956                $diff    = $now - $sent_at;
     957
     958                /**
     959                 * Filters the lock time for the resend activation.
     960                 *
     961                 * @since 15.0.0
     962                 *
     963                 * @param float|int $lock_time The lock time for the resend activation. Default: 1 hour.
     964                 * @param BP_Signup $signup The signup object.
     965                 */
     966                $lock_time = apply_filters( 'bp_core_signup_resend_activation_lock_time', HOUR_IN_SECONDS, $signup );
     967
     968                // If the activation email was sent less than the lock time ago.
     969                return false === ( $diff < $lock_time );
    926970        }
    927971
Note: See TracChangeset for help on using the changeset viewer.