-
Notifications
You must be signed in to change notification settings - Fork 3
/
mobile.php
98 lines (47 loc) · 1.69 KB
/
mobile.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
<?php
function wp4t_enable_mobile() {
global $current_user;
if(isset($_POST['status'])) {
if(empty($_POST['status'])) {
$enabled = false;
delete_user_meta($current_user->ID,'wpt_mobile_code');
}
else {
$enabled = true;
$code = sanitize_text_field($_POST['status']);
update_user_meta($current_user->ID,'wpt_mobile_code',$code);
}
} else {
$code = get_user_meta($current_user->ID,'wpt_mobile_code',true);
if($code)
$enabled = true;
else
$enabled = false;
}
if(!$enabled)
$code = wp_generate_password(20,false);
$enabled_checked = ($enabled) ? ' checked="checked" ' : '';
$disabled_checked = ($enabled) ? '' : ' checked="checked" ';
?>
<h1>Enable Mobile App</h2>
<form method="post" action="">
<input type="radio" name="status" value="<?php echo $code ?>" <?php echo $enabled_checked ?> > Enabled <input type="radio" name="status" value="" <?php echo $disabled_checked ?> > Disabled
<button>Update</button>
</form>
<?php
if($enabled)
printf('<p>Enter this code into the mobile app to enable role signups.</p><code>%s</code>',$code);
}
function wpt_mobile_user_check() {
global $wpdb;
if(isset($_GET['mobilekey'])) {
$key = sanitize_text_field($_GET['mobilekey']);
$sql = "SELECT user_id FROM $wpdb->usermeta WHERE meta_key='wpt_mobile_code' AND meta_value='$key' ";
$user_id = $wpdb->get_var($sql);
if($user_id) {
wp_set_current_user($user_id);
return true;
}
}
return false;
}