WP_User.php
2.92 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
namespace FakerPress\Provider;
use Faker\Provider\Base;
use FakerPress;
class WP_User extends Base {
public function user_login( $login = null ) {
if ( is_null( $login ) ) {
$login = $this->generator->userName;
}
return $login;
}
public function user_pass( $pass = null, $qty = 10 ) {
if ( is_null( $pass ) ) {
if ( function_exists( 'wp_generate_password' ) ) {
$pass = wp_generate_password( $qty );
} else {
$pass = $this->generator->randomNumber( $qty - 1 ) . $this->generator->randomLetter();
}
}
return $pass;
}
public function role( $role = null ) {
if ( is_null( $role ) ) {
$role = array_keys( get_editable_roles() );
}
return $this->generator->randomElement( $role );
}
public function user_nicename( $nicename = null ) {
if ( is_null( $nicename ) ) {
$nicename = $this->generator->userName;
}
return $nicename;
}
public function user_url( $url = null ) {
if ( is_null( $url ) ) {
$url = $this->generator->url;
}
return $url;
}
public function user_email( $email = null ) {
if ( is_null( $email ) ) {
$email = $this->generator->safeEmail;
}
return $email;
}
public function display_name( $display_name = null, $gender = [ 'male', 'female' ] ) {
if ( is_null( $display_name ) ) {
$display_name = $this->generator->firstName( $this->generator->randomElements( $gender, 1 ) );
}
return $display_name;
}
public function nickname( $nickname = null ) {
if ( is_null( $nickname ) ) {
$nickname = $this->generator->userName;
}
return $nickname;
}
public function first_name( $first_name = null, $gender = [ 'male', 'female' ] ) {
if ( is_null( $first_name ) ) {
$first_name = $this->generator->firstName( $this->generator->randomElements( $gender, 1 ) );
}
return $first_name;
}
public function last_name( $last_name = null ) {
if ( is_null( $last_name ) ) {
$last_name = $this->generator->lastName;
}
return $last_name;
}
public function description( $html = true, $args = [] ) {
$defaults = [
'qty' => [ 5, 15 ],
];
$args = wp_parse_args( $args, $defaults );
if ( true === $html ) {
$content = implode( "\n", $this->generator->html_elements( $args ) );
} else {
$content = implode( "\r\n\r\n", $this->generator->paragraphs( FakerPress\Utils::instance()->get_qty_from_range( $args['qty'] ) ) );
}
return $content;
}
public function user_registered( $min = 'now', $max = null ) {
try {
$min = new \Carbon\Carbon( $min );
} catch ( Exception $e ) {
return null;
}
if ( ! is_null( $max ) ) {
// Unfortunatelly there is not such solution to this problem, we need to try and catch with DateTime
try {
$max = new \Carbon\Carbon( $max );
} catch ( Exception $e ) {
return null;
}
}
if ( ! is_null( $max ) ) {
$selected = $this->generator->dateTimeBetween( (string) $min, (string) $max )->format( 'Y-m-d H:i:s' );
} else {
$selected = (string) $min;
}
return $selected;
}
}