function show_sub_tab_page($page, $tab, $subtab)
 {
     $menu = hrm_page();
     if (!isset($menu[$page][$tab]['submenu'])) {
         return;
     }
     if (empty($menu[$page][$tab]['submenu']) && count($menu[$page][$tab]['submenu'])) {
         $subtab = key($menu[$page][$tab]['submenu']);
         if (!hrm_user_can_access($tab, $subtab, 'view')) {
             printf('<h1>%s</h1>', __('You do not have permission to access this page', 'cpm'));
             return false;
         }
         $path = isset($menu[$page][$tab]['submenu'][$subtab]['file_path']) ? $menu[$page][$tab]['submenu'][$subtab]['file_path'] : '';
         $path = apply_filters('hrm_subtab_path', $path, $page, $tab, $subtab);
         if (file_exists($path)) {
             require_once $path;
         } else {
             echo 'Page not found';
         }
     } else {
         if (!hrm_user_can_access($tab, $subtab, 'view')) {
             printf('<h1>%s</h1>', __('You do not have permission to access this page', 'cpm'));
             return;
         }
         $path = isset($menu[$page][$tab]['submenu'][$subtab]['file_path']) ? $menu[$page][$tab]['submenu'][$subtab]['file_path'] : '';
         $path = apply_filters('hrm_subtab_path', $path, $page, $tab, $subtab);
         if (file_exists($path)) {
             require_once $path;
         } else {
             echo 'Page not found';
         }
     }
 }
<?php

$menu = hrm_page();
$employee_id = hrm_get_employee_id();
?>
<h2 class="nav-tab-wrapper">
    <?php 
foreach ($menu[$page] as $key => $tab_event) {
    if (!isset($tab_event['nested_tab'])) {
        continue;
    }
    if (!$tab_event['nested_tab']) {
        continue;
    }
    $active = $tab == $key ? 'nav-tab-active' : '';
    $url = hrm_employee_menu_url($page, $key, $employee_id);
    //hrm_tab_menu_url( $key, $page );
    //$url = add_query_arg( array( 'employee_id' => $employee_id ), $url );
    printf('<a href="%1$s" class="nav-tab %4$s" id="%2$s-tab">%3$s</a>', $url, $tab_event['id'], $tab_event['title'], $active);
}
?>
</h2>
<?php 
if (!$subtab) {
    if (!isset($menu[$page][$tab]['submenu'])) {
        return;
    }
    if (!count($menu[$page][$tab]['submenu'])) {
        return;
    }
    $subtab = key($menu[$page][$tab]['submenu']);
function hrm_get_query_args()
{
    $menu = hrm_page();
    $page = isset($_GET['page']) && !empty($_GET['page']) ? $_GET['page'] : false;
    if (!$page) {
        $query = array('page' => false, 'tab' => false, 'subtab' => false);
        return apply_filters('hrm_query_var', $query);
    }
    if (isset($_GET['tab']) && !empty($_GET['tab'])) {
        $tab = $_GET['tab'];
    } else {
        if (isset($menu[$page]) && count($menu[$page])) {
            $tab = array_keys($menu[$page]);
            $tab = reset($tab);
        } else {
            $tab = false;
        }
    }
    if (!$tab) {
        $query = array('page' => $page, 'tab' => false, 'subtab' => false);
        return apply_filters('hrm_query_var', $query);
    }
    if (isset($_GET['sub_tab']) && !empty($_GET['sub_tab'])) {
        $subtab = $_GET['sub_tab'];
    } else {
        if (isset($menu[$page][$tab]['submenu']) && count($menu[$page][$tab]['submenu'])) {
            $subtab = array_keys($menu[$page][$tab]['submenu']);
            $subtab = reset($subtab);
        } else {
            $subtab = false;
        }
    }
    if (!$subtab) {
        $query = array('page' => $page, 'tab' => $tab, 'subtab' => false);
        return apply_filters('hrm_query_var', $query);
    } else {
        $query = array('page' => $page, 'tab' => $tab, 'subtab' => $subtab);
        return apply_filters('hrm_query_var', $query);
    }
}
 function admin_page_handler()
 {
     if (!is_user_logged_in()) {
         sprintf('Please <a href="%s">login</a>', wp_login_url());
         return;
     }
     $current_user_id = get_current_user_id();
     $user_status = get_user_meta($current_user_id, '_status', true);
     if ($user_status == 'no') {
         _e('<div class="hrm wrap"><h1>This account temporary disabled!</h1></div>', 'hrm');
         return;
     }
     $menu = hrm_page();
     $query_args = hrm_get_query_args();
     $page = $query_args['page'];
     $tab = $query_args['tab'];
     $subtab = $query_args['subtab'];
     if ($page == 'hrm_author') {
         require_once dirname(__FILE__) . '/templates/author/header.php';
         return;
     }
     echo '<div class="hrm wrap" id="hrm">';
     Hrm_Settings::getInstance()->show_tab_page($page, $tab, $subtab);
     echo '</div>';
 }
 function role_permission($role_name = false, $display_name = null)
 {
     $redirect = isset($_POST['hrm_dataAttr']['redirect']) && !empty($_POST['hrm_dataAttr']['redirect']) ? $_POST['hrm_dataAttr']['redirect'] : '';
     $get_tab = isset($_POST['hrm_dataAttr']['tab']) ? $_POST['hrm_dataAttr']['tab'] : '';
     if ($role_name !== false) {
         $roles = get_role($role_name);
         $hidden_form['id'] = array('type' => 'hidden', 'value' => 'edit');
     }
     $page = hrm_page();
     //hidden form
     $hidden_form['role_name'] = array('label' => __('Role', 'hrm'), 'type' => $role_name === false ? 'text' : 'hidden', 'required' => 'required', 'value' => $role_name === false ? '' : esc_attr($role_name), 'extra' => array('data-hrm_validation' => true, 'data-hrm_required' => true, 'data-hrm_required_error_msg' => __('This field is required', 'hrm')));
     $hidden_form['display_name'] = array('label' => __('Display Name', 'hrm'), 'type' => $display_name === null ? 'text' : 'hidden', 'value' => $display_name === null ? '' : esc_attr($display_name), 'required' => 'required', 'extra' => array('data-hrm_validation' => true, 'data-hrm_required' => true, 'data-hrm_required_error_msg' => __('This field is required', 'hrm')));
     foreach ($page as $tab => $tab_item) {
         foreach ($tab_item as $tab_name => $tab_name_itme) {
             if ($get_tab != $tab_name) {
                 continue;
             }
             $view = isset($roles->capabilities[$tab_name . '_view']) ? 'view' : '';
             $add = isset($roles->capabilities[$tab_name . '_add']) ? 'add' : '';
             $delete = isset($roles->capabilities[$tab_name . '_delete']) ? 'delete' : '';
             $tab_role[] = array('label' => __('View', 'hrm'), 'value' => 'view', 'class' => 'hrm-cap-' . $tab_name . '_view', 'checked' => $role_name === false ? 'view' : $view);
             $tab_role[] = array('label' => __('Add', 'hrm'), 'value' => 'add', 'class' => 'hrm-cap-' . $tab_name . '_add', 'checked' => $role_name === false ? 'add' : $add);
             $tab_role[] = array('label' => __('Delete', 'hrm'), 'value' => 'delete', 'class' => 'hrm-cap-' . $tab_name . '_delete', 'checked' => $role_name === false ? 'delete' : $delete);
             if (isset($tab_name_itme['role']) && is_array($tab_name_itme['role']) && count($tab_name_itme['role'])) {
                 foreach ($tab_name_itme['role'] as $role_value => $label) {
                     $checked = isset($roles->capabilities[$tab_name . '_' . $role_value]) ? $role_value : '';
                     $tab_role[] = array('label' => $label, 'value' => $role_value, 'class' => 'hrm-cap-' . $tab_name . '_' . $role_value, 'checked' => $role_name === false ? $role_value : $checked);
                 }
             }
             $hidden_form['cap[' . $tab_name . '][]'] = array('label' => $tab_name_itme['title'], 'type' => 'checkbox', 'desc' => 'Choose access permission', 'wrap_class' => 'hrm-parent-field', 'fields' => $tab_role);
             $tab_role = '';
             $tab_name_itme['submenu'] = isset($tab_name_itme['submenu']) ? $tab_name_itme['submenu'] : array();
             foreach ($tab_name_itme['submenu'] as $submenu => $submenu_item) {
                 $view = isset($roles->capabilities[$submenu . '_view']) ? 'view' : '';
                 $add = isset($roles->capabilities[$submenu . '_add']) ? 'add' : '';
                 $delete = isset($roles->capabilities[$submenu . '_delete']) ? 'delete' : '';
                 $submenu_role[] = array('label' => __('View', 'hrm'), 'value' => 'view', 'class' => 'hrm-cap-' . $submenu . '_view' . ' hrm-cap-' . $tab_name . '-view-child' . ' hrm-cap-' . $tab_name, 'checked' => $role_name === false ? 'view' : $view);
                 $submenu_role[] = array('label' => __('Add', 'hrm'), 'value' => 'add', 'class' => 'hrm-cap-' . $submenu . '_add' . ' hrm-cap-' . $tab_name . '-add-child' . ' hrm-cap-' . $tab_name, 'checked' => $role_name === false ? 'add' : $add);
                 $submenu_role[] = array('label' => __('Delete', 'hrm'), 'value' => 'delete', 'class' => 'hrm-cap-' . $submenu . '_delete' . ' hrm-cap-' . $tab_name . '-delete-child' . ' hrm-cap-' . $tab_name, 'checked' => $role_name === false ? 'delete' : $delete);
                 if (isset($submenu_item['role']) && is_array($submenu_item['role']) && count($submenu_item['role'])) {
                     foreach ($submenu_item['role'] as $role_value => $label) {
                         $checked = isset($roles->capabilities[$submenu . '_' . $role_value]) ? $role_value : '';
                         $submenu_role[] = array('label' => $label, 'value' => $role_value, 'class' => 'hrm-cap-' . $submenu . '_' . $role_value . ' hrm-cap-' . $tab_name . '-delete-child' . ' hrm-cap-' . $tab_name, 'checked' => $role_name === false ? $role_value : $checked);
                     }
                 }
                 $hidden_form['cap[' . $submenu . '][]'] = array('label' => $submenu_item['title'], 'type' => 'checkbox', 'desc' => 'Choose access permission', 'wrap_class' => 'hrm-child-field', 'fields' => $submenu_role);
                 $submenu_role = '';
             }
         }
     }
     $hidden_form['header'] = 'User Role';
     $hidden_form['action'] = 'user_role';
     $hidden_form['url'] = $redirect;
     ob_start();
     echo hrm_Settings::getInstance()->hidden_form_generator($hidden_form);
     $return_value = array('append_data' => ob_get_clean());
     return $return_value;
 }