/**
  * Test context calculations for submenus.
  */
 public function test_submenu_contexts()
 {
     $screen = get_current_screen();
     $self = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : null;
     $page = isset($_GET['page']) ? $_GET['page'] : null;
     $submenus = _fieldmanager_registry('submenus');
     _fieldmanager_registry('submenus', array());
     // Spoof is_admin().
     set_current_screen('dashboard-user');
     // Submenu of a default WordPress menu.
     $options_submenu = rand_str();
     fm_register_submenu_page($options_submenu, 'options-general.php', 'Options');
     $_SERVER['PHP_SELF'] = '/options-general.php';
     $_GET['page'] = $options_submenu;
     $this->assertEquals(array('submenu', $options_submenu), fm_calculate_context());
     // Submenu of a custom menu.
     $custom_menu_submenu = rand_str();
     fm_register_submenu_page($custom_menu_submenu, rand_str(), 'Custom');
     $_SERVER['PHP_SELF'] = '/admin.php';
     $_GET['page'] = $custom_menu_submenu;
     $this->assertEquals(array('submenu', $custom_menu_submenu), fm_calculate_context());
     // Submenu that Fieldmanager didn't register.
     $_SERVER['PHP_SELF'] = '/themes.php';
     $_GET['page'] = rand_str();
     $this->assertEquals(array(null, null), fm_calculate_context());
     $GLOBALS['current_screen'] = $screen;
     $_SERVER['PHP_SELF'] = $self;
     $_GET['page'] = $page;
     _fieldmanager_registry('submenus', $submenus);
 }
 public function tearDown($value = null)
 {
     $GLOBALS['current_screen'] = $this->screen;
     $_SERVER['PHP_SELF'] = $this->self;
     $_GET = $this->get;
     _fieldmanager_registry('submenus', $this->submenus);
 }
/**
 * Register submenu pages from the Fieldmanager registry.
 */
function _fm_add_submenus()
{
    $submenus = _fieldmanager_registry('submenus');
    if (!is_array($submenus)) {
        return;
    }
    foreach ($submenus as $s) {
        call_user_func_array('add_submenu_page', $s);
    }
}
 /**
  * Build a fieldmanager context from the default fields.
  *
  * @param  string $name The FM name.
  */
 private function get_context($name)
 {
     $fields = $this->get_fields($name);
     $fields->activate_submenu_page();
     return _fieldmanager_registry('active_submenu');
 }
 /**
  * Activate this group in an already-added submenu page
  * @param string $title
  */
 public function activate_submenu_page()
 {
     $this->require_base();
     $submenus = _fieldmanager_registry('submenus');
     $s = $submenus[$this->name];
     $active_submenu = new Fieldmanager_Context_Submenu($s[0], $s[1], $s[2], $s[3], $s[4], $this, True);
     _fieldmanager_registry('active_submenu', $active_submenu);
 }