/** * display admin page for creating and managing temporary users * * @return null */ public static function admin_settings() { // check our user permissions again if (false === TempAdminUser_Utilities::check_user_perm()) { echo __('You do not have permission to access this page.', 'temporary-admin-user'); die; } // begin the markup for the settings page echo '<div class="wrap tempadmin-settings-wrap">'; echo '<h2>' . __('Manage Temporary Users', 'temporary-admin-user') . '</h2>'; // display our new user form echo '<div class="tempadmin-settings-box tempadmin-new-user-box">'; echo '<h3>' . __('Create New User', 'temporary-admin-user') . '</h3>'; echo TempAdminUser_Layout::new_user_form(); echo '</div>'; // display our existing active users echo '<div id="tempadmin-users-active" class="tempadmin-settings-box tempadmin-users-list-box">'; echo '<form method="post">'; echo '<div class="tempadmin-users-list-title-row">'; echo '<h3>'; echo '<span class="tempadmin-users-title-text">' . __('Active User Accounts', 'temporary-admin-user') . ' </span>'; echo '<span class="tempadmin-users-list-action tempadmin-users-active-action">'; echo TempAdminUser_Layout::user_action_button(__('Demote Selected Users', 'temporary-admin-user'), 'demote'); echo '</span>'; echo '</h3>'; echo '</div>'; echo '<div class="tempadmin-users-list-data">'; echo TempAdminUser_Layout::existing_user_list('administrator'); echo '</div>'; echo '</form>'; echo '</div>'; // display our existing expired users echo '<div id="tempadmin-users-expired" class="tempadmin-settings-box tempadmin-users-list-box">'; echo '<form method="post">'; echo '<div class="tempadmin-users-list-title-row">'; echo '<h3>'; echo '<span class="tempadmin-users-title-text">' . __('Expired User Accounts', 'temporary-admin-user') . ' </span>'; echo '<span class="tempadmin-users-list-action tempadmin-users-expired-action">'; echo TempAdminUser_Layout::user_action_button(__('Delete Selected Users', 'temporary-admin-user'), 'delete'); echo '</span>'; echo '</h3>'; echo '</div>'; echo '<div class="tempadmin-users-list-data">'; echo TempAdminUser_Layout::existing_user_list('subscriber'); echo '</div>'; echo '</form>'; echo '</div>'; // close the markup for the settings page echo '</div>'; }
/** * create the content portion of the email sent to a new user * * @param object $user the WP_User object * @param string $password the password assigned to the new user * @param array $sitedata the data array of site info * * @return mixed the content of the email, possibly HTML formatted */ public static function generate_email_content($user = OBJECT, $password = '', $sitedata = array()) { // get our two expire setups $expire_stamp = get_user_meta($user->ID, '_tempadmin_expire', true); $expire_date = TempAdminUser_Utilities::format_date_display($expire_stamp, 'date-format'); $expire_time = TempAdminUser_Utilities::format_date_display($expire_stamp, 'time-format'); // set an empty $message = ''; // set the primary hello message $message .= sprintf(__('A temporary user account has been created for you on %s. This login will expire on %s at %s', 'temporary-admin-user'), $sitedata['site-name'], $expire_date, $expire_time) . "\r\n"; // and the user / pass / login URL message $message .= sprintf(__('Username: %s', 'temporary-admin-user'), esc_attr($user->user_login)) . "\r\n"; $message .= sprintf(__('Password: %s', 'temporary-admin-user'), $password) . "\r\n"; $message .= sprintf(__('Login URL: %s', 'temporary-admin-user'), esc_url($sitedata['login-url'])); // filter it $message = apply_filters('tempadmin_email_message', $message); // if we aren't HTML, just return plain text if ('html' !== apply_filters('tempadmin_email_content_type', 'html')) { return $message; } // so we have the HTML type. format that $content = ''; $content .= '<html>' . "\n"; $content .= '<head>' . "\n"; $content .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . "\n"; $content .= '</head>' . "\n"; $content .= '<body>' . "\n"; $content .= TempAdminUser_Utilities::format_email_content($message); $content .= '</body>' . "\n"; $content .= '</html>' . "\n"; // send it back return trim($content); }
/** * set up the new user notification email * * @param integer $user the newly created user ID or the entire object * @param string $password the password assigned to the new user * * @return mixed an HTML email with the new user info */ protected static function new_user_notification($user = 0, $password = '') { // check if we recieved just the user ID and fetch the object if (is_numeric($user) && !is_object($user)) { $user = new WP_User($user); } // bail if somehow we didn't get a valid user object if (!is_object($user)) { return false; } // get our email content type $email_type = apply_filters('tempadmin_email_content_type', 'html'); // fetch the site info, which we need for the email $sitedata = TempAdminUser_Utilities::get_site_data(); // switch to HTML format unless otherwise told if ($email_type == 'html') { add_filter('wp_mail_content_type', array(__CLASS__, 'set_html_content_type')); } // construct email headers $headers = 'From: ' . esc_attr($sitedata['site-name']) . ' <' . sanitize_email($sitedata['admin-email']) . '>' . "\r\n"; $headers .= 'Return-Path: ' . sanitize_email($sitedata['admin-email']) . "\r\n"; // add the additional headers for HTML email if ($email_type == 'html') { $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-Type: text/html; charset="UTF-8"' . "\r\n"; } // set my email subject $subject = apply_filters('tempadmin_email_subject', __('New User Account', 'temporary-admin-user')); // get my user content $content = TempAdminUser_Layout::generate_email_content($user, $password, $sitedata); // and send the email wp_mail(sanitize_email($user->user_email), $subject, $content, $headers); // reset the email content type (if originally set ) if ($email_type == 'html') { remove_filter('wp_mail_content_type', array(__CLASS__, 'set_html_content_type')); } // and return return; }