Version Description
Download this release
Release Info
Developer | picklewagon |
Plugin | ![]() |
Version | 1.1 |
Comparing to | |
See all releases |
Code changes from version 1.0 to 1.1
- new-user-approve.php +469 -263
- ui.tabs.css +9 -7
new-user-approve.php
CHANGED
@@ -1,264 +1,470 @@
|
|
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.
|
8 |
-
Author URI: http://www.picklewagon.com
|
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 |
-
function
|
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 |
?>
|
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.1
|
8 |
+
Author URI: http://www.picklewagon.com/
|
9 |
+
*/
|
10 |
+
|
11 |
+
/** Copyright 2009
|
12 |
+
This program is free software; you can redistribute it and/or modify
|
13 |
+
it under the terms of the GNU General Public License as published by
|
14 |
+
the Free Software Foundation; either version 2 of the License, or
|
15 |
+
(at your option) any later version.
|
16 |
+
|
17 |
+
This program is distributed in the hope that it will be useful,
|
18 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20 |
+
GNU General Public License for more details.
|
21 |
+
|
22 |
+
You should have received a copy of the GNU General Public License
|
23 |
+
along with this program; if not, write to the Free Software
|
24 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
25 |
+
*/
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Guess the wp-content and plugin urls/paths
|
29 |
+
*/
|
30 |
+
if ( !defined('WP_CONTENT_URL') )
|
31 |
+
define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
|
32 |
+
if ( !defined('WP_CONTENT_DIR') )
|
33 |
+
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
|
34 |
+
|
35 |
+
if (!defined('PLUGIN_URL'))
|
36 |
+
define('PLUGIN_URL', WP_CONTENT_URL . '/plugins/');
|
37 |
+
if (!defined('PLUGIN_PATH'))
|
38 |
+
define('PLUGIN_PATH', WP_CONTENT_DIR . '/plugins/');
|
39 |
+
|
40 |
+
if (!class_exists('pw_new_user_approve')) {
|
41 |
+
class pw_new_user_approve {
|
42 |
+
/**
|
43 |
+
* @var string The options string name for this plugin
|
44 |
+
*/
|
45 |
+
var $optionsName = 'pw_new_user_approve_options';
|
46 |
+
|
47 |
+
/**
|
48 |
+
* @var string $localizationDomain Domain used for localization
|
49 |
+
*/
|
50 |
+
var $localizationDomain = "pw_new_user_approve";
|
51 |
+
|
52 |
+
/**
|
53 |
+
* @var string $pluginurl The url to this plugin
|
54 |
+
*/
|
55 |
+
var $pluginurl = '';
|
56 |
+
|
57 |
+
/**
|
58 |
+
* @var string $pluginpath The path to this plugin
|
59 |
+
*/
|
60 |
+
var $pluginpath = '';
|
61 |
+
|
62 |
+
/**
|
63 |
+
* @var array $options Stores the options for this plugin
|
64 |
+
*/
|
65 |
+
var $options = array();
|
66 |
+
|
67 |
+
// Class Functions
|
68 |
+
/**
|
69 |
+
* PHP 4 Compatible Constructor
|
70 |
+
*/
|
71 |
+
function pw_new_user_approve() {
|
72 |
+
$this->__construct();
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* PHP 5 Constructor
|
77 |
+
*/
|
78 |
+
function __construct(){
|
79 |
+
// Language Setup
|
80 |
+
$locale = get_locale();
|
81 |
+
$mo = dirname(__FILE__) . "/languages/" . $this->localizationName . "-".$locale.".mo";
|
82 |
+
load_textdomain($this->localizationDomain, $mo);
|
83 |
+
|
84 |
+
// Constants setup
|
85 |
+
$this->pluginurl = PLUGIN_URL . dirname(plugin_basename(__FILE__)).'/';
|
86 |
+
$this->pluginpath = PLUGIN_PATH . dirname(plugin_basename(__FILE__)).'/';
|
87 |
+
|
88 |
+
// Initialize the options
|
89 |
+
$this->get_options();
|
90 |
+
|
91 |
+
// Actions
|
92 |
+
add_action('admin_menu', array(&$this, 'admin_menu_link'));
|
93 |
+
add_action('admin_footer', array(&$this, 'admin_scripts_footer'));
|
94 |
+
add_action('init', array(&$this, 'init'));
|
95 |
+
add_action('admin_head', array(&$this, 'add_admin_css'));
|
96 |
+
add_action('register_post', array(&$this, 'send_approval_email'), 10, 3);
|
97 |
+
add_action('init', array(&$this, 'process_input'));
|
98 |
+
add_action('lostpassword_post', array(&$this, 'lost_password'));
|
99 |
+
add_filter('registration_errors', array(&$this, 'show_user_message'), 10, 1);
|
100 |
+
add_filter('login_message', array(&$this, 'welcome_user'));
|
101 |
+
//add_action('rightnow_end', array(&$this, 'dashboard_stats')); // still too slow
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Retrieves the plugin options from the database.
|
106 |
+
*/
|
107 |
+
function get_options() {
|
108 |
+
// Don't forget to set up the default options
|
109 |
+
if (!$theOptions = get_option($this->optionsName)) {
|
110 |
+
$theOptions = array('default'=>'options');
|
111 |
+
update_option($this->optionsName, $theOptions);
|
112 |
+
}
|
113 |
+
$this->options = $theOptions;
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* @desc Saves the admin options to the database.
|
118 |
+
*/
|
119 |
+
function save_admin_options(){
|
120 |
+
update_option($this->optionsName, $this->options);
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* @desc Adds the options subpanel
|
125 |
+
*/
|
126 |
+
function admin_menu_link() {
|
127 |
+
add_submenu_page('users.php', 'Approve New Users', 'Approve New Users', 'edit_users', basename(__FILE__), array(&$this, 'approve_admin'));
|
128 |
+
add_filter( 'plugin_action_links', array(&$this, 'filter_plugin_actions'), 10, 2 );
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* @desc Adds the Settings link to the plugin activate/deactivate page
|
133 |
+
*/
|
134 |
+
function filter_plugin_actions($links, $file) {
|
135 |
+
static $this_plugin;
|
136 |
+
if( ! $this_plugin ) {
|
137 |
+
$this_plugin = plugin_basename(__FILE__);
|
138 |
+
}
|
139 |
+
|
140 |
+
if( $file == $this_plugin ){
|
141 |
+
$settings_link = '<a href="users.php?page=' . basename(__FILE__) . '">' . __('Settings') . '</a>';
|
142 |
+
array_unshift( $links, $settings_link ); // before other links
|
143 |
+
}
|
144 |
+
return $links;
|
145 |
+
}
|
146 |
+
|
147 |
+
function admin_scripts_footer() {
|
148 |
+
if($_GET['page'] == basename(__FILE__)) {
|
149 |
+
?>
|
150 |
+
<script type="text/javascript">
|
151 |
+
//<![CDATA[
|
152 |
+
jQuery(document).ready(function($) {
|
153 |
+
$('#pw_approve_tabs > ul').tabs({ fx: { opacity: 'toggle' } });
|
154 |
+
});
|
155 |
+
//]]>
|
156 |
+
</script>
|
157 |
+
<?php
|
158 |
+
}
|
159 |
+
}
|
160 |
+
|
161 |
+
function dashboard_stats() {
|
162 |
+
// Query the users table
|
163 |
+
$wp_user_search = new PW_User_Search($_GET['usersearch'], $_GET['userspage']);
|
164 |
+
$user_status = array();
|
165 |
+
|
166 |
+
// Make the user objects
|
167 |
+
foreach ($wp_user_search->get_results() as $userid) {
|
168 |
+
$user = new WP_User($userid);
|
169 |
+
$status = get_usermeta($userid, 'pw_user_status');
|
170 |
+
if ($status == '') { // user was created in admin
|
171 |
+
update_usermeta($userid, 'pw_user_status', 'approved');
|
172 |
+
$status = get_usermeta($userid, 'pw_user_status');
|
173 |
+
}
|
174 |
+
if ($user_status[$status] == null) {
|
175 |
+
$user_status[$status] = 0;
|
176 |
+
}
|
177 |
+
$user_status[$status] += 1;
|
178 |
+
}
|
179 |
+
?>
|
180 |
+
<div>
|
181 |
+
<p><span style="font-weight:bold;"><a href="users.php?page=<?php print basename(__FILE__) ?>">Users</a></span>:
|
182 |
+
<?php foreach($user_status as $status =>$count) print "$count $status "; ?>
|
183 |
+
</p>
|
184 |
+
</div>
|
185 |
+
<?php
|
186 |
+
}
|
187 |
+
|
188 |
+
/**
|
189 |
+
* @desc create the view for the admin interface
|
190 |
+
*/
|
191 |
+
function approve_admin() {
|
192 |
+
// Query the users table
|
193 |
+
$wp_user_search = new PW_User_Search($_GET['usersearch'], $_GET['userspage']);
|
194 |
+
$user_status = array();
|
195 |
+
|
196 |
+
// Make the user objects
|
197 |
+
foreach ($wp_user_search->get_results() as $userid) {
|
198 |
+
$user = wp_cache_get($userid, 'pw_user_status_cache');
|
199 |
+
|
200 |
+
if (!$user) {
|
201 |
+
$user = new WP_User($userid);
|
202 |
+
$status = get_usermeta($userid, 'pw_user_status');
|
203 |
+
if ($status == '') { // user was created in admin
|
204 |
+
update_usermeta($userid, 'pw_user_status', 'approved');
|
205 |
+
$status = get_usermeta($userid, 'pw_user_status');
|
206 |
+
}
|
207 |
+
$user->status = $status;
|
208 |
+
wp_cache_add($userid, $user, 'pw_user_status_cache');
|
209 |
+
}
|
210 |
+
|
211 |
+
$user_status[$status][] = $user;
|
212 |
+
}
|
213 |
+
|
214 |
+
if (isset($_GET['user']) && isset($_GET['status'])) {
|
215 |
+
echo '<div id="message" class="updated fade"><p>User successfully updated.</p></div>';
|
216 |
+
}
|
217 |
+
?>
|
218 |
+
<div class="wrap">
|
219 |
+
<h2>User Registration Approval</h2>
|
220 |
+
|
221 |
+
<h3>User Management</h3>
|
222 |
+
<div id="pw_approve_tabs">
|
223 |
+
<ul>
|
224 |
+
<li><a href="#pw_pending_users"><span>Users Pending Approval</span></a></li>
|
225 |
+
<li><a href="#pw_approved_users"><span>Approved Users</span></a></li>
|
226 |
+
<li><a href="#pw_denied_users"><span>Denied Users</span></a></li>
|
227 |
+
</ul>
|
228 |
+
<div id="pw_pending_users">
|
229 |
+
<?php $this->approve_table($user_status, 'pending', true, true); ?>
|
230 |
+
</div>
|
231 |
+
<div id="pw_approved_users">
|
232 |
+
<?php $this->approve_table($user_status, 'approved', false, true); ?>
|
233 |
+
</div>
|
234 |
+
<div id="pw_denied_users">
|
235 |
+
<?php $this->approve_table($user_status, 'denied', true, false); ?>
|
236 |
+
</div>
|
237 |
+
</div>
|
238 |
+
</div>
|
239 |
+
<?php
|
240 |
+
}
|
241 |
+
|
242 |
+
/**
|
243 |
+
* @desc the table that shows the registered users grouped by status
|
244 |
+
*/
|
245 |
+
function approve_table($users, $status, $approve, $deny) {
|
246 |
+
if (count($users[$status]) > 0) {
|
247 |
+
?>
|
248 |
+
<table class="widefat">
|
249 |
+
<thead>
|
250 |
+
<tr class="thead">
|
251 |
+
<th><?php _e('ID') ?></th>
|
252 |
+
<th><?php _e('Username') ?></th>
|
253 |
+
<th><?php _e('Name') ?></th>
|
254 |
+
<th><?php _e('E-mail') ?></th>
|
255 |
+
<?php if ($approve && $deny) { ?>
|
256 |
+
<th colspan="2" style="text-align: center"><?php _e('Actions') ?></th>
|
257 |
+
<?php } else { ?>
|
258 |
+
<th style="text-align: center"><?php _e('Actions') ?></th>
|
259 |
+
<?php } ?>
|
260 |
+
</tr>
|
261 |
+
</thead>
|
262 |
+
<tbody>
|
263 |
+
<?php
|
264 |
+
// show each of the users
|
265 |
+
$row = 1;
|
266 |
+
foreach ($users[$status] as $user) {
|
267 |
+
$class = ($row % 2) ? '' : ' class="alternate"';
|
268 |
+
$avatar = get_avatar( $user->user_email, 32 );
|
269 |
+
if ($approve) {
|
270 |
+
$approve_link = '/wp-admin/users.php?page='.basename(__FILE__).'&user='.$user->ID.'&status=approve';
|
271 |
+
$approve_link = ( function_exists('wp_nonce_url') ) ? wp_nonce_url($approve_link, 'plugin-name-action_' . get_class($this)) : $approve_link;
|
272 |
+
}
|
273 |
+
if ($deny) {
|
274 |
+
$deny_link = '/wp-admin/users.php?page='.basename(__FILE__).'&user='.$user->ID.'&status=deny';
|
275 |
+
$deny_link = ( function_exists('wp_nonce_url') ) ? wp_nonce_url($deny_link, 'plugin-name-action_' . get_class($this)) : $deny_link;
|
276 |
+
}
|
277 |
+
?><tr <?php echo $class; ?>>
|
278 |
+
<td><?php echo $user->ID; ?></td>
|
279 |
+
<td><?php echo $avatar." ".$user->user_login; ?></td>
|
280 |
+
<td><?php echo $user->first_name." ".$user->last_name; ?></td>
|
281 |
+
<td><a href="mailto:<?php echo $user->user_email; ?>" title="email: <?php echo $user->user_email; ?>"><?php echo $user->user_email; ?></a></td>
|
282 |
+
<?php if ($approve) { ?>
|
283 |
+
<td align="center"><a href="<?php echo $approve_link; ?>" title="Approve <?php echo $user->user_login; ?>"><?php _e('Approve') ?></a></td>
|
284 |
+
<?php } ?>
|
285 |
+
<?php if ($deny) { ?>
|
286 |
+
<td align="center"><a href="<?php echo $deny_link; ?>" title="Deny <?php echo $user->user_login; ?>"><?php _e('Deny') ?></a></td>
|
287 |
+
<?php } ?>
|
288 |
+
</tr><?php
|
289 |
+
$row++;
|
290 |
+
}
|
291 |
+
?>
|
292 |
+
</tbody>
|
293 |
+
</table>
|
294 |
+
<?php
|
295 |
+
} else {
|
296 |
+
echo "<p>There are no users with a status of $status</p>";
|
297 |
+
}
|
298 |
+
}
|
299 |
+
|
300 |
+
/**
|
301 |
+
* @desc send an email to the admin to request approval
|
302 |
+
*/
|
303 |
+
function send_approval_email($user_login, $user_email, $errors) {
|
304 |
+
if (!$errors->get_error_code()) {
|
305 |
+
/* check if already exists */
|
306 |
+
$user_data = get_userdatabylogin($user_login);
|
307 |
+
if (!empty($user_data)){
|
308 |
+
$errors->add('registration_required' , __("User name already exists"), 'message');
|
309 |
+
} else {
|
310 |
+
/* send email to admin for approval */
|
311 |
+
$message = __($user_login.' ('.$user_email.') has requested a username at '.get_settings('blogname')) . "\r\n\r\n";
|
312 |
+
$message .= get_option('siteurl') . "\r\n\r\n";
|
313 |
+
$message .= __('To approve or deny this user access to '.get_settings('blogname'). ' go to') . "\r\n\r\n";
|
314 |
+
$message .= get_settings('siteurl') . "/wp-admin/users.php?page=".basename(__FILE__)."\r\n";
|
315 |
+
|
316 |
+
// send the mail
|
317 |
+
@wp_mail(get_settings('admin_email'), sprintf(__('[%s] User Approval'), get_settings('blogname')), $message);
|
318 |
+
|
319 |
+
// create the user
|
320 |
+
$user_pass = wp_generate_password();
|
321 |
+
$user_id = wp_create_user($user_login, $user_pass, $user_email);
|
322 |
+
|
323 |
+
update_usermeta($user_id, 'pw_user_status', 'pending');
|
324 |
+
}
|
325 |
+
}
|
326 |
+
}
|
327 |
+
|
328 |
+
/**
|
329 |
+
* @desc admin approval of user
|
330 |
+
*/
|
331 |
+
function approve_user() {
|
332 |
+
global $wpdb;
|
333 |
+
|
334 |
+
$query = $wpdb->prepare("SELECT * FROM $wpdb->users WHERE ID = %d", $_GET['user']);
|
335 |
+
$user = $wpdb->get_row($query);
|
336 |
+
|
337 |
+
// reset password
|
338 |
+
$new_pass = substr(md5(uniqid(microtime())), 0, 7);
|
339 |
+
$wpdb->query("UPDATE $wpdb->users SET user_pass = MD5('$new_pass'), user_activation_key = '' WHERE ID = '$user->ID'");
|
340 |
+
wp_cache_delete($user->ID, 'users');
|
341 |
+
wp_cache_delete($user->user_login, 'userlogins');
|
342 |
+
|
343 |
+
// send email to user telling of approval
|
344 |
+
$user_login = stripslashes($user->user_login);
|
345 |
+
$user_email = stripslashes($user->user_email);
|
346 |
+
|
347 |
+
// format the message
|
348 |
+
$message = sprintf(__('You have been approved to access %s \r\n'), get_settings('blogname'));
|
349 |
+
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n";
|
350 |
+
$message .= sprintf(__('Password: %s'), $new_pass) . "\r\n";
|
351 |
+
$message .= get_settings('siteurl') . "/wp-login.php\r\n";
|
352 |
+
|
353 |
+
// send the mail
|
354 |
+
@wp_mail($user_email, sprintf(__('[%s] Registration Approved'), get_settings('blogname')), $message);
|
355 |
+
|
356 |
+
// change usermeta tag in database to approved
|
357 |
+
update_usermeta($user->ID, 'pw_user_status', 'approved');
|
358 |
+
}
|
359 |
+
|
360 |
+
/**
|
361 |
+
* @desc admin denial of user
|
362 |
+
*/
|
363 |
+
function deny_user() {
|
364 |
+
global $wpdb;
|
365 |
+
|
366 |
+
$query = $wpdb->prepare("SELECT * FROM $wpdb->users WHERE ID = %d", $_GET['user']);
|
367 |
+
$user = $wpdb->get_row($query);
|
368 |
+
|
369 |
+
// send email to user telling of denial
|
370 |
+
$user_email = stripslashes($user->user_email);
|
371 |
+
|
372 |
+
// format the message
|
373 |
+
$message = sprintf(__('You have been denied access to %s'), get_settings('blogname'));
|
374 |
+
|
375 |
+
// send the mail
|
376 |
+
@wp_mail($user_email, sprintf(__('[%s] Registration Denied'), get_settings('blogname')), $message);
|
377 |
+
|
378 |
+
// change usermeta tag in database to denied
|
379 |
+
update_usermeta($user->ID, 'pw_user_status', 'denied');
|
380 |
+
}
|
381 |
+
|
382 |
+
/**
|
383 |
+
* @desc display a message to the user if they have not been approved
|
384 |
+
*/
|
385 |
+
function show_user_message($errors) {
|
386 |
+
if ( $errors->get_error_code() )
|
387 |
+
return $errors;
|
388 |
+
|
389 |
+
$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.";
|
390 |
+
$message .= "You will receive an email with instructions on what you will need to do next. Thanks for your patience.";
|
391 |
+
|
392 |
+
$errors->add('registration_required', __($message), 'message');
|
393 |
+
|
394 |
+
login_header(__('Pending Approval'), '<p class="message register">' . __("Registration successful.") . '</p>', $errors);
|
395 |
+
|
396 |
+
echo "<body></html>";
|
397 |
+
exit();
|
398 |
+
}
|
399 |
+
|
400 |
+
/**
|
401 |
+
* @desc accept input from admin to modify a user
|
402 |
+
*/
|
403 |
+
function process_input() {
|
404 |
+
if ($_GET['page'] == basename(__FILE__) && isset($_GET['status'])) {
|
405 |
+
$valid_request = check_admin_referer('plugin-name-action_' . get_class($this));
|
406 |
+
|
407 |
+
if ($valid_request) {
|
408 |
+
if ($_GET['status'] == 'approve') {
|
409 |
+
$this->approve_user();
|
410 |
+
}
|
411 |
+
|
412 |
+
if ($_GET['status'] == 'deny') {
|
413 |
+
$this->deny_user();
|
414 |
+
}
|
415 |
+
}
|
416 |
+
}
|
417 |
+
}
|
418 |
+
|
419 |
+
/**
|
420 |
+
* @desc only give a user their password if they have been approved
|
421 |
+
*/
|
422 |
+
function lost_password() {
|
423 |
+
$username = sanitize_user($_POST['user_login']);
|
424 |
+
$user_data = get_userdatabylogin(trim($username));
|
425 |
+
if ($user_data->pw_user_status != 'approved') {
|
426 |
+
wp_redirect('wp-login.php');
|
427 |
+
exit();
|
428 |
+
}
|
429 |
+
|
430 |
+
return;
|
431 |
+
}
|
432 |
+
|
433 |
+
function welcome_user($message) {
|
434 |
+
if (!isset($_GET['action'])) {
|
435 |
+
$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>';
|
436 |
+
}
|
437 |
+
|
438 |
+
if ($_GET['action'] == 'register' && !$_POST) {
|
439 |
+
$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>';
|
440 |
+
}
|
441 |
+
|
442 |
+
return $message;
|
443 |
+
}
|
444 |
+
|
445 |
+
function init() {
|
446 |
+
if($_GET['page'] == basename(__FILE__)) {
|
447 |
+
wp_enqueue_script('jquery-ui-tabs');
|
448 |
+
}
|
449 |
+
}
|
450 |
+
|
451 |
+
function add_admin_css() {
|
452 |
+
if($_GET['page'] == basename(__FILE__)) {
|
453 |
+
echo '<link rel="stylesheet" href="'.$this->pluginurl.'ui.tabs.css'.'" type="text/css" />';
|
454 |
+
}
|
455 |
+
}
|
456 |
+
} // End Class
|
457 |
+
} // End if class exists statement
|
458 |
+
|
459 |
+
if (!class_exists('WP_User_Search')) {
|
460 |
+
require_once(ABSPATH . 'wp-admin/includes/user.php');
|
461 |
+
}
|
462 |
+
class PW_User_Search extends WP_User_Search {
|
463 |
+
var $users_per_page = 999999999;
|
464 |
+
}
|
465 |
+
|
466 |
+
// instantiate the class
|
467 |
+
if (class_exists('pw_new_user_approve')) {
|
468 |
+
$pw_new_user_approve = new pw_new_user_approve();
|
469 |
+
}
|
470 |
?>
|
ui.tabs.css
CHANGED
@@ -44,9 +44,10 @@
|
|
44 |
text-decoration: none;
|
45 |
white-space: nowrap; /* @ IE 6 */
|
46 |
outline: 0; /* @ Firefox, prevent dotted border after click */
|
47 |
-
background-color
|
|
|
48 |
/* border */
|
49 |
-
border-color: #
|
50 |
border-style:solid;
|
51 |
border-width:1px;
|
52 |
-moz-border-radius-topleft: 3px;
|
@@ -80,9 +81,10 @@
|
|
80 |
padding-top: 0;
|
81 |
height: 27px;
|
82 |
background-position: 0 -23px;
|
83 |
-
line-height: 27px;
|
84 |
-
color
|
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... */
|
@@ -90,8 +92,8 @@
|
|
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:
|
94 |
-
color
|
95 |
}
|
96 |
.ui-tabs-disabled {
|
97 |
opacity: .4;
|
@@ -101,7 +103,7 @@
|
|
101 |
color: #000;
|
102 |
}
|
103 |
.ui-tabs-panel {
|
104 |
-
border: 1px solid #
|
105 |
padding: 10px;
|
106 |
background: #fff; /* declare background color for container to avoid distorted fonts in IE while fading */
|
107 |
}
|
44 |
text-decoration: none;
|
45 |
white-space: nowrap; /* @ IE 6 */
|
46 |
outline: 0; /* @ Firefox, prevent dotted border after click */
|
47 |
+
/*background-color:#EAF3FA;*/
|
48 |
+
background-color:#F1F1F1;
|
49 |
/* border */
|
50 |
+
border-color: #DFDFDF #DFDFDF #FFFFFF;
|
51 |
border-style:solid;
|
52 |
border-width:1px;
|
53 |
-moz-border-radius-topleft: 3px;
|
81 |
padding-top: 0;
|
82 |
height: 27px;
|
83 |
background-position: 0 -23px;
|
84 |
+
line-height: 27px;
|
85 |
+
color:#333;
|
86 |
background-color: #FFF;
|
87 |
+
font-weight:bold;
|
88 |
}
|
89 |
.ui-tabs-nav .ui-tabs-selected a:link, .ui-tabs-nav .ui-tabs-selected a:visited,
|
90 |
.ui-tabs-nav .ui-tabs-disabled a:link, .ui-tabs-nav .ui-tabs-disabled a:visited { /* @ Opera, use pseudo classes otherwise it confuses cursor... */
|
92 |
}
|
93 |
.ui-tabs-nav a:hover, .ui-tabs-nav a:focus, .ui-tabs-nav a:active, .ui-tabs-nav a:hover span,
|
94 |
.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... */
|
95 |
+
cursor:pointer;
|
96 |
+
color:#333333;
|
97 |
}
|
98 |
.ui-tabs-disabled {
|
99 |
opacity: .4;
|
103 |
color: #000;
|
104 |
}
|
105 |
.ui-tabs-panel {
|
106 |
+
border: 1px solid #dfdfdf !important;
|
107 |
padding: 10px;
|
108 |
background: #fff; /* declare background color for container to avoid distorted fonts in IE while fading */
|
109 |
}
|