/
front_register.php
371 lines (291 loc) · 10.8 KB
/
front_register.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
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
<?php
class Designmodo_registration_form
{
private $username;
private $email;
private $password;
private $first_name;
private $estimezone;
private $esgame;
private $gamebox;
function __construct()
{
add_shortcode('dm_registration_form', array($this, 'shortcode'));
add_action('wp_enqueue_scripts', array($this, 'flat_ui_kit'));
}
function tz_list() {
$zones_array = array();
$timestamp = time();
foreach(timezone_identifiers_list() as $key => $zone) {
date_default_timezone_set($zone);
$zones_array[$key]['zone'] = $zone;
$zones_array[$key]['diff_from_GMT'] = 'UTC/GMT ' . date('P', $timestamp);
}
return $zones_array;
}
function select_game() {
global $wpdb;
$sel="";
$table1 = $wpdb->prefix . 'iggame';
$tableedit = $wpdb->prefix . 'iggamelist';
global $wpdb;
$team_rec= $wpdb->get_results(
"SELECT * FROM $table1"
);
for($i=0;$i<count($team_rec);$i++):
echo '<input type="checkbox" value="'.$team_rec[$i]->id.'" name="gamebox[]"
/>'.$team_rec[$i]->name.'</br>';
endfor;
}
public function registration_form()
{
if (is_user_logged_in()) {
$current_user = wp_get_current_user();
echo 'Welcome '.$current_user ->user_firstname;
}
else{
?>
<form method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" id="game_register">
<div class="login-form">
<div class="form-group">
<label class="login-field-icon fui-user" for="reg-name">User Name</label>
<input name="reg_name" type="text" class="form-control login-field"
value="<?php echo(isset($_POST['reg_name']) ? $_POST['reg_name'] : null); ?>"
id="reg-name" required/>
</div>
<div class="form-group">
<label class="login-field-icon fui-lock" for="reg-pass">Password</label>
<input name="reg_password" type="password" class="form-control login-field"
value="<?php echo(isset($_POST['reg_password']) ? $_POST['reg_password'] : null); ?>"
id="reg-pass" required/>
</div>
<div class="form-group">
<label class="login-field-icon fui-mail" for="reg-email">Email</label>
<input name="reg_email" type="email" class="form-control login-field"
value="<?php echo(isset($_POST['reg_email']) ? $_POST['reg_email'] : null); ?>"
id="reg-email" required/>
</div>
<div class="form-group">
<label class="login-field-icon fui-user" for="estimezone">TimeZone</label>
<select name="estimezone" name="estimezone">
<option value="0">Please, select timezone</option>
<?php foreach(self::tz_list() as $t) {
if($exp_timezone==$t['zone']) {
$sel="selected=selected";
}
else {
$sel="";
}
?>
<option value="<?php print $t['zone'] ?>" <?php echo $sel;?>>
<?php print $t['diff_from_GMT'] . ' - ' . $t['zone'] ?>
</option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label>Favourite Games </label>
<?php self::select_game();?>
</div>
<input class="btn btn-primary btn-lg btn-block" type="submit" name="reg_submit" value="Register"/>
</div>
</form>
<?php
}
}
function validation()
{
if (empty($this->username) || empty($this->password) || empty($this->email)) {
return new WP_Error('field', 'Required form field is missing');
}
if (strlen($this->username) < 4) {
return new WP_Error('username_length', 'Username too short. At least 4 characters is required');
}
if (strlen($this->password) < 5) {
return new WP_Error('password', 'Password length must be greater than 5');
}
if (!is_email($this->email)) {
return new WP_Error('email_invalid', 'Email is not valid');
}
if (email_exists($this->email)) {
return new WP_Error('email', 'Email Already in use');
}
$details = array('Username' => $this->username,
'First Name' => $this->first_name,
);
foreach ($details as $field => $detail) {
if (!validate_username($detail)) {
return new WP_Error('name_invalid', 'Sorry, the "' . $field . '" you entered is not valid');
}
}
}
function registration()
{
$userdata = array(
'user_login' => esc_attr($this->username),
'user_email' => esc_attr($this->email),
'user_pass' => esc_attr($this->password),
'first_name' => esc_attr($this->first_name),
'estimezone' => esc_attr($this->estimezone),
'gamebox' => esc_attr($this->gamebox),
);
if (is_wp_error($this->validation())) {
echo '<div style="margin-bottom: 6px" class="btn btn-block btn-lg btn-danger">';
echo '<strong>' . $this->validation()->get_error_message() . '</strong>';
echo '</div>';
} else {
$register_user = wp_insert_user($userdata);
if (!is_wp_error($register_user)) {
echo '<div style="margin-bottom: 6px" class="btn btn-block btn-lg btn-danger">';
echo '<strong>Registration complete. Goto <a href="' . wp_login_url() . '">login page</a></strong>';
echo '</div>';
} else {
echo '<div style="margin-bottom: 6px" class="btn btn-block btn-lg btn-danger">';
echo '<strong>' . $register_user->get_error_message() . '</strong>';
echo '</div>';
}
$to= esc_attr($this->email);
$admin_email = get_option( 'admin_email' );
$blog_title = get_bloginfo('name');
$message='Your Username is: <b>'.esc_attr($this->username).'</b>';
$subject= 'Username For '.$blog_title;
$headers .= 'From: '.$blog_title.' '.$admin_email. "\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
wp_mail( $to, $subject, $message, $headers);
}
}
function flat_ui_kit()
{
wp_enqueue_style('bootstrap-css', plugins_url('bootstrap/css/bootstrap.css', __FILE__));
wp_enqueue_style('flat-ui-kit', plugins_url('css/flat-ui.css', __FILE__));
}
function shortcode()
{
ob_start();
if (!empty($_POST['reg_submit']) && $_POST['reg_submit']) {
$this->username = $_POST['reg_name'];
$this->email = $_POST['reg_email'];
$this->password = $_POST['reg_password'];
$this->first_name = $_POST['reg_name'];
$this->estimezone = $_POST['estimezone'];
if(!empty($_POST['gamebox'])) $this->gamebox = implode(",",$_POST['gamebox']);
$this->validation();
$this->registration();
}
$this->registration_form();
return ob_get_clean();
}
}
new Designmodo_registration_form;
//////////* Extra Field *////////
add_action('register_form','show_extrafield');
add_action('register_post','check_fields',10,3);
add_action('user_register', 'register_extra_fields');
function show_extrafield()
{
?>
<select name="estimezone" name="estimezone">
<option value="0">Please, select timezone</option>
<?php foreach(tz_list() as $t) {
if($exp_timezone==$t['zone']) {
$sel="selected=selected";
}
else {
$sel="";
}
?>
<option value="<?php print $t['zone'] ?>" <?php echo $sel;?>>
<?php print $t['diff_from_GMT'] . ' - ' . $t['zone'] ?>
</option>
<?php } ?>
</select>
<?php
}
function check_fields ( $login, $email, $errors )
{
global $estimezone;
$estimezone = $_POST['estimezone'];
$gamebox = implode(",",$_POST['gamebox']);
}
function register_extra_fields ( $user_id, $password = "", $meta = array() )
{
update_user_meta( $user_id, 'estimezone', $_POST['estimezone'] );
if(!empty($_POST['gamebox'])) update_user_meta( $user_id, 'gamebox', implode(",",$_POST['gamebox']) );
}
///////* Backend Edition */////////
add_action( 'show_user_profile', 'add_extra_profile' );
add_action( 'edit_user_profile', 'add_extra_profile' );
function add_extra_profile( $user )
{
function select_game($id) {
global $wpdb;
$sel="";
$table1 = $wpdb->prefix . 'iggame';
$tableedit = $wpdb->prefix . 'iggamelist';
global $wpdb;
$team_rec= $wpdb->get_results(
"SELECT * FROM $table1"
);
$temp_data= explode(",",get_the_author_meta('gamebox', $id ));
function objectToArray ($object) {
if(!is_object($object) && !is_array($object))
return $object;
return array_map('objectToArray', (array) $object);
}
foreach ($team_rec as $key => $obj)
{
$flag = '';
$objtoarr=json_decode(json_encode($obj),TRUE);
for($k=0;$k<count($temp_data);$k++):
if (in_array($temp_data[$k],$objtoarr))
{
$flag = 'checked';
}
endfor;
echo '<input type="checkbox" '. $flag
. ' value="' . $team_rec[$key]->id
. '" name="gamebox[]"/>' . $team_rec[$key]->name
. '</br>';
}
}
?>
<h3>Game Option fields</h3>
<table class="form-table">
<tr>
<th><label for="estimezone">Timezone</label></th>
<td><input type="text" name="estimezone" value="<?php echo esc_attr(get_the_author_meta( 'estimezone', $user->ID ));?>" readonly class="regular-text" /></td>
</tr>
<tr>
<th><label for="gamebox">Favourite Games</label></th> <td> <?php select_game($user->ID);?> </td>
</tr>
</table>
<?php
}
add_action( 'personal_options_update', 'save_extra_social_links' );
add_action( 'edit_user_profile_update', 'save_extra_social_links' );
function save_extra_social_links( $user_id )
{
update_user_meta( $user_id,'estimezone', sanitize_text_field( $_POST['estimezone'] ) );
update_user_meta( $user_id,'gamebox', implode(",",$_POST['gamebox'] ));
}
function ematcheslogin( $atts, $content = null ) {
$current_user = wp_get_current_user();
$form="";
extract( shortcode_atts( array(
'redirect' => ''
), $atts ) );
if (!is_user_logged_in()) {
if($redirect) {
$redirect_url = $redirect;
} else {
$redirect_url = get_permalink();
}
$form = wp_login_form(array('echo' => false, 'redirect' => $redirect_url,'label_username' => __( 'Email' )));
return '<div class="gm_loginform"><a href="'.site_url().'/register">Not a Member, Register Now</a>'.$form .'</div>
<a href="'.wp_lostpassword_url( get_bloginfo('url') ).'" title="Lost Password">Lost Password</a>';
}
else{
return '<div class="gm_loginform">Welcome '.$current_user->user_firstname.'</div>';
}
}
add_shortcode('esloginform', 'ematcheslogin');