Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Prospecitve Users
- Description: Adds multi-site user network admin screen that lists prospective users and optionally resends the new user notification email. Also resets the 2 day timer before the key becomes invalid.
- Author: bcworkz
- Version: 0.10 beta
- */
- // Add sub menu page to Network Users section
- add_action('network_admin_menu', 'pu_list_prospective_users');
- function pu_list_prospective_users() {
- if (!is_multisite()) wp_die('Prospective Users plugin is for multi-site only. You must deactivate this plugin.');
- add_submenu_page('users.php', 'Prospective Users', 'Prospective Users', 'manage_network_users', 'prospective_users', 'pu_do_menu_screen');
- }
- // output admin screen and handle any resend requests
- function pu_do_menu_screen() {
- // security measure
- if ( ! current_user_can('manage_network_users')) {
- echo 'You do not have permission to manage network users';
- return;
- }
- global $wpdb;
- echo '<div class="wrap">'; // standard admin screen content wrapper
- // handle any resend email request for passed signup_id
- if ('POST' == $_SERVER['REQUEST_METHOD'] && array_key_exists('signup-id', $_POST)) {
- $signup_id = (int) $_POST['signup-id'];
- $p_user = $wpdb->get_row("SELECT * FROM {$wpdb->signups} WHERE signup_id = $signup_id;");
- $user_login = $p_user->user_login;
- $user_email = $p_user->user_email;
- // generate new key
- $key = substr( md5( time() . wp_rand() . $user_email ), 0, 16 );
- // send admin created user message instead of self sign up message
- add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' );
- // send the email with new activation key
- $success = wpmu_signup_user_notification( $user_login, $user_email, $key );
- if ( $success ) {
- echo "<div id=\"message\" class=\"updated notice notice-success is-dismissible\"> <br>
- Activation email re-sent to $user_email <$user_login><br> </div>\n";
- // save new key and current date in the user's signup record
- $wpdb->update( $wpdb->signups,
- ['registered'=> date('Y-m-d H:i:s'), 'activation_key'=> $key,],
- ['signup_id'=> $signup_id,],
- '%s', '%d');
- }
- }
- // main admin screen output
- echo '<h1>Prospective Users</h1>';
- echo "The resend button sends the new user email that is sent when a new user is added by an admin. The user's key
- and signup date is updated to resatart the 2 day timer that runs before the key expires. Any
- keys previously sent will become invalid. Each prospective user record is presented
- below as a class object as a matter of expediency.";
- // get user data from signups table
- $signups = $wpdb->get_results("SELECT * FROM {$wpdb->signups} WHERE active = 0");
- if ( 0 == count( $signups )) echo '<br><br>There are no prospective users at this time';
- // output all pending signup records
- foreach ( $signups as $user) {
- echo '<pre>';
- print_r( $user );
- echo '</pre>';
- $meta = unserialize( $user->meta );
- if ( ! array_key_exists('new_role', $meta)) $meta['new_role'] = "{site's default}";
- // resend email button
- echo "<form action=\"\" method=\"POST\">
- <input type=\"hidden\" name=\"role\" value=\"{$meta['new_role']}\">
- <input type=\"hidden\" name=\"signup-id\" value=\"{$user->signup_id}\">
- <input type=\"submit\"value=\"Resend Email\"></form>
- ----------------------------------------------------------------------<br>\n";
- }
- echo '</div><!-- .wrap -->';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement