Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/10/2018 12:44:33 PM (8 years ago)
Author:
djpaul
Message:

Members: add "IDs only" return format option for BP_Signup::get().

Fixes #7641

Props espellcaste

File:
1 edited

Legend:

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

    r11630 r11804  
    133133     *     @type string      $activation_key Activation key to search for.
    134134     *     @type string      $user_login     Specific user login to return.
     135     *     @type string      $fields         Which fields to return. Specify 'ids' to fetch a list of signups IDs.
     136     *                                       Default: 'all' (return BP_Signup objects).
    135137     * }
    136138     * @return array {
    137      *     @type array $signups Located signups.
     139     *     @type array $signups Located signups. (IDs only if `fields` is set to `ids`.)
    138140     *     @type int   $total   Total number of signups matching params.
    139141     * }
     
    152154                'activation_key' => '',
    153155                'user_login'     => '',
     156                'fields'         => 'all',
    154157            ),
    155158            'bp_core_signups_get_args'
     
    214217        }
    215218
    216         // Used to calculate a diff between now & last
    217         // time an activation link has been resent.
    218         $now = current_time( 'timestamp', true );
    219 
    220         foreach ( (array) $paged_signups as $key => $signup ) {
    221 
    222             $signup->id   = intval( $signup->signup_id );
    223 
    224             $signup->meta = ! empty( $signup->meta ) ? maybe_unserialize( $signup->meta ) : false;
    225 
    226             $signup->user_name = '';
    227             if ( ! empty( $signup->meta['field_1'] ) ) {
    228                 $signup->user_name = wp_unslash( $signup->meta['field_1'] );
     219        // We only want the IDs.
     220        if ( 'ids' === $r['fields'] ) {
     221            $paged_signups = wp_list_pluck( $paged_signups, 'signup_id' );
     222        } else {
     223
     224            // Used to calculate a diff between now & last
     225            // time an activation link has been resent.
     226            $now = current_time( 'timestamp', true );
     227
     228            foreach ( (array) $paged_signups as $key => $signup ) {
     229
     230                $signup->id   = intval( $signup->signup_id );
     231
     232                $signup->meta = ! empty( $signup->meta ) ? maybe_unserialize( $signup->meta ) : false;
     233
     234                $signup->user_name = '';
     235                if ( ! empty( $signup->meta['field_1'] ) ) {
     236                    $signup->user_name = wp_unslash( $signup->meta['field_1'] );
     237                }
     238
     239                // Sent date defaults to date of registration.
     240                if ( ! empty( $signup->meta['sent_date'] ) ) {
     241                    $signup->date_sent = $signup->meta['sent_date'];
     242                } else {
     243                    $signup->date_sent = $signup->registered;
     244                }
     245
     246                $sent_at = mysql2date('U', $signup->date_sent );
     247                $diff    = $now - $sent_at;
     248
     249                /**
     250                 * Add a boolean in case the last time an activation link
     251                 * has been sent happened less than a day ago.
     252                 */
     253                if ( $diff < 1 * DAY_IN_SECONDS ) {
     254                    $signup->recently_sent = true;
     255                }
     256
     257                if ( ! empty( $signup->meta['count_sent'] ) ) {
     258                    $signup->count_sent = absint( $signup->meta['count_sent'] );
     259                } else {
     260                    $signup->count_sent = 1;
     261                }
     262
     263                $paged_signups[ $key ] = $signup;
    229264            }
    230 
    231             // Sent date defaults to date of registration.
    232             if ( ! empty( $signup->meta['sent_date'] ) ) {
    233                 $signup->date_sent = $signup->meta['sent_date'];
    234             } else {
    235                 $signup->date_sent = $signup->registered;
    236             }
    237 
    238             $sent_at = mysql2date('U', $signup->date_sent );
    239             $diff    = $now - $sent_at;
    240 
    241             /**
    242              * Add a boolean in case the last time an activation link
    243              * has been sent happened less than a day ago.
    244              */
    245             if ( $diff < 1 * DAY_IN_SECONDS ) {
    246                 $signup->recently_sent = true;
    247             }
    248 
    249             if ( ! empty( $signup->meta['count_sent'] ) ) {
    250                 $signup->count_sent = absint( $signup->meta['count_sent'] );
    251             } else {
    252                 $signup->count_sent = 1;
    253             }
    254 
    255             $paged_signups[ $key ] = $signup;
    256265        }
    257266
     
    272281
    273282        return array( 'signups' => $paged_signups, 'total' => $total_signups );
    274 
    275283    }
    276284
Note: See TracChangeset for help on using the changeset viewer.