Changeset 11804
- Timestamp:
- 01/10/2018 12:44:33 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-members/classes/class-bp-signup.php
r11630 r11804 133 133 * @type string $activation_key Activation key to search for. 134 134 * @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). 135 137 * } 136 138 * @return array { 137 * @type array $signups Located signups. 139 * @type array $signups Located signups. (IDs only if `fields` is set to `ids`.) 138 140 * @type int $total Total number of signups matching params. 139 141 * } … … 152 154 'activation_key' => '', 153 155 'user_login' => '', 156 'fields' => 'all', 154 157 ), 155 158 'bp_core_signups_get_args' … … 214 217 } 215 218 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; 229 264 } 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 link243 * 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;256 265 } 257 266 … … 272 281 273 282 return array( 'signups' => $paged_signups, 'total' => $total_signups ); 274 275 283 } 276 284 -
trunk/tests/phpunit/testcases/members/class-bp-signup.php
r11737 r11804 108 108 $ss = BP_Signup::get( array( 109 109 'offset' => 1, 110 ) ); 111 112 $this->assertEquals( array( $s2 ), wp_list_pluck( $ss['signups'], 'signup_id' ) ); 110 'fields' => 'ids', 111 ) ); 112 113 $this->assertEquals( array( $s2 ), $ss['signups'] ); 113 114 } 114 115 … … 123 124 $ss = BP_Signup::get( array( 124 125 'number' => 2, 125 ) ); 126 127 $this->assertEquals( array( $s3, $s2 ), wp_list_pluck( $ss['signups'], 'signup_id' ) ); 126 'fields' => 'ids', 127 ) ); 128 129 $this->assertEquals( array( $s3, $s2 ), $ss['signups'] ); 128 130 } 129 131 … … 140 142 $ss = BP_Signup::get( array( 141 143 'usersearch' => 'ghi', 142 ) ); 143 144 $this->assertEquals( array( $s1 ), wp_list_pluck( $ss['signups'], 'signup_id' ) ); 144 'fields' => 'ids', 145 ) ); 146 147 $this->assertEquals( array( $s1 ), $ss['signups'] ); 145 148 } 146 149 … … 162 165 'orderby' => 'email', 163 166 'number' => 3, 164 ) ); 165 166 // default order is DESC 167 $this->assertEquals( array( $s3, $s1, $s2 ), wp_list_pluck( $ss['signups'], 'signup_id' ) ); 167 'fields' => 'ids', 168 ) ); 169 170 // default order is DESC. 171 $this->assertEquals( array( $s3, $s1, $s2 ), $ss['signups'] ); 168 172 } 169 173 … … 186 190 'number' => 3, 187 191 'order' => 'ASC', 188 ) ); 189 190 $this->assertEquals( array( $s2, $s1, $s3 ), wp_list_pluck( $ss['signups'], 'signup_id' ) ); 192 'fields' => 'ids', 193 ) ); 194 195 $this->assertEquals( array( $s2, $s1, $s3 ), $ss['signups'] ); 191 196 } 192 197 … … 201 206 $ss = BP_Signup::get( array( 202 207 'include' => array( $s1, $s3 ), 203 ) ); 204 205 $this->assertEquals( array( $s1, $s3 ), wp_list_pluck( $ss['signups'], 'signup_id' ) ); 208 'fields' => 'ids', 209 ) ); 210 211 $this->assertEquals( array( $s1, $s3 ), $ss['signups'] ); 206 212 } 207 213 … … 222 228 $ss = BP_Signup::get( array( 223 229 'activation_key' => 'bar', 224 ) ); 225 226 $this->assertEquals( array( $s2 ), wp_list_pluck( $ss['signups'], 'signup_id' ) ); 230 'fields' => 'ids', 231 ) ); 232 233 $this->assertEquals( array( $s2 ), $ss['signups'] ); 227 234 } 228 235 … … 243 250 $ss = BP_Signup::get( array( 244 251 'user_login' => 'zzzzfoo', 245 ) ); 246 247 $this->assertEquals( array( $s2 ), wp_list_pluck( $ss['signups'], 'signup_id' ) ); 252 'fields' => 'ids', 253 ) ); 254 255 $this->assertEquals( array( $s2 ), $ss['signups'] ); 248 256 } 249 257 … … 366 374 $this->assertEqualSets( $blogs, array_keys( $blogs ) ); 367 375 } 376 377 /** 378 * @group get 379 */ 380 public function test_get_signup_ids_only() { 381 $s1 = self::factory()->signup->create(); 382 $s2 = self::factory()->signup->create(); 383 $s3 = self::factory()->signup->create(); 384 385 $ss = BP_Signup::get( array( 386 'number' => 3, 387 'fields' => 'ids', 388 ) ); 389 390 $this->assertEquals( array( $s3, $s2, $s1 ), $ss['signups'] ); 391 } 368 392 }
Note: See TracChangeset
for help on using the changeset viewer.