d17b9051 by Marty Penner

Format and translate various methods/classes

1 parent 212a1099
...@@ -59,11 +59,11 @@ function login($username, $password, $remember = false) { ...@@ -59,11 +59,11 @@ function login($username, $password, $remember = false) {
59 throw new LogicException('Unable to login because headers have been sent'); 59 throw new LogicException('Unable to login because headers have been sent');
60 } 60 }
61 61
62 $auth = _signon(Array( 62 $auth = _signon([
63 'user_login' => esc_sql($username) 63 'user_login' => esc_sql($username)
64 , 'user_password' => esc_sql($password) 64 , 'user_password' => esc_sql($password)
65 , 'remember' => $remember 65 , 'remember' => $remember
66 )); 66 ]);
67 67
68 if (get_class($auth) == 'WP_User') { 68 if (get_class($auth) == 'WP_User') {
69 // This is done to ensure the auth'd user is logged in; cookie is not yet readable, redirect needed 69 // This is done to ensure the auth'd user is logged in; cookie is not yet readable, redirect needed
...@@ -124,7 +124,7 @@ function logout() { ...@@ -124,7 +124,7 @@ function logout() {
124 * @global $wpdb 124 * @global $wpdb
125 * @see wpmu_signup_user 125 * @see wpmu_signup_user
126 */ 126 */
127 function register($username, $email, $password, $meta = Array()) { 127 function register($username, $email, $password, $meta = []) {
128 global $wpdb; 128 global $wpdb;
129 require_once(ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'registration.php'); 129 require_once(ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'registration.php');
130 130
...@@ -138,11 +138,11 @@ function register($username, $email, $password, $meta = Array()) { ...@@ -138,11 +138,11 @@ function register($username, $email, $password, $meta = Array()) {
138 */ 138 */
139 $wpdb->query("DELETE FROM {$wpdb->signups} WHERE user_email='$email' AND active=0"); 139 $wpdb->query("DELETE FROM {$wpdb->signups} WHERE user_email='$email' AND active=0");
140 140
141 $user_data = Array( 141 $user_data = [
142 'username' => $username 142 'username' => $username
143 , 'password' => $password 143 , 'password' => $password
144 , 'email' => $email 144 , 'email' => $email
145 ); 145 ];
146 $meta['password'] = $password; 146 $meta['password'] = $password;
147 // array_filter($user_data, 'esc_sql'); 147 // array_filter($user_data, 'esc_sql');
148 148
...@@ -158,7 +158,7 @@ function register($username, $email, $password, $meta = Array()) { ...@@ -158,7 +158,7 @@ function register($username, $email, $password, $meta = Array()) {
158 $key = substr(md5(time() . rand() . $email ), 0, 16); 158 $key = substr(md5(time() . rand() . $email ), 0, 16);
159 $meta = serialize($meta); 159 $meta = serialize($meta);
160 160
161 $wpdb->insert($wpdb->signups, Array( 161 $wpdb->insert($wpdb->signups, [
162 'domain' => '', 162 'domain' => '',
163 'path' => '', 163 'path' => '',
164 'title' => '', 164 'title' => '',
...@@ -167,7 +167,7 @@ function register($username, $email, $password, $meta = Array()) { ...@@ -167,7 +167,7 @@ function register($username, $email, $password, $meta = Array()) {
167 'registered' => current_time('mysql', true), 167 'registered' => current_time('mysql', true),
168 'activation_key' => $key, 168 'activation_key' => $key,
169 'meta' => $meta 169 'meta' => $meta
170 )); 170 ]);
171 171
172 // do_action('ACTION_REGISTER'); ??? 172 // do_action('ACTION_REGISTER'); ???
173 173
...@@ -209,7 +209,7 @@ function activate($key, $password_validation = null) { ...@@ -209,7 +209,7 @@ function activate($key, $password_validation = null) {
209 throw new Exception('Unable to create user'); 209 throw new Exception('Unable to create user');
210 } 210 }
211 211
212 $wpdb->update($wpdb->signups, Array('active' => 1, 'activated' => current_time('mysql', true)), Array('activation_key' => $key)); 212 $wpdb->update($wpdb->signups, ['active' => 1, 'activated' => current_time('mysql', true)], ['activation_key' => $key]);
213 // $user_site = get_site_option('dashboard_blog', $current_site->blog_id); 213 // $user_site = get_site_option('dashboard_blog', $current_site->blog_id);
214 214
215 if (function_exists('add_user_to_blog')) { 215 if (function_exists('add_user_to_blog')) {
...@@ -240,16 +240,18 @@ class Validation extends Common\Validation { ...@@ -240,16 +240,18 @@ class Validation extends Common\Validation {
240 */ 240 */
241 protected function username($val) { 241 protected function username($val) {
242 if (empty($val)) { 242 if (empty($val)) {
243 throw new Exception('<li>Username is blank</li>'); 243 throw new Exception('<li>'.__('Username is blank', CBV_DOMAIN).'</li>');
244 } 244 }
245 245
246 require_once(ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'registration.php'); 246 require_once(ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'registration.php');
247 if (!validate_username($val)) { 247 if (!validate_username($val)) {
248 throw new Exception('<li>Username must be at least 4 characters, letters and numbers only</li>'); 248 throw new Exception(
249 '<li>'.__('Username must be at least 4 characters, letters and numbers only', CBV_DOMAIN).'</li>'
250 );
249 } 251 }
250 252
251 if (username_exists($val)) { 253 if (username_exists($val)) {
252 throw new Exception('<li>Username already exists</li>'); 254 throw new Exception('<li>'.__('Username already exists', CBV_DOMAIN).'</li>');
253 } 255 }
254 } 256 }
255 257
...@@ -260,15 +262,19 @@ class Validation extends Common\Validation { ...@@ -260,15 +262,19 @@ class Validation extends Common\Validation {
260 */ 262 */
261 protected function password($val) { 263 protected function password($val) {
262 if (empty($val)) { 264 if (empty($val)) {
263 throw new Exception('<li>Password can not be blank</li>'); 265 throw new Exception('<li>'.__('Password can not be blank', CBV_DOMAIN).'</li>');
264 } 266 }
265 267
266 if (isset($val[PASS_MAX_LEN])) { 268 if (isset($val[PASS_MAX_LEN])) {
267 throw new Exception('<li>Password can not be longer than ' . PASS_MAX_LEN . ' characters.</li>'); 269 throw new Exception(
270 '<li>'.sprintf(__('Password can not be longer than %d characters.', CBV_DOMAIN), PASS_MAX_LEN).'</li>'
271 );
268 } 272 }
269 273
270 if (preg_match('/(\\\\|\\\'|"| )+/i', $val)) { 274 if (preg_match('/(\\\\|\\\'|"| )+/i', $val)) {
271 throw new Exception('<li>Password can not contain spaces, backslashes (\) or quotes</li>'); 275 throw new Exception(
276 '<li>'.__('Password can not contain spaces, backslashes (\) or quotes', CBV_DOMAIN).'</li>'
277 );
272 } 278 }
273 } 279 }
274 280
...@@ -278,11 +284,11 @@ class Validation extends Common\Validation { ...@@ -278,11 +284,11 @@ class Validation extends Common\Validation {
278 */ 284 */
279 protected function email($val) { 285 protected function email($val) {
280 if (!(boolean)filter_var($val, FILTER_VALIDATE_EMAIL)) { 286 if (!(boolean)filter_var($val, FILTER_VALIDATE_EMAIL)) {
281 throw new Exception('<li>Invalid email address</li>'); 287 throw new Exception('<li>'.__('Invalid email address', CBV_DOMAIN).'</li>');
282 } 288 }
283 289
284 if (false !== email_exists($val)) { 290 if (false !== email_exists($val)) {
285 throw new Exception('<li>Email address already registered</li>'); 291 throw new Exception('<li>'.__('Email address already registered', CBV_DOMAIN).' </li > ');
286 } 292 }
287 } 293 }
288 } 294 }
...@@ -294,4 +300,3 @@ class Vars { ...@@ -294,4 +300,3 @@ class Vars {
294 */ 300 */
295 public static $options; 301 public static $options;
296 } 302 }
297 ?>
...\ No newline at end of file ...\ No newline at end of file
......