rank-tools.php
6.45 KB
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
<?php
/**
* Rank Tools
*
* @package badgeos
* @subpackage Tools
* @author earningTimes, LLC
* @license http://www.gnu.org/licenses/agpl.txt GNU AGPL v3.0
* @link https://badgeos.org
*/
$rank_types = badgeos_get_ranks();
$args = array(
'role' => '',
'orderby' => 'nicename',
'order' => 'ASC',
'count_total' => false,
'fields' => array( 'ID', 'user_nicename' ),
);
$wp_users = get_users( $args );
?>
<div id="rank-tabs">
<div class="tab-title"><?php esc_attr_e( 'Rank Tools', 'badgeos' ); ?></div>
<ul>
<li>
<a href="#rank_bulk_award">
<i class="fa fa-trophy" aria-hidden="true"></i>
<?php esc_attr_e( 'Award Ranks In Bulk', 'badgeos' ); ?>
</a>
</li>
<li>
<a href="#rank_bulk_revoke">
<i class="fa fa-star-o" aria-hidden="true"></i>
<?php esc_attr_e( 'Revoke Ranks In Bulk', 'badgeos' ); ?>
</a>
</li>
</ul>
<div id="rank_bulk_award">
<form method="POST" class="rank-bulk-award" action="">
<table cellspacing="0">
<tbody>
<tr>
<th scope="row"><label for="rank_types"><?php esc_attr_e( 'Ranks to Award', 'badgeos' ); ?></label></th>
<td>
<select id="rank_types_to_award" data-placeholder="Select Rank to Award" name="badgeos_tools[award_rank_types][]" multiple="multiple" class="badgeos-select">
<?php
if ( is_array( $rank_types ) && ! empty( $rank_types ) ) {
foreach ( $rank_types as $rank_type ) {
echo '<option value="' . esc_attr( $rank_type->ID ) . '">' . esc_attr( $rank_type->post_title ) . '</option>';
}
}
?>
</select>
<span class="tool-hint"><?php esc_attr_e( 'Choose the ranks to award', 'badgeos' ); ?></span>
</td>
</tr>
<tr>
<th scope="row"><label for="all_users"><?php esc_attr_e( 'Award to All Users', 'badgeos' ); ?></label></th>
<td>
<div class="form-switcher form-switcher-lg form-switcher-sm-phone">
<input type="checkbox" name="badgeos_tools[award_all_users]" id="award-ranks" data-com.bitwarden.browser.user-edited="yes">
<label class="switcher" for="award-ranks"></label>
</div>
<span class="tool-hint"><?php esc_attr_e( 'Check this point to award ranks to all users', 'badgeos' ); ?></span>
</td>
</tr>
<tr>
<th scope="row"><label for="users"><?php esc_attr_e( 'Users to Award', 'badgeos' ); ?></label></th>
<td>
<select id="badgeos-award-users" name="badgeos_tools[award_users][]" data-placeholder="Select a user" multiple="multiple" class="badgeos-select">
<?php
$args = array(
'role' => '',
'orderby' => 'nicename',
'order' => 'ASC',
'count_total' => false,
'fields' => array( 'ID', 'user_nicename' ),
);
$wp_users = get_users( $args );
foreach ( $wp_users as $user ) :
?>
<option value="<?php echo esc_attr( $user->ID ); ?>" <?php selected( esc_attr( $user->ID ), 'disabled' ); ?>>
<?php echo esc_html( $user->user_nicename ); ?>
</option>
<?php endforeach; ?>
</select>
<span class="tool-hint"><?php esc_attr_e( 'Choose users to award', 'badgeos' ); ?></span>
</td>
</tr>
</tbody>
</table>
<?php wp_nonce_field( 'rank_bulk_award', 'rank_bulk_award' ); ?>
<input type="hidden" name="action" value="award_bulk_ranks">
<input type="submit" name="award_bulk_ranks" class="button button-primary" value="<?php esc_attr_e( 'Award Ranks', 'badgeos' ); ?>">
</form>
</div>
<div id="rank_bulk_revoke">
<form method="POST" class="rank_bulk_revoke" action="">
<table cellspacing="0">
<tbody>
<tr>
<th scope="row"><label for="rank_types"><?php esc_attr_e( 'Ranks to Revoke', 'badgeos' ); ?></label></th>
<td>
<select id="rank_types_to_revoke" data-placeholder="Select Ranks to Revoke" name="badgeos_tools[revoke_rank_types][]" multiple="multiple" class="badgeos-select">
<?php
if ( $wp_users ) {
$plucked = array();
foreach ( $wp_users as $wp_user ) {
$user_ranks = badgeos_get_user_ranks(
array(
'user_id' => absint( $wp_user->ID ),
)
);
if ( $user_ranks ) {
foreach ( $user_ranks as $user_rank ) {
if ( in_array( $user_rank->rank_id, $plucked, true ) ) {
continue;
}
$plucked[] = $user_rank->rank_id;
echo '<option value="' . esc_attr( $user_rank->rank_id ) . '">' . esc_attr( $user_rank->rank_title ) . '</option>';
}
}
}
}
?>
</select>
<span class="tool-hint"><?php esc_attr_e( 'Check this point to revoke ranks to all users', 'badgeos' ); ?></span>
</td>
</tr>
<tr>
<th scope="row"><label for="all_users"><?php esc_attr_e( 'Revoke to All Users', 'badgeos' ); ?></label></th>
<td>
<div class="form-switcher form-switcher-lg">
<input type="checkbox" name="badgeos_tools[revoke_all_users]" id="revoke-ranks" data-com.bitwarden.browser.user-edited="yes">
<label class="switcher" for="revoke-ranks"></label>
</div>
<span class="tool-hint"><?php esc_attr_e( 'Check this point to revoke ranks to all users', 'badgeos' ); ?></span>
</td>
</tr>
<tr>
<th scope="row"><label for="users"><?php esc_attr_e( 'Users to Revoke', 'badgeos' ); ?></label></th>
<td>
<select id="badgeos-revoke-users" name="badgeos_tools[revoke_users][]" data-placeholder="Select a user" multiple="multiple" class="badgeos-select">
<?php
$args = array(
'role' => '',
'orderby' => 'nicename',
'order' => 'ASC',
'count_total' => false,
'fields' => array( 'ID', 'user_nicename' ),
);
$wp_users = get_users( $args );
foreach ( $wp_users as $user ) :
?>
<option value="<?php echo esc_attr( $user->ID ); ?>">
<?php echo esc_html( $user->user_nicename ); ?>
</option>
<?php endforeach; ?>
</select>
<span class="tool-hint"><?php esc_attr_e( 'Choose users to revoke', 'badgeos' ); ?></span>
</td>
</tr>
</tbody>
</table>
<?php wp_nonce_field( 'rank_bulk_revoke', 'rank_bulk_revoke' ); ?>
<input type="hidden" name="action" value="revoke_bulk_ranks">
<input type="submit" name="revoke_bulk_ranks" class="button button-primary" value="<?php esc_attr_e( 'Revoke Ranks', 'badgeos' ); ?>">
</form>
</div>
</div>