HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: //proc/self/cwd/wp-content/plugins/members/addons/members-role-hierarchy/admin/class-edit-role.php
<?php
/**
 * Adds the role position meta box on the edit/new role screen and handles the save
 * callback functionality.
 *
 * @package   MembersRoleHierarchy
 * @author    Justin Tadlock <justin@justintadlock.com>
 * @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' ); ?>

		<label>
			<input type="number" name="mrh_role_position" value="<?php echo esc_attr( $position ); ?>" />
		</label>

		<p class="description">
			<?php esc_html_e( "Set the role's position in the hierarchy.", 'members' ); ?>
		</p>
	<?php }

	/**
	 * Saves the role position.
	 *
	 * @since  1.0.0
	 * @access public
	 * @param  string  $role
	 * @return void
	 */
	public function save( $role ) {

		// Verify the nonce before proceeding.
		if ( ! isset( $_POST['mrh_role_position_nonce'] ) || ! wp_verify_nonce( $_POST['mrh_role_position_nonce'], 'role_position' ) ) {
			return;
		}

		// Get the current role to edit.
		$role = members_sanitize_role( $role );

		// If the role doesn't exist, bail.
		if ( ! $role )
			return;

		// Get the posted position.
		$new_position = isset( $_POST['mrh_role_position'] ) ? intval( $_POST['mrh_role_position'] ) : 0;

		// Get the role's current position.
		$old_position = mrh_get_role_position( $role );

		// If the posted position doesn't matche the old position, update it.
		if ( $new_position != $old_position )
			mrh_set_role_position( $role, $new_position );
	}
}

MRH_Edit_Role::get_instance();