page = add_submenu_page( 'members', $title, esc_html__( 'Roles', 'members' ), $edit_roles_cap, 'roles', array( $this, 'page' ) ); // Let's roll if we have a page. if ( $this->page ) { // If viewing the edit role page. if ( isset( $_REQUEST['action'] ) && 'edit' === $_REQUEST['action'] && current_user_can( 'edit_roles' ) ) $this->page_obj = new Role_Edit(); // If viewing the role list page. else $this->page_obj = new Roles(); // Load actions. add_action( "load-{$this->page}", array( $this, 'load' ) ); // Load scripts/styles. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) ); } } /** * Checks posted data on load and performs actions if needed. * * @since 2.0.0 * @access public * @return void */ public function load() { if ( method_exists( $this->page_obj, 'load' ) ) $this->page_obj->load(); } /** * Loads necessary scripts/styles. * * @since 2.0.0 * @access public * @param string $hook_suffix * @return void */ public function enqueue( $hook_suffix ) { if ( $this->page === $hook_suffix && method_exists( $this->page_obj, 'enqueue' ) ) $this->page_obj->enqueue(); } /** * Outputs the page. * * @since 2.0.0 * @access public * @return void */ public function page() { if ( method_exists( $this->page_obj, 'page' ) ) $this->page_obj->page(); } /** * Returns the instance. * * @since 2.0.0 * @access public * @return object */ public static function get_instance() { if ( ! self::$instance ) self::$instance = new self; return self::$instance; } } Manage_Roles::get_instance();