* @copyright Copyright (c) 2017, Justin Tadlock * @link http://themehybrid.com/plugins/members-role-hierarchy * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html */ /** * Edit role class. * * @since 1.0.0 * @access public */ final class MRH_Edit_Role { /** * Returns the instance. * * @since 1.0.0 * @access public * @return object */ public static function get_instance() { static $instance = null; if ( is_null( $instance ) ) { $instance = new self; $instance->setup_actions(); } return $instance; } /** * Constructor method. * * @since 1.0.0 * @access private * @return void */ private function __construct() {} /** * Sets up actions and filters. * * @since 1.0.0 * @access public * @return void */ private function setup_actions() { // Call when screen is loaded. add_action( 'members_load_role_edit', array( $this, 'load' ) ); add_action( 'members_load_role_new', array( $this, 'load' ) ); // Save role position. add_action( 'members_role_updated', array( $this, 'save' ) ); add_action( 'members_role_added', array( $this, 'save' ) ); } /** * Runs on the role new/edit screen load. * * @since 1.0.0 * @access public * @return void */ public function load() { add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); } /** * Adds custom meta boxes to the edit role screen. * * @since 1.0.0 * @access public * @param string $screen_id * @param string $role * @return void */ public function add_meta_boxes( $screen_id, $role = '' ) { // If role isn't editable, bail. if ( $role && ! members_is_role_editable( $role ) ) return; // Add the meta box. add_meta_box( 'mrh_role_position', esc_html__( 'Role Position', 'members' ), array( $this, 'meta_box' ), $screen_id, 'side', 'default' ); } /** * Outputs the role position meta box. * * @since 1.0.0 * @access public * @param object $role * @return void */ public function meta_box( $role ) { $position = $role ? mrh_get_role_position( $role->name ) : mrh_get_default_role_position(); wp_nonce_field( 'role_position', 'mrh_role_position_nonce' ); ?>