This repository has been archived by the owner on Dec 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Committee.php
69 lines (61 loc) · 2.76 KB
/
Committee.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
<?php
class Committee {
public function __construct() {
// Display option to add user to committee on their profile
add_action('show_user_profile', array($this, 'display_is_committee'));
add_action('edit_user_profile', array($this, 'display_is_committee'));
// Save changes to committee after any update to profile pages are made
add_action('personal_options_update', array($this, 'save_is_committee'));
add_action('edit_user_profile_update', array($this, 'save_is_committee'));
}
// Display a checkbox for toggling whether the user is a member of URN comittee or not
// and display a text field for naming their committee position
public function display_is_committee($user) {
if (esc_attr(get_the_author_meta('is_committee', $user->ID)) !== 'true') {
$checked = '';
$role = '';
}
else {
$checked = 'checked';
$role = esc_attr(get_the_author_meta('committee_role', $user->ID));
}
$disabled = current_user_can('administrator') ? '' : 'disabled';
$html = '<h3>Committee</h3>
<table class="form-table">
<tbody>
<tr>
<th>Status</th>
<td>
<label for="is_committee">
<input ' . $disabled . ' autocomplete="off"
name="is_committee" value="true"
id="is_committee" ' . $checked . ' type="checkbox">
Is a member of committee?
</label>
</td>
</tr>
<tr>
<th><label for="committee_role">Role</label></th>
<td><input ' . $disabled . ' autocomplete="off"
name="committee_role" id="committee_role"
value="' . $role .'" class="regular-text code"
type="text"></td>
</tr>
</tbody>
</table>';
echo $html;
}
// Update user's committee membership info
public function save_is_committee($user_id) {
if (current_user_can('administrator')) {
if (isset($_POST['is_committee']) && isset($_POST['committee_role'])) {
update_user_meta($user_id, 'is_committee', $_POST['is_committee']);
update_user_meta($user_id, 'committee_role', $_POST['committee_role']);
}
else {
update_user_meta($user_id, 'is_committee', 'false');
update_user_meta($user_id, 'committee_role', '');
}
}
}
}