/**
  * Add/edit form
  */
 public function form()
 {
     $form = $this->prepare_screen();
     /**
      * postbox-controll
      */
     $form['box-1-open'] = array('#type' => 'markup', '#markup' => '<div id="post-body-content">', '_builtin' => true);
     $html = '<ul class="types">';
     $subpages = wpcf_admin_menu_get_subpages();
     foreach ($subpages as $menu_slug => $menu) {
         if (isset($menu['context']) && 'menu_only' == $menu['context']) {
             continue;
         }
         $html .= sprintf('<li><a href="%s"><span class="%s %s"></span>%s</a></li>', esc_url(add_query_arg(array('page' => $menu_slug), admin_url('admin.php'))), esc_attr(isset($menu['toolset_icon']) ? $menu['toolset_icon'] : 'icon-toolset-logo'), esc_attr($menu_slug), $menu['menu_title']);
     }
     $html .= '</ul>';
     $form['box-content'] = array('#type' => 'markup', '#markup' => $html, '_builtin' => true);
     $form['box-1-close'] = array('#type' => 'markup', '#markup' => '</div>', '_builtin' => true);
     return $form;
 }
/**
 * admin_menu hook.
 */
function wpcf_admin_menu_hook()
{
    $wpcf_capability = apply_filters('wpcf_capability', WPCF_CUSTOM_POST_TYPE_VIEW);
    add_menu_page(__('Types', 'wpcf'), __('Types', 'wpcf'), $wpcf_capability, 'wpcf', 'wpcf_admin_menu_summary');
    $subpages = wpcf_admin_menu_get_subpages();
    foreach ($subpages as $menu_slug => $menu) {
        if (isset($menu['context']) && 'dashboard_only' == $menu['context']) {
            continue;
        }
        wpcf_admin_add_submenu_page($menu, $menu_slug);
    }
    if (isset($_GET['page'])) {
        $current_page = $_GET['page'];
        switch ($current_page) {
            /**
             * User Fields Control
             */
            case 'wpcf-user-fields-control':
                wpcf_admin_add_submenu_page(array('menu_title' => __('User Field Control', 'wpcf'), 'function' => 'wpcf_admin_menu_user_fields_control', 'capability_filter' => 'wpcf_ufc_view'), 'wpcf-user-fields-control');
                break;
                /**
                 *  Post Fields Control
                 */
            /**
             *  Post Fields Control
             */
            case 'wpcf-custom-fields-control':
                wpcf_admin_add_submenu_page(array('menu_title' => __('Post Field Control', 'wpcf'), 'function' => 'wpcf_admin_menu_custom_fields_control', 'capability_filter' => 'wpcf_cfc_view'), 'wpcf-custom-fields-control');
                break;
                /**
                 * Import/Export
                 */
            /**
             * Import/Export
             */
            case 'wpcf-import-export':
                wpcf_admin_add_submenu_page(array('menu_title' => __('Import/Export', 'wpcf'), 'function' => 'wpcf_admin_menu_import_export'), 'wpcf-import-export');
                break;
                /**
                 * debug
                 */
            /**
             * debug
             */
            case 'wpcf-debug-information':
                wpcf_admin_add_submenu_page(array('menu_title' => __('Debug Information', 'wpcf'), 'function' => 'wpcf_admin_menu_debug_information'), 'wpcf-debug-information');
                break;
                /**
                 * custom field grup
                 */
            /**
             * custom field grup
             */
            case 'wpcf-edit':
                $title = isset($_GET['group_id']) ? __('Edit Group', 'wpcf') : __('Add New Post Field Group', 'wpcf');
                $hook = wpcf_admin_add_submenu_page(array('menu_title' => $title, 'function' => 'wpcf_admin_menu_edit_fields', 'capability' => WPCF_CUSTOM_FIELD_VIEW), $current_page);
                add_action('load-' . $hook, 'wpcf_admin_menu_edit_fields_hook');
                wpcf_admin_plugin_help($hook, 'wpcf-edit');
                break;
            case 'wpcf-view-custom-field':
                $hook = wpcf_admin_add_submenu_page(array('menu_title' => __('View Post Field Group', 'wpcf'), 'function' => 'wpcf_admin_menu_edit_fields', 'capability' => WPCF_CUSTOM_FIELD_VIEW), $current_page);
                wpcf_admin_plugin_help($hook, 'wpcf-edit');
                break;
                /**
                 * custom post
                 */
            /**
             * custom post
             */
            case 'wpcf-edit-type':
                $title = __('Add New Post Type', 'wpcf');
                if (isset($_GET['wpcf-post-type'])) {
                    $title = __('Edit Post Type', 'wpcf');
                }
                $hook = wpcf_admin_add_submenu_page(array('menu_title' => $title, 'function' => 'wpcf_admin_menu_edit_type', 'capability' => WPCF_CUSTOM_FIELD_EDIT), $current_page);
                add_action('load-' . $hook, 'wpcf_admin_menu_edit_type_hook');
                wpcf_admin_plugin_help($hook, 'wpcf-edit-type');
                break;
            case 'wpcf-view-type':
                $hook = wpcf_admin_add_submenu_page(array('menu_title' => __('View Post Type', 'wpcf'), 'function' => 'wpcf_admin_menu_edit_type', 'capability' => WPCF_CUSTOM_FIELD_VIEW), $current_page);
                add_action('load-' . $hook, 'wpcf_admin_menu_edit_type_hook');
                wpcf_admin_plugin_help($hook, 'wpcf-edit-type');
                break;
            case 'wpcf-edit-tax':
                $title = isset($_GET['wpcf-tax']) ? __('Edit Taxonomy', 'wpcf') : __('Add New Taxonomy', 'wpcf');
                $hook = wpcf_admin_add_submenu_page(array('menu_title' => $title, 'function' => 'wpcf_admin_menu_edit_tax', 'capability' => WPCF_CUSTOM_TAXONOMY_EDIT), $current_page);
                add_action('load-' . $hook, 'wpcf_admin_menu_edit_tax_hook');
                wpcf_admin_plugin_help($hook, 'wpcf-edit-tax');
                break;
            case 'wpcf-view-tax':
                $hook = wpcf_admin_add_submenu_page(array('menu_title' => __('View Taxonomy', 'wpcf'), 'function' => 'wpcf_admin_menu_edit_tax', 'capability' => WPCF_CUSTOM_TAXONOMY_VIEW), $current_page);
                add_action('load-' . $hook, 'wpcf_admin_menu_edit_tax_hook');
                wpcf_admin_plugin_help($hook, 'wpcf-edit-tax');
                break;
                /**
                 * user meta fields
                 */
            /**
             * user meta fields
             */
            case 'wpcf-edit-usermeta':
                $title = isset($_GET['group_id']) ? __('Edit User Field Group', 'wpcf') : __('Add New User Field Group', 'wpcf');
                $hook = wpcf_admin_add_submenu_page(array('menu_title' => $title, 'function' => 'wpcf_admin_menu_edit_user_fields', 'capability' => WPCF_USER_META_FIELD_EDIT), $current_page);
                wpcf_admin_plugin_help($hook, 'wpcf-edit-usermeta');
                break;
            case 'wpcf-view-usermeta':
                $hook = wpcf_admin_add_submenu_page(array('menu_title' => __('View User Field Group', 'wpcf'), 'function' => 'wpcf_admin_menu_edit_user_fields', 'capability' => WPCF_USER_META_FIELD_VIEW), $current_page);
                wpcf_admin_plugin_help($hook, 'wpcf-edit-usermeta');
                break;
            case WPCF_Page_Edit_Termmeta::PAGE_NAME:
                // Initialize the page.
                /** @var WPCF_Page_Edit_Termmeta $termmeta_page */
                $termmeta_page = WPCF_Page_Edit_Termmeta::get_instance();
                $termmeta_page->initialize();
                break;
            case WPCF_Page_Control_Termmeta::PAGE_NAME:
                // Initialize by creating an instance.
                /** @var WPCF_Page_Control_Termmeta $term_field_control_page */
                $term_field_control_page = WPCF_Page_Control_Termmeta::get_instance();
                $term_field_control_page->initialize();
                break;
        }
    }
    // Check if migration from other plugin is needed
    if (class_exists('Acf') && !class_exists('acf_pro') || defined('CPT_VERSION')) {
        $hook = add_submenu_page('wpcf', __('Migration', 'wpcf'), __('Migration', 'wpcf'), 'manage_options', 'wpcf-migration', 'wpcf_admin_menu_migration');
        add_action('load-' . $hook, 'wpcf_admin_menu_migration_hook');
        wpcf_admin_plugin_help($hook, 'wpcf-migration');
    }
    do_action('wpcf_menu_plus');
    // remove the repeating Types submenu
    remove_submenu_page('wpcf', 'wpcf');
}