* @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_Edit { /** * Holds the instances of this class. * * @since 2.0.0 * @access private * @var object */ private static $instance; /** * Sets up needed actions/filters for the admin to initialize. * * @since 2.0.0 * @access public * @return void */ public function __construct() { // If multiple roles per user is not enabled, bail. if ( ! members_multiple_user_roles_enabled() ) return; // Only run our customization on the 'user-edit.php' page in the admin. add_action( 'load-user-edit.php', array( $this, 'load_user_edit' ) ); add_action( 'load-profile.php', array( $this, 'load_user_edit' ) ); } /** * Adds actions/filters on load. * * @since 2.0.0 * @access public * @return void */ public function load_user_edit() { // Handle scripts and styles. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) ); add_action( 'admin_footer', array( $this, 'print_scripts' ), 25 ); add_action( 'admin_head', array( $this, 'print_styles' ) ); add_action( 'show_user_profile', array( $this, 'profile_fields' ) ); add_action( 'edit_user_profile', array( $this, 'profile_fields' ) ); // Must use `profile_update` to change role. Otherwise, WP will wipe it out. add_action( 'profile_update', array( $this, 'role_update' ), 10, 2 ); } /** * Adds custom profile fields. * * @since 2.0.0 * @access public * @param object $user * @return void */ public function profile_fields( $user ) { global $wp_roles; if ( ! current_user_can( 'promote_users' ) || ! current_user_can( 'edit_user', $user->ID ) ) return; $user_roles = (array) $user->roles; $roles = members_get_roles(); ksort( $roles ); wp_nonce_field( 'new_user_roles', 'members_new_user_roles_nonce' ); ?>
|