Advertisement
bcworkz

prospective-users.php

Feb 19th, 2019
1,017
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.40 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Prospecitve Users
  4. 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.
  5. Author: bcworkz
  6. Version: 0.10 beta
  7. */
  8.  
  9. // Add sub menu page to Network Users section
  10. add_action('network_admin_menu', 'pu_list_prospective_users');
  11. function pu_list_prospective_users() {
  12.     if (!is_multisite()) wp_die('Prospective Users plugin is for multi-site only. You must deactivate this plugin.');
  13.     add_submenu_page('users.php', 'Prospective Users', 'Prospective Users', 'manage_network_users', 'prospective_users', 'pu_do_menu_screen');
  14. }
  15.  
  16. // output admin screen and handle any resend requests
  17. function pu_do_menu_screen() {
  18.     // security measure
  19.     if ( ! current_user_can('manage_network_users')) {
  20.         echo 'You do not have permission to manage network users';
  21.         return;
  22.     }
  23.  
  24.     global $wpdb;
  25.     echo '<div class="wrap">'; // standard admin screen content wrapper
  26.  
  27.     // handle any resend email request for passed signup_id
  28.     if ('POST' == $_SERVER['REQUEST_METHOD'] && array_key_exists('signup-id', $_POST)) {
  29.         $signup_id = (int) $_POST['signup-id'];
  30.         $p_user = $wpdb->get_row("SELECT * FROM {$wpdb->signups} WHERE signup_id = $signup_id;");
  31.         $user_login = $p_user->user_login;
  32.         $user_email = $p_user->user_email;
  33.         // generate new key
  34.         $key = substr( md5( time() . wp_rand() . $user_email ), 0, 16 );
  35.         // send admin created user message instead of self sign up message
  36.         add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' );
  37.  
  38.  
  39.         // send the email with new activation key
  40.         $success = wpmu_signup_user_notification( $user_login, $user_email, $key );
  41.         if ( $success ) {
  42.             echo "<div id=\"message\" class=\"updated notice notice-success is-dismissible\">&nbsp;<br>
  43.                 Activation email re-sent to $user_email &lt;$user_login&gt;<br>&nbsp;</div>\n";
  44.             // save new key and current date in the user's signup record
  45.             $wpdb->update( $wpdb->signups,
  46.                 ['registered'=> date('Y-m-d H:i:s'), 'activation_key'=> $key,],
  47.                 ['signup_id'=> $signup_id,],
  48.                 '%s', '%d');
  49.         }
  50.     }
  51.     // main admin screen output
  52.     echo '<h1>Prospective Users</h1>';
  53.     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
  54.         and signup date is updated to resatart the 2 day timer that runs before the key expires. Any
  55.         keys previously sent will become invalid. Each prospective user record is presented
  56.         below as a class object as a matter of expediency.";
  57.  
  58.     // get user data from signups table
  59.     $signups = $wpdb->get_results("SELECT * FROM {$wpdb->signups} WHERE active = 0");
  60.     if ( 0 == count( $signups )) echo '<br><br>There are no prospective users at this time';
  61.  
  62.     // output all pending signup records
  63.     foreach ( $signups as $user) {
  64.         echo '<pre>';
  65.         print_r( $user );
  66.         echo '</pre>';
  67.         $meta = unserialize( $user->meta );
  68.         if ( ! array_key_exists('new_role', $meta)) $meta['new_role'] = "{site's default}";
  69.  
  70.         // resend email button
  71.         echo "<form action=\"\" method=\"POST\">
  72.             <input type=\"hidden\" name=\"role\" value=\"{$meta['new_role']}\">
  73.             <input type=\"hidden\" name=\"signup-id\" value=\"{$user->signup_id}\">
  74.             <input type=\"submit\"value=\"Resend Email\"></form>
  75.             ----------------------------------------------------------------------<br>\n";
  76.     }
  77.     echo '</div><!-- .wrap -->';
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement