New User Approve - Version 1.0

Version Description

Download this release

Release Info

Developer picklewagon
Plugin Icon 128x128 New User Approve
Version 1.0
Comparing to
See all releases

Version 1.0

Files changed (3) hide show
  1. new-user-approve.php +264 -0
  2. readme.txt +38 -0
  3. ui.tabs.css +127 -0
new-user-approve.php ADDED
@@ -0,0 +1,264 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: New User Approve
4
+ Plugin URI: http://www.picklewagon.com/wordpress/new-user-approve
5
+ Description: This plugin allows administrators to approve users once they register. Only approved users will be allowed to access the blog.
6
+ Author: Josh Harrison
7
+ Version: 1.0
8
+ Author URI: http://www.picklewagon.com
9
+ */
10
+
11
+ // get the directory where this plugin is located
12
+ define('PW_NEWUSER_APPROVE_DIR', basename(dirname(__FILE__)));
13
+
14
+ // this file
15
+ define('PW_NEWUSER_APPROVE_FILE', PW_NEWUSER_APPROVE_DIR . '/' . basename(__FILE__));
16
+
17
+ // create the admin page in the users tab
18
+ function pw_approve_add_admin_pages() {
19
+ add_submenu_page('profile.php', 'Approve New Users', 'Approve New Users', 'edit_users', __FILE__, 'pw_approve_admin');
20
+ }
21
+
22
+ // create the view for the admin interface
23
+ function pw_approve_admin() {
24
+ // Query the users table
25
+ $wp_user_search = new WP_User_Search($_GET['usersearch'], $_GET['userspage']);
26
+
27
+ // Make the user objects
28
+ foreach ($wp_user_search->get_results() as $userid) {
29
+ $user = new WP_User($userid);
30
+ $status = get_usermeta($userid, 'pw_user_status');
31
+ if ($status == '') {
32
+ update_usermeta($userid, 'pw_user_status', 'pending');
33
+ $status = get_usermeta($userid, 'pw_user_status');
34
+ }
35
+ $user_status[$status][] = $user;
36
+ }
37
+
38
+ if (isset($_GET['user']) && isset($_GET['status'])) {
39
+ echo '<div id="message" class="updated fade"><p>User successfully updated.</p></div>';
40
+ }
41
+ ?>
42
+ <div class="wrap">
43
+ <h2>User Registration Approval</h2>
44
+ <br />
45
+ <div id="pw_approve_tabs">
46
+ <ul>
47
+ <li><a href="#pw_pending_users"><span>Users Pending Approval</span></a></li>
48
+ <li><a href="#pw_approved_users"><span>Approved Users</span></a></li>
49
+ <li><a href="#pw_denied_users"><span>Denied Users</span></a></li>
50
+ </ul>
51
+ <div id="pw_pending_users">
52
+ <?php pw_approve_table($user_status, 'pending', true, true); ?>
53
+ </div>
54
+ <div id="pw_approved_users">
55
+ <?php pw_approve_table($user_status, 'approved', false, true); ?>
56
+ </div>
57
+ <div id="pw_denied_users">
58
+ <?php pw_approve_table($user_status, 'denied', true, false); ?>
59
+ </div.
60
+ </div>
61
+ </div>
62
+
63
+ <script type="text/javascript">
64
+ //<![CDATA[
65
+ jQuery(document).ready(function($) {
66
+ $('#pw_approve_tabs > ul').tabs({ fx: { opacity: 'toggle' } });
67
+ });
68
+ //]]>
69
+ </script>
70
+ <?php
71
+ }
72
+
73
+ // the table that shows the registered users grouped by status
74
+ function pw_approve_table($users, $status, $approve, $deny) {
75
+ if (count($users[$status]) > 0) {
76
+ ?>
77
+ <table class="widefat">
78
+ <tbody>
79
+ <tr class="thead">
80
+ <th><?php _e('ID') ?></th>
81
+ <th><?php _e('Username') ?></th>
82
+ <th><?php _e('Name') ?></th>
83
+ <th><?php _e('E-mail') ?></th>
84
+ <?php if ($approve && $deny) { ?>
85
+ <th colspan="2" style="text-align: center"><?php _e('Actions') ?></th>
86
+ <?php } else { ?>
87
+ <th style="text-align: center"><?php _e('Actions') ?></th>
88
+ <?php } ?>
89
+ </tr>
90
+ </tbody>
91
+ <?php
92
+ // show each of the users
93
+ $row = 1;
94
+ foreach ($users[$status] as $user) {
95
+ $class = ($row % 2) ? '' : ' class="alternate"';
96
+ ?><tr <?php echo $class; ?>>
97
+ <td><?php echo $user->ID; ?></td>
98
+ <td><?php echo $user->user_login; ?></td>
99
+ <td><?php echo $user->first_name." ".$user->last_name; ?></td>
100
+ <td><?php echo $user->user_email; ?></td>
101
+ <?php if ($approve) { ?>
102
+ <td align="center"><a href="<?php echo get_settings('siteurl') . "/wp-admin/users.php?page=".PW_NEWUSER_APPROVE_FILE."&user=".$user->ID."&status=approve"; ?>"><?php _e('Approve') ?></a></td>
103
+ <?php } ?>
104
+ <?php if ($deny) { ?>
105
+ <td align="center"><a href="<?php echo get_settings('siteurl') . "/wp-admin/users.php?page=".PW_NEWUSER_APPROVE_FILE."&user=".$user->ID."&status=deny"; ?>"><?php _e('Deny') ?></a></td>
106
+ <?php } ?>
107
+ </tr><?php
108
+ $row++;
109
+ }
110
+ ?>
111
+ </table>
112
+ <?php
113
+ } else {
114
+ echo "<p>There are no users with a status of $status</p>";
115
+ }
116
+ }
117
+
118
+ // send an email to the admin to request approval
119
+ function pw_approve_request_approval_email() {
120
+ global $user_login, $user_email;
121
+
122
+ /* send email to admin for approval */
123
+ $message = __($user_login.' ('.$user_email.') has requested a username at '.get_settings('blogname')) . "\r\n\r\n";
124
+ $message .= get_option('siteurl') . "\r\n\r\n";
125
+ $message .= __('To approve or deny this user access to '.get_settings('blogname'). ' go to') . "\r\n\r\n";
126
+ $message .= get_settings('siteurl') . "/wp-admin/users.php?page=".PW_NEWUSER_APPROVE_FILE."\r\n";
127
+
128
+ // send the mail
129
+ @wp_mail(get_settings('admin_email'), sprintf(__('[%s] User Approval'), get_settings('blogname')), $message);
130
+
131
+ // create the user
132
+ $user_pass = wp_generate_password();
133
+ $user_id = wp_create_user($user_login, $user_pass, $user_email);
134
+
135
+ update_usermeta($user_id, 'pw_user_status', 'pending');
136
+ }
137
+
138
+ // admin approval of user
139
+ function pw_approve_approve_user() {
140
+ global $wpdb;
141
+
142
+ $user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = ".$_GET['user']);
143
+
144
+ // reset password
145
+ $new_pass = substr(md5(uniqid(microtime())), 0, 7);
146
+ $wpdb->query("UPDATE $wpdb->users SET user_pass = MD5('$new_pass'), user_activation_key = '' WHERE user_login = '$user->user_login'");
147
+ wp_cache_delete($user->ID, 'users');
148
+ wp_cache_delete($user->user_login, 'userlogins');
149
+
150
+ // send email to user telling of approval
151
+ $user_login = stripslashes($user->user_login);
152
+ $user_email = stripslashes($user->user_email);
153
+
154
+ // format the message
155
+ $message = sprintf(__('You have been approved to access %s \r\n'), get_settings('blogname'));
156
+ $message .= sprintf(__('Username: %s'), $user_login) . "\r\n";
157
+ $message .= sprintf(__('Password: %s'), $new_pass) . "\r\n";
158
+ $message .= get_settings('siteurl') . "/wp-login.php\r\n";
159
+
160
+ // send the mail
161
+ @wp_mail($user_email, sprintf(__('[%s] Registration Approved'), get_settings('blogname')), $message);
162
+
163
+ // change usermeta tag in database to approved
164
+ update_usermeta($user->ID, 'pw_user_status', 'approved');
165
+ }
166
+
167
+ // admin denial of user
168
+ function pw_approve_deny_user() {
169
+ global $wpdb;
170
+
171
+ $user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = ".$_GET['user']);
172
+
173
+ // send email to user telling of denial
174
+ $user_email = stripslashes($user->user_email);
175
+
176
+ // format the message
177
+ $message = sprintf(__('You have been denied access to %s'), get_settings('blogname'));
178
+
179
+ // send the mail
180
+ @wp_mail($user_email, sprintf(__('[%s] Registration Denied'), get_settings('blogname')), $message);
181
+
182
+ // change usermeta tag in database to denied
183
+ update_usermeta($user->ID, 'pw_user_status', 'denied');
184
+ }
185
+
186
+ // display a message to the user if they have not been approved
187
+ function pw_approve_errors() {
188
+ global $errors;
189
+
190
+ if ( $errors->get_error_code() )
191
+ return $errors;
192
+
193
+ $message = "An email has been sent to the site administrator. The administrator will review the information that has been submitted and either approve or deny your request.";
194
+ $message .= "You will receive an email with instructions on what you will need to do next. Thanks for your patience.";
195
+
196
+ $errors->add('registration_required', __($message), 'message');
197
+
198
+ login_header(__('Pending Approval'), '<p class="message register">' . __("Registration successful.") . '</p>', $errors);
199
+
200
+ echo "<body></html>";
201
+ exit();
202
+ }
203
+
204
+ // accept input from admin to modify a user
205
+ function pw_approve_process_input() {
206
+ if ($_GET['page'] == PW_NEWUSER_APPROVE_FILE && isset($_GET['status'])) {
207
+ if ($_GET['status'] == 'approve') {
208
+ pw_approve_approve_user();
209
+ }
210
+
211
+ if ($_GET['status'] == 'deny') {
212
+ pw_approve_deny_user();
213
+ }
214
+ //wp_redirect(get_settings('siteurl').'/wp-admin/users.php?page='.PW_NEWUSER_APPROVE_FILE);
215
+ }
216
+ }
217
+
218
+ // only give a user their password if they have been approved
219
+ function pw_approve_lost_password() {
220
+ $username = sanitize_user($_POST['user_login']);
221
+ $user_data = get_userdatabylogin(trim($username));
222
+ if ($user_data->pw_user_status != 'approved') {
223
+ wp_redirect('wp-login.php');
224
+ exit();
225
+ }
226
+
227
+ return;
228
+ }
229
+
230
+ function pw_approve_show_message($message) {
231
+ if (!isset($_GET['action'])) {
232
+ $message .= '<p class="message">Welcome to the '.bloginfo('name').'. This site is accessible to approved users only. To be approved, you must first register.</p>';
233
+ }
234
+
235
+ if ($_GET['action'] == 'register' && !$_POST) {
236
+ $message .= '<p class="message">After you register, your request will be sent to the site administrator for approval. You will then receive an email with further instructions.</p>';
237
+ }
238
+
239
+ return $message;
240
+ }
241
+
242
+ function pw_approve_init() {
243
+ if($_GET['page'] == PW_NEWUSER_APPROVE_FILE) {
244
+ wp_enqueue_script('jquery-ui-tabs');
245
+ }
246
+ }
247
+
248
+ function pw_approve_add_css() {
249
+ if($_GET['page'] == PW_NEWUSER_APPROVE_FILE) {
250
+ echo '<link rel="stylesheet" href="'.WP_PLUGIN_URL.'/'.PW_NEWUSER_APPROVE_DIR.'/ui.tabs.css'.'" type="text/css" />';
251
+ }
252
+ }
253
+
254
+ if (function_exists('add_action')) {
255
+ add_action('admin_menu', 'pw_approve_add_admin_pages');
256
+ add_action('register_post', 'pw_approve_request_approval_email');
257
+ add_action('init', 'pw_approve_process_input');
258
+ add_action('lostpassword_post', 'pw_approve_lost_password');
259
+ add_filter('registration_errors', 'pw_approve_errors');
260
+ add_filter('login_message', 'pw_approve_show_message');
261
+ add_action('init', 'pw_approve_init');
262
+ add_action('admin_head', 'pw_approve_add_css');
263
+ }
264
+ ?>
readme.txt ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
2
+ Contributors: picklewagon
3
+ Donate link: http://www.picklewagon.com/wordpress/
4
+ Tags: users, registration
5
+ Requires at least: 2.5
6
+ Tested up to: 2.7
7
+ Stable tag: 1.0
8
+
9
+ New User Approve is a Wordpress plugin that allows a blog administrator to
10
+ approve a user before they are able to access and login to the blog.
11
+
12
+ == Description ==
13
+
14
+ In a normal Wordpress blog, once a new user registers, the user is created in
15
+ the database. Then an email is sent to the new user with their login
16
+ credentials. Very simple. As it should be.
17
+
18
+ The New User Approve plugin changes up the registration process. When a user
19
+ registers for the blog, the user gets created and then an email gets sent to
20
+ the administrators of the site. An administrator then is expected to either
21
+ approve or deny the registration request. An email is then sent to the user
22
+ indicating whether they were approved or denied. If the user was approved,
23
+ the email will include the login credentials. Until a user is approved, the
24
+ user will not be able to login to the site.
25
+
26
+ == Installation ==
27
+
28
+ 1. Upload new-user-approve to the wp-content/plugins directory
29
+ 2. Activate the plugin through the �Plugins� menu in WordPress
30
+ 3. No configuration necessary.
31
+
32
+ == Frequently Asked Questions ==
33
+
34
+ No FAQ yet.
35
+
36
+ == Screenshots ==
37
+
38
+ No screenshots yet.
ui.tabs.css ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .ui-wrapper { border: 1px solid #50A029; }
2
+ .ui-wrapper input, .ui-wrapper textarea { border: 0; }
3
+
4
+ /* Caution! Ensure accessibility in print and other media types... */
5
+ @media projection, screen { /* Use class for showing/hiding tab content, so that visibility can be better controlled in different media types... */
6
+ .ui-tabs-hide {
7
+ display: none;
8
+ }
9
+ }
10
+
11
+ /* Hide useless elements in print layouts... */
12
+ @media print {
13
+ .ui-tabs-nav {
14
+ display: none;
15
+ }
16
+ }
17
+
18
+ /* Skin */
19
+ .ui-tabs-nav, .ui-tabs-panel {
20
+ }
21
+ .ui-tabs-nav {
22
+ list-style: none;
23
+ margin: 0;
24
+ padding: 0 0 0 3px;
25
+ }
26
+ .ui-tabs-nav:after { /* clearing without presentational markup, IE gets extra treatment */
27
+ display: block;
28
+ clear: both;
29
+ content: " ";
30
+ }
31
+ .ui-tabs-nav li {
32
+ float: left;
33
+ margin: 0 0 0 2px;
34
+ }
35
+ .ui-tabs-nav a, .ui-tabs-nav a span {
36
+ float: left; /* fixes dir=ltr problem and other quirks IE */
37
+ padding: 0 6px 0 12px;
38
+ color: #2583AD;
39
+ }
40
+ .ui-tabs-nav a {
41
+ margin: 6px 0 0; /* position: relative makes opacity fail for disabled tab in IE */
42
+ padding-left: 0;
43
+ background-position: 100% 0;
44
+ text-decoration: none;
45
+ white-space: nowrap; /* @ IE 6 */
46
+ outline: 0; /* @ Firefox, prevent dotted border after click */
47
+ background-color: #EAF3FA;
48
+ /* border */
49
+ border-color: #C6D9E9 #C6D9E9 #FFFFFF;
50
+ border-style:solid;
51
+ border-width:1px;
52
+ -moz-border-radius-topleft: 3px;
53
+ -khtml-border-top-left-radius: 3px;
54
+ -webkit-border-top-left-radius: 3px;
55
+ border-top-left-radius: 3px;
56
+ -moz-border-radius-topright: 3px;
57
+ -khtml-border-top-right-radius: 3px;
58
+ -webkit-border-top-right-radius: 3px;
59
+ border-top-right-radius: 3px;
60
+ }
61
+ .ui-tabs-nav a:link, .ui-tabs-nav a:visited {
62
+ color: #a2a2a2;
63
+ }
64
+ .ui-tabs-nav .ui-tabs-selected a {
65
+ position: relative;
66
+ top: 1px;
67
+ z-index: 2;
68
+ margin-top: 0;
69
+ background-position: 100% -23px;
70
+ color: #424242;
71
+ background-color: #FFF;
72
+ }
73
+ .ui-tabs-nav a span {
74
+ padding-top: 1px;
75
+ height: 20px;
76
+ background-position: 0 0;
77
+ line-height: 20px;
78
+ }
79
+ .ui-tabs-nav .ui-tabs-selected a span {
80
+ padding-top: 0;
81
+ height: 27px;
82
+ background-position: 0 -23px;
83
+ line-height: 27px;
84
+ color: #D54E21;
85
+ background-color: #FFF;
86
+ }
87
+ .ui-tabs-nav .ui-tabs-selected a:link, .ui-tabs-nav .ui-tabs-selected a:visited,
88
+ .ui-tabs-nav .ui-tabs-disabled a:link, .ui-tabs-nav .ui-tabs-disabled a:visited { /* @ Opera, use pseudo classes otherwise it confuses cursor... */
89
+ cursor: text;
90
+ }
91
+ .ui-tabs-nav a:hover, .ui-tabs-nav a:focus, .ui-tabs-nav a:active, .ui-tabs-nav a:hover span,
92
+ .ui-tabs-nav .ui-tabs-unselect a:hover, .ui-tabs-nav .ui-tabs-unselect a:focus, .ui-tabs-nav .ui-tabs-unselect a:active { /* @ Opera, we need to be explicit again here now... */
93
+ cursor: pointer;
94
+ color: #D54E21;
95
+ }
96
+ .ui-tabs-disabled {
97
+ opacity: .4;
98
+ filter: alpha(opacity=40);
99
+ }
100
+ .ui-tabs-nav .ui-tabs-disabled a:link, .ui-tabs-nav .ui-tabs-disabled a:visited {
101
+ color: #000;
102
+ }
103
+ .ui-tabs-panel {
104
+ border: 1px solid #519e2d;
105
+ padding: 10px;
106
+ background: #fff; /* declare background color for container to avoid distorted fonts in IE while fading */
107
+ }
108
+ /*.ui-tabs-loading em {
109
+ * padding: 0 0 0 20px;
110
+ * background: url(loading.gif) no-repeat 0 50%;
111
+ * }*/
112
+
113
+ /* Additional IE specific bug fixes... */
114
+ * html .ui-tabs-nav { /* auto clear @ IE 6 & IE 7 Quirks Mode */
115
+ display: inline-block;
116
+ }
117
+ *:first-child+html .ui-tabs-nav { /* auto clear @ IE 7 Standards Mode - do not group selectors, otherwise IE 6 will ignore complete rule (because of the unknown + combinator)... */
118
+ display: inline-block;
119
+ }
120
+ #pw_email_users {
121
+ height:100%;
122
+ margin:0;
123
+ }
124
+ #pw_email_options {
125
+ height:100%;
126
+ margin:0;
127
+ }