Skip to:
Content

BuddyPress.org

Ticket #8540: 8540-change-active-handling.patch

File 8540-change-active-handling.patch, 3.7 KB (added by dcavins, 2 years ago)

Improve handling of active status in signups class.

  • 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 b0f1d6673..3b70c5999 100644
    class BP_Signup { 
    111111
    112112                // Cache missed, so query the DB.
    113113                if ( false === $signup ) {
    114                         $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->members->table_name_signups} WHERE signup_id = %d AND active = 0", $this->id ) );
     114                        $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->members->table_name_signups} WHERE signup_id = %d", $this->id ) );
    115115
    116116                        wp_cache_set( $this->id, $signup, 'bp_signups' );
    117117                }
    class BP_Signup { 
    187187         *                                       `registered`, `activated`. Default `signup_id`.
    188188         *     @type string      $order          Order direction. Default 'DESC'.
    189189         *     @type bool        $include        Whether or not to include more specific query params.
    190          *     @type string      $activation_key Activation key to search for.
     190         *     @type string      $activation_key Activation key to search for. If specified, all other
     191         *                                       parameters will be ignored.
     192         *     @type int|bool    $active         Pass 0 for inactive signups, 1 for active signups,
     193         *                                       and `false` to ignore.
    191194         *     @type string      $user_login     Specific user login to return.
    192195         *     @type string      $fields         Which fields to return. Specify 'ids' to fetch a list of signups IDs.
    193196         *                                       Default: 'all' (return BP_Signup objects).
    class BP_Signup { 
    210213                                'order'          => 'DESC',
    211214                                'include'        => false,
    212215                                'activation_key' => '',
     216                                'active'         => 0,
    213217                                'user_email'     => '',
    214218                                'user_login'     => '',
    215219                                'fields'         => 'all',
    class BP_Signup { 
    231235                $sql = array(
    232236                        'select'     => "SELECT DISTINCT signup_id",
    233237                        'from'       => "{$bp->members->table_name_signups}",
    234                         'where'      => array(
    235                                 'active = 0',
    236                         ),
     238                        'where'      => array(),
    237239                        'orderby'    => '',
    238240                        'limit'      => '',
    239241                );
    240242
    241                 if ( empty( $r['include'] ) ) {
     243                // Activation key trumps other parameters because it should be unique.
     244                if ( ! empty( $r['activation_key'] ) ) {
     245
     246                        $sql['where'][] = $wpdb->prepare( "activation_key = %s", $r['activation_key'] );
     247
     248                // `Include` finds signups by ID.
     249                } else if ( ! empty( $r['include'] ) ) {
     250
     251                        $in             = implode( ',', wp_parse_id_list( $r['include'] ) );
     252                        $sql['where'][] = "signup_id IN ({$in})";
     253
     254                /**
     255                 * Finally, the general case where a variety of parameters
     256                 * can be used in combination to find signups.
     257                 */
     258                } else {
     259
     260                        // Active.
     261                        if ( false !== $r['active'] ) {
     262                                $sql['where'][] = $wpdb->prepare( "active = %d", absint( $r['active'] ) );
     263                        }
    242264
    243265                        // Search terms.
    244266                        if ( ! empty( $r['usersearch'] ) ) {
    class BP_Signup { 
    246268                                $sql['where'][]    = $wpdb->prepare( "( user_login LIKE %s OR user_email LIKE %s OR meta LIKE %s )", $search_terms_like, $search_terms_like, $search_terms_like );
    247269                        }
    248270
    249                         // Activation key.
    250                         if ( ! empty( $r['activation_key'] ) ) {
    251                                 $sql['where'][] = $wpdb->prepare( "activation_key = %s", $r['activation_key'] );
    252                         }
    253 
    254271                        // User email.
    255272                        if ( ! empty( $r['user_email'] ) ) {
    256273                                $sql['where'][] = $wpdb->prepare( "user_email = %s", $r['user_email'] );
    class BP_Signup { 
    268285                        if ( -1 !== $number ) {
    269286                                $sql['limit'] = $wpdb->prepare( "LIMIT %d, %d", absint( $r['offset'] ), $number );
    270287                        }
    271                 } else {
    272                         $in             = implode( ',', wp_parse_id_list( $r['include'] ) );
    273                         $sql['where'][] = "signup_id IN ({$in})";
    274288                }
    275289
    276290                // Implode WHERE clauses.