[ create a new paste ] login | about

Link: http://codepad.org/d7MtD9i7    [ raw code | fork ]

PHP, pasted on Dec 27:
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
<?php
/**
 * Handles all data - both Facebook requests and local WP database reuests.
 */
class Wdfb_Model {
	var $fb;
	var $db;
	var $data;
	var $log;

	function __construct () {
		global $wpdb;
		$this->data =& Wdfb_OptionsRegistry::get_instance();
		$this->db = $wpdb;
		$this->fb = new Facebook(array(
			'appId' => trim($this->data->get_option('wdfb_api', 'app_key')),
			'secret' => trim($this->data->get_option('wdfb_api', 'secret_key')),
			'cookie' => true,
		));
		$this->fb->getLoginUrl(); // Generate the CSRF sig stuff yay
		$this->log = new Wdfb_ErrorLog;
	}

	function Wdfb_Model () {
		$this->__construct();
	}

	/**
	 * Returns all blogs on the current site.
	 */
	function get_blog_ids () {
		global $current_blog;
		$site_id = 0;
		if ($current_blog) {
			$site_id = $current_blog->site_id;
		}
		$sql = "SELECT blog_id FROM " . $this->db->blogs . " WHERE site_id={$site_id} AND public='1' AND archived= '0' AND spam='0' AND deleted='0' ORDER BY registered DESC";
		return $this->db->get_results($sql, ARRAY_A);
	}

	/**
	 * Logs the user out of the site and Facebook.
	 */
	function wp_logout ($redirect=false) {
		setcookie('fbsr_' . $this->fb->getAppId(), '', time()-100, '/', COOKIE_DOMAIN); // Yay for retardness in FB SDK
		@session_unset();
		@session_destroy();
		unset($_SESSION);
		wp_logout();
		wp_set_current_user(0);
		if ($redirect) wp_redirect($redirect);
	}

	/**
	 * Lists registered BuddyPress profile fields.
	 */
	function get_bp_xprofile_fields () {
		if (!defined('BP_VERSION')) return true;
		$tbl_pfx = function_exists('bp_core_get_table_prefix') ? bp_core_get_table_prefix() : apply_filters('bp_core_get_table_prefix', $this->db->base_prefix);
		$sql = "SELECT id, name FROM {$tbl_pfx}bp_xprofile_fields";
		return $this->db->get_results($sql, ARRAY_A);
	}

	/**
	 * Create/update the BuddyPress profile field.
	 */
	function set_bp_xprofile_field ($field_id, $user_id, $data) {
		if (!defined('BP_VERSION')) return true;

		$field_id = (int)$field_id;
		$user_id = (int)$user_id;
		if (!$field_id || !$user_id) return false;

		if (is_array($data)) $data = $data['name']; // For complex FB fields that return JSON objects
		if (!$data) return false; // Don't waste cycles if we don't need to

		$tbl_pfx = function_exists('bp_core_get_table_prefix') ? bp_core_get_table_prefix() : apply_filters('bp_core_get_table_prefix', $this->db->base_prefix);
		$sql = "SELECT id FROM {$tbl_pfx}bp_xprofile_data WHERE field_id={$field_id} AND user_id={$user_id}";
		$id = $this->db->get_var($sql);

		if ($id) {
			$sql = "UPDATE {$tbl_pfx}bp_xprofile_data SET data='" . $data . "' WHERE id={$id}";
		} else {
			$sql = "INSERT INTO {$tbl_pfx}bp_xprofile_data (field_id, user_id, value, last_updated) VALUES (" .
				(int)$field_id . ', ' . (int)$user_id . ", '" . $data . "', '" . date('Y-m-d H:i:s') . "')";
		}
		return $this->db->query($sql);
	}

	/**
	 * Gets FB profile image and sets it as BuddyPress avatar.
	 */
	function set_fb_image_as_bp_avatar ($user_id, $me) {
		if (!defined('BP_VERSION')) return true;
		if (!function_exists('bp_core_avatar_upload_path')) return true;
		if (!$me || !@$me['id']) return false;

		$fb_uid = $me['id'];

		if (function_exists('xprofile_avatar_upload_dir')) {
			$xpath = xprofile_avatar_upload_dir(false, $user_id);
			$path = $xpath['path'];
		} 
		if (!function_exists('xprofile_avatar_upload_dir') || empty($path)) {
			$object = 'user';
			$avatar_dir = apply_filters('bp_core_avatar_dir', 'avatars', $object);
			$path = bp_core_avatar_upload_path() . "/{$avatar_dir}/" . $user_id;
			$path = apply_filters('bp_core_avatar_folder_dir', $path, $user_id, $object, $avatar_dir);
			if (!realpath($path)) @wp_mkdir_p($path);
		}

		// Get FB picture
		//$fb_img = file_get_contents("http://graph.facebook.com/{$fb_uid}/picture?type=large");
		$page = wp_remote_get("http://graph.facebook.com/{$fb_uid}/picture?type=large", array(
			'method' 		=> 'GET',
			'timeout' 		=> '5',
			'redirection' 	=> '5',
			'user-agent' 	=> 'wdfb',
			'blocking'		=> true,
			'compress'		=> false,
			'decompress'	=> true,
			'sslverify'		=> false
		));
		if(is_wp_error($page)) return false; // Request fail
		if ((int)$page['response']['code'] != 200) return false; // Request fail
		$fb_img = $page['body'];
		
		$filename = md5($fb_uid);
		$filepath = "{$path}/{$filename}";
		file_put_contents($filepath, $fb_img);

		// Determine the right extension
		$info = getimagesize($filepath);
		$extension = false;

		if (function_exists('image_type_to_extension')) {
			$extension = image_type_to_extension($info[2], false);
		} else {
			switch ($info[2]) {
				case IMAGETYPE_GIF:
					$extension = 'gif';
					break;
				case IMAGETYPE_JPEG:
					$extension = 'jpg';
					break;
				case IMAGETYPE_PNG:
					$extension = 'png';
					break;
			}
		}
		// Unknown file type, clean up
		if (!$extension) {
			@unlink($filepath);
			return false;
		}
		$extension = 'jpeg' == strtolower($extension) ? 'jpg' : $extension; // Forcing .jpg extension for JPEGs

		// Clear old avatars
		$imgs = glob($path . '/*.{gif,png,jpg}', GLOB_BRACE);
		if (is_array($imgs)) foreach ($imgs as $old) {
			@unlink($old);
		}

		// Create and set new avatar
		if (defined('WDFB_BP_AVATAR_AUTO_CROP') && WDFB_BP_AVATAR_AUTO_CROP) {
			// Explicitly requested thumbnail processing
			// First, determine the centering position for cropping
			if ($info && isset($info[0]) && $info[0] && isset($info[1]) && $info[1]) {
				$full = apply_filters('wdfb-avatar-auto_crop', array(
					'x' => (int)(($info[0] - bp_core_avatar_full_width()) / 2),
					'y' => (int)(($info[1] - bp_core_avatar_full_height()) / 2),
					'width' => bp_core_avatar_full_width(),
					'height' => bp_core_avatar_full_height(),
				), $filepath, $info);
			}
			$crop = $full
				? wp_crop_image($filepath, $full['x'], $full['y'], $full['width'], $full['height'], bp_core_avatar_full_width(), bp_core_avatar_full_height(), false, "{$filepath}-bpfull.{$extension}")
				: false
			;
			if (!$crop) {
				@unlink($filepath);
				return false;
			}
			// Now, the thumbnail. First, try to resize the full avatar
			$thumb_file = wp_create_thumbnail("{$filepath}-bpfull.{$extension}", bp_core_avatar_thumb_width());
			if (!is_wp_error($thumb_file)) {
				// All good! We're done - clean up
				copy($thumb_file, "{$filepath}-bpthumb.{$extension}");
				@unlink($thumb_file);
			} else {
				// Sigh. Let's just fake it by using the original file then.
				copy("{$filepath}-bpfull.{$extension}", "{$filepath}-bpthumb.{$extension}");
			}
			@unlink($filepath);
			return true;
		} else {
			// No auto-crop, move on
			copy($filepath, "{$filepath}-bpfull.{$extension}");
			copy($filepath, "{$filepath}-bpthumb.{$extension}");
			@unlink($filepath);
			return true;
		}

		return false;
	}

	function get_all_user_tokens () {
		$sql = "SELECT * FROM " . $this->db->base_prefix . "usermeta WHERE meta_key='wdfb_api_accounts'";
		return $this->db->get_results($sql, ARRAY_A);
	}
	
	/**
	 * Gets an existing app token for the user.
	 */
	function get_user_api_token ($fb_uid) {
		global $current_user;
		$meta = get_user_meta($current_user->id, 'wdfb_api_accounts', true);
		$token = isset($meta['auth_tokens']) ? $meta['auth_tokens'] : array();
		if (!$token) return false;
		if (!isset($token[$fb_uid])) return false;
		return $token[$fb_uid];
	}

	function comment_already_imported ($fb_cid) {
		if (!$fb_cid) return false;
		$key = '%s:13:"fb_comment_id";s:' . strlen($fb_cid) . ':"' . $fb_cid . '";%';
		$sql = "SELECT meta_id FROM " . $this->db->prefix . "commentmeta WHERE meta_value LIKE '{$key}'";
		return $this->db->get_var($sql);
	}

	function get_wp_user_from_fb () {
		$fb_user_id = $this->fb->getUser();

		$sql = "SELECT user_id FROM " . $this->db->base_prefix . "usermeta WHERE meta_key='wdfb_fb_uid' AND meta_value=%s";
		$res = $this->db->get_results($this->db->prepare($sql, $fb_user_id), ARRAY_A);
		if ($res) return $res[0]['user_id'];

		// User not yet linked. Try finding her by email.
		$me = false;
		try {
			$me = $this->fb->api('/me');
		} catch (Exception $e) {
			return false;
		}
		if (!$me || !isset($me['email'])) return false;

		$sql = "SELECT ID FROM " . $this->db->base_prefix . "users WHERE user_email=%s";
		$res = $this->db->get_results($this->db->prepare($sql, $me['email']), ARRAY_A);

		if (!$res) return false;

		return $this->map_fb_to_wp_user($res[0]['ID']);
		
		
		}

	function get_fb_user_from_wp ($wp_uid) {
		$fb_uid = get_user_meta($wp_uid, 'wdfb_fb_uid', true);
		return $fb_uid;
	}

	function map_fb_to_wp_user ($wp_uid) {
		if (!$wp_uid) return false;
		update_user_meta($wp_uid, 'wdfb_fb_uid', $this->fb->getUser());
		return $wp_uid;
	}

	function map_fb_to_current_wp_user () {
		$user = wp_get_current_user();
		$id = $user->ID;
		$this->map_fb_to_wp_user($id);

	}

	function register_fb_user () {
		$uid = $this->get_wp_user_from_fb();
		if ($uid) return $this->map_fb_to_wp_user($uid);

		return $this->create_new_wp_user_from_fb();
	}

	function delete_wp_user ($uid) {
		$uid = (int)$uid;
		if (!$uid) return false;
		$this->db->query("DELETE FROM {$this->db->users} WHERE ID={$uid}");
		$this->db->query("DELETE FROM {$this->db->usermeta} WHERE user_id={$uid}");
	}

	function create_new_wp_user_from_fb () {
		$send_email = false;
		$reg = (array)((isset($this->fb->registration) && $this->fb->registration) ? $this->fb : $this->fb->getSignedRequest());
		$registration = isset($reg['registration']) ? $reg['registration'] : array();
		try {
			$me = $this->fb->api('/me');
		} catch (Exception $e) {
			$me = $registration;
			$send_email = true; // we'll need to notify the user
			$me['id'] = $this->fb->user_id;
		}
		if (!$me) return false;

		$username = $this->_create_username_from_fb_response($me);
		$password = wp_generate_password(12, false);
		$user_id = wp_create_user($username, $password, $me['email']);

		if (is_wp_error($user_id)) {
			$this->log->error(__FUNCTION__, new Exception($user_id->get_error_message()));
			return false;
		} else if ($send_email) {
			wp_new_user_notification($user_id, $password);
			do_action('wdfb-registration_email_sent');
		}

		// Allow others to process the fields
		do_action('wdfb-user_registered', $user_id, $registration);

		// Allow other actions - e.g. posting to Facebook, upon registration
		do_action('wdfb-user_registered-postprocess', $user_id, $me, $registration, $this);

		if (defined('BP_VERSION')) $this->populate_bp_fields_from_fb($user_id, $me); // BuddyPress
		else $this->populate_wp_fields_from_fb($user_id, $me); // WordPress

		return $this->map_fb_to_wp_user($user_id);
	}

	function populate_bp_fields_from_fb ($user_id, $me=false) {
		if (!defined('BP_VERSION')) return true;
		if (!$me) {
			try {
				$me = $this->fb->api('/me');
			} catch (Exception $e) {
				return false;
			}
			if (!$me) return false;
		}

		$this->set_fb_image_as_bp_avatar($user_id, $me);

		$bp_fields = $this->get_bp_xprofile_fields();
		if (is_array($bp_fields)) foreach ($bp_fields as $bpf) {
			$fb_value = $this->data->get_option('wdfb_connect', 'buddypress_registration_fields_' . $bpf['id']);
			if ($fb_value && @$me[$fb_value]) $this->set_bp_xprofile_field($bpf['id'], $user_id, @$me[$fb_value]);
		}
		return true;
	}

	function populate_wp_fields_from_fb ($user_id, $me=false) {
		if (!$me) {
			try {
				$me = $this->fb->api('/me');
			} catch (Exception $e) {
				return false;
			}
			if (!$me) return false;
		}
		$wp_mappings = $this->data->get_option('wdfb_connect', 'wordpress_registration_fields');

		if (is_array($wp_mappings)) foreach($wp_mappings as $map) {
			if (!$map['wp'] || !$map['fb'] || !@$me[$map['fb']]) continue;
			if (is_array(@$me[$map['fb']]) && isset($me[$map['fb']]['name'])) $data = @$me[$map['fb']]['name'];
			else if (is_array(@$me[$map['fb']]) && isset($me[$map['fb']][0])) $data = join(', ', array_map(create_function('$m', 'return $m["name"];'), $me[$map['fb']]));
			else $data = @$me[$map['fb']];
			update_user_meta($user_id, $map['wp'], $data);
		}


		return true;
	}

	function get_user_data_for ($for=false) {
		if (!$for) return false;
		try {
			$data = $this->fb->api("/{$for}");
		} catch (Exception $e) {
			return false;
		}
		return $data;
	}

	function get_current_wp_user_data () {
		$user = wp_get_current_user();
		if (!$user || !$user->ID) return false; // User not logged into WP, skip
		$fb_uid = get_user_meta($user->ID, 'wdfb_fb_uid', true);
		return $this->get_user_data_for($fb_uid);
	}

	function get_current_fb_user_data () {
		return $this->get_user_data_for('me');
	}

	function get_current_user_fb_id () {
		$fb_uid = $this->fb->getUser();
		if ($fb_uid) return $fb_uid; // User is logged into FB, use that

		$user = wp_get_current_user();
		if (!$user || !$user->ID) return false; // User not logged into WP, skip

		$fb_uid = get_user_meta($user->ID, 'wdfb_fb_uid', true);
		return $fb_uid;
	}

	function get_pages_tokens ($token=false) {
		$fid = $this->get_current_user_fb_id();
		if (!$fid) return false;

		$token = $token ? $token : $this->get_user_api_token($fid);
		/*
		$token = $token ? "?access_token={$token}" : '';
		try {
			//$ret = $this->fb->api('/' . $fid . '/accounts/');
			$ret = $this->fb->api('/' . $fid . '/accounts/' . $token);
		} catch (Exception $e) {
			return false;
		}
		return $ret;
		*/
		$url = "https://graph.facebook.com/{$fid}/accounts?access_token={$token}";
		$page = wp_remote_get($url, array(
			'method' 		=> 'GET',
			'timeout' 		=> '5',
			'redirection' 	=> '5',
			'user-agent' 	=> 'wdfb',
			'blocking'		=> true,
			'compress'		=> false,
			'decompress'	=> true,
			'sslverify'		=> false
		));

		if(is_wp_error($page)) return false; // Request fail
		if ((int)$page['response']['code'] != 200) return false; // Request fail

		return (array)@json_decode($page['body']);
	}

	function post_on_facebook ($type, $fid, $post, $as_page=false) {
		$type = $type ? $type : 'feed';
		
		$fid = $fid ? $fid : $this->get_current_user_fb_id();
		$token = $this->get_user_api_token($fid);

		// Events sanity check
		if ('events' == $type && (!@$post['start_time'] || !@$post['end_time'])) return false;

		//$post['auth_token'] = $tokens[$fid];
		if (!$token) {
			$tokens = $this->data->get_option('wdfb_api', 'auth_tokens');
			$token = $tokens[$fid];
		}
		$post['access_token'] = $token;
		
		$title = ('feed' == $type) ? @$post['message'] : '';
		$_ap = $as_page ? 'as page' : '';
		$this->log->notice("Posting {$title} to Facebook [{$type}] - [{$fid}] {$_ap} [{$token}].");

		/*
		if ($as_page) {
			try {
				$resp = $this->fb->api($fid, array('auth_token' => $tokens[$fid]));
			} catch (Exception $e) {
				$this->log->notice("Unable to post to Facebook as page.");
			}
			
			// can_post checks perms for posting as user
			if (@$resp['can_post']) $post['access_token'] = $tokens[$fid];
			else $this->log->notice("Unable to post to Facebook as page.");
		}
		*/

		try {
			$ret = $this->fb->api('/' . $fid . '/' . $type . '/', 'POST', $post);
		} catch (Exception $e) {
			$this->log->error(__FUNCTION__, $e);
			return false;
		}
		$this->log->notice("Posting to Facebook finished.");
		return $ret;
	}

	function get_events_for ($for) {
		if (!$for) return false;

		$tokens = $this->data->get_option('wdfb_api', 'auth_tokens');
		$token = $tokens[$for];

		try {
			$res = $this->fb->api('/' . $for . '/events/?auth_token=' . $token);
		} catch (Exception $e) {
			return false;
		}
		return $res;
	}

	function get_albums_for ($for) {
		if (!$for) return false;

		$tokens = $this->data->get_option('wdfb_api', 'auth_tokens');
		$token = $tokens[$for];

		try {
			$res = $this->fb->api('/' . $for . '/albums/?auth_token=' . $token);
		} catch (Exception $e) {
			return false;
		}
		return $res;
	}

	function get_current_albums () {
		$user = wp_get_current_user();
		$fb_accounts = get_user_meta($user->ID, 'wdfb_api_accounts', true);
		$fb_accounts = isset($fb_accounts['auth_accounts']) ? $fb_accounts['auth_accounts'] : false;
		if (!$fb_accounts) return false;
		$albums = array('data'=>array());
		foreach ($fb_accounts as $fid => $label) {
			$res = $this->get_albums_for($fid);
			if (!$res) continue;
			$albums['data'] = array_merge($albums['data'], $res['data']);
		}
		return $albums ? $albums : false;
	}

	function get_album_photos ($aid, $limit=false, $offset=false) {
		if (!$aid) return false;
		$page_size = 25;
		$max_limit = apply_filters('wdfb-albums-max_photos_limit', 
			(defined('WDFB_ALBUMS_MAX_PHOTOS_LIMIT') && WDFB_ALBUMS_MAX_PHOTOS_LIMIT ? WDFB_ALBUMS_MAX_PHOTOS_LIMIT : 200)
		);

		if ($limit && $limit > $page_size) {
			$limit = $limit > $max_limit ? $max_limit : $limit;
			$batch = array();
			for ($i=0; $i<$limit; $i+=$page_size) {
				$batch[] = json_encode(array(
					'method' => 'GET',
					'relative_url' => "/{$aid}/photos/?limit={$page_size}&offset={$i}&fields=id,name,picture,source,height,width,images,link,icon,created_time,updated_time"
				));
			}
			try {
				$res = $this->fb->api('/', 'POST', array('batch' => '[' . implode(',',$batch) . ']'));
			} catch (Exception $e) {
				$this->log->error(__FUNCTION__, $e);
				return false;
			}
			$return = array();
			foreach ($res as $key => $data) {
				if (!$data || !isset($data['body'])) continue;
				$data = json_decode($data['body'],true);
				$return = array_merge($return, $data['data']);
			}
			return array('data' => $return);
		} else {
			$limit = $limit ? '?limit=' . $limit : '';
			try {
				$res = $this->fb->api('/' . $aid . '/photos/' . $limit);
			} catch (Exception $e) {
				$this->log->error(__FUNCTION__, $e);
				return false;
			}
			return $res;
		}
	}

	function get_feed_for ($uid, $limit=false) {
		if (!$uid) return false;
		$limit = $limit ? '?limit=' . $limit : '';

		$tokens = $this->data->get_option('wdfb_api', 'auth_tokens');
		$token = $tokens[$uid];

		$req = $limit ? $limit . '&auth_token=' . $token : '?auth_token=' . $token;

		try {
			$res = $this->fb->api('/' . $uid . '/feed/' . $req);
		} catch (Exception $e) {
			return false;
		}
		return $res;
	}

	function get_item_comments ($for) {
		$uid = $this->get_current_user_fb_id();

		$tokens = $this->data->get_option('wdfb_api', 'auth_tokens');
		$token = $tokens[$uid];

		try {
			$res = $this->fb->api('/' . $for . '/comments/?auth_token=' . $token);
		} catch (Exception $e) {
			$this->log->error(__FUNCTION__, $e);
			return false;
		}
		return $res;
	}

	function _create_username_from_fb_response ($me) {
		if (@$me['first_name'] && @$me['last_name']) {
			$name = preg_replace('/[^a-zA-Z0-9_]+/', '', ucfirst($me['first_name']) . '_' . ucfirst($me['last_name']));
		} else if (isset($me['name'])) {
			$name = $me['name'];
		} else {
			list($name, $rest) = explode('@', $me['email']);
		}
		$username = strtolower(preg_replace('/[^a-zA-Z0-9_]+/', '', $name));
		while (username_exists($username)) {
			$username .= rand();
		}
		return apply_filters('wdfb-registration-username', $username, $me);
	}
}


Create a new paste based on this one


Comments: