forked from buddypress/wp-cli-buddypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponent.php
56 lines (50 loc) · 1.02 KB
/
component.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* Base component class.
*
* @since 1.0
*/
class BPCLI_Component extends \WP_CLI\CommandWithDBObject {
/**
* Get a random user id.
*
* @since 1.1
*
* @return int
*/
protected function get_random_user_id() {
global $wpdb;
return $wpdb->get_var( "SELECT ID FROM $wpdb->users ORDER BY RAND() LIMIT 1" );
}
/**
* Get a random group id.
*
* @since 1.1
*
* @return int
*/
protected function get_random_group_id() {
global $wpdb, $bp;
return $wpdb->get_var( "SELECT id FROM {$bp->groups->table_name} ORDER BY RAND() LIMIT 1" );
}
/**
* Verify a user ID by the passed identifier.
*
* Accepts a user_login or an ID.
*
* @since 1.2.0
*
* @return int
*/
protected function get_user_id_from_identifier( $i ) {
// @todo this'll be screwed up if user has a numeric user_login
if ( ! is_numeric( $i ) ) {
$user_id = (int) username_exists( $i );
} else {
$user_id = $i;
$user_obj = new WP_User( $user_id );
$user_id = $user_obj->ID;
}
return intval( $i );
}
}