* @copyright Copyright (c) 2009 - 2018, Justin Tadlock * @link https://themehybrid.com/plugins/members * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html */ namespace Members\Admin; /** * Edit user screen class. * * @since 2.0.0 * @access public */ final class User_New { /** * Holds the instances of this class. * * @since 2.0.0 * @access private * @var object */ private static $instance; /** * Constructor method. * * @since 2.0.0 * @access private * @return void */ private function __construct() {} /** * Sets up needed actions/filters for the admin to initialize. * * @since 2.0.0 * @access private * @return void */ private function setup_actions() { // If multiple roles per user is not enabled, bail. // // @since 2.0.1 Added a check to not run on multisite. // @link https://github.com/justintadlock/members/issues/153 if ( ! members_multiple_user_roles_enabled() || is_multisite() ) return; // Only run our customization on the 'user-edit.php' page in the admin. add_action( 'load-user-new.php', array( $this, 'load' ) ); // Sets the new user's roles. add_action( 'user_register', array( $this, 'user_register' ), 5 ); } /** * Adds actions/filters on load. * * @since 2.0.0 * @access public * @return void */ public function load() { // Adds the profile fields. add_action( 'user_new_form', array( $this, 'profile_fields' ) ); // Handle scripts. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) ); add_action( 'admin_footer', array( $this, 'print_scripts' ), 25 ); } /** * Adds custom profile fields. * * @since 2.0.0 * @access public * @return void */ public function profile_fields() { if ( ! current_user_can( 'promote_users' ) ) return; // Get the default user roles. $new_user_roles = apply_filters( 'members_default_user_roles', array( get_option( 'default_role' ) ) ); // If the form was submitted but didn't go through, get the posted roles. if ( isset( $_POST['createuser'] ) && ! empty( $_POST['members_user_roles'] ) ) $new_user_roles = array_map( 'members_sanitize_role', $_POST['members_user_roles'] ); $roles = members_get_roles(); ksort( $roles ); wp_nonce_field( 'new_user_roles', 'members_new_user_roles_nonce' ); ?>
|