Admin Page Framework Documentation

Packages

  • AdminPageFramework
    • Common
      • Factory
      • Form
        • FieldType
      • Utility
    • Factory
      • AdminPage
      • MetaBox
      • NetworkAdmin
      • PageMetaBox
      • PostType
      • TaxonomyField
      • TermMeta
      • UserMeta
      • Widget
    • Utility

Classes

  • AdminPageFramework
  • AdminPageFramework_Controller
  • AdminPageFramework_Controller_Form
  • AdminPageFramework_Controller_Menu
  • AdminPageFramework_Controller_Page
  • AdminPageFramework_View

Resources

  • Tutorials
  • Support
  • Reporting Issues

Class AdminPageFramework_Controller_Menu

Provides methods to manipulate menu items.

Abstract
Package: AdminPageFramework\Factory\AdminPage
Since: 2.0.0
Since: 3.3.1 Changed the name from AdminPageFramework_Menu.
Since: 3.6.3 Changed the name from AdminPageFramework_Menu_Controller.
Extends: AdminPageFramework_View_Menu
Located at factory/admin_page/AdminPageFramework_Controller_Menu.php

Methods summary

public
# setRootMenuPage( string $sRootMenuLabel, string $sIcon16x16 = null, string $iMenuPosition = null )

Sets to which top level page is going to be adding sub-pages.

Example

$this->setRootMenuPage( 'Settings' );
$this->setRootMenuPage(
    'APF Form',
    plugins_url( 'image/screen_icon32x32.jpg', __FILE__ )
);

Parameters

$sRootMenuLabel
string
If the method cannot find the passed string from the following listed items, it will create a top level menu item with the passed string. ( case insensitive )
Dashboard, Posts, Media, Links, Pages, Comments, Appearance, Plugins, Users, Tools, Settings, Network Admin
$sIcon16x16
string
(optional) the source of menu icon with either of the following forms:
  • the URL of the menu icon with the size of 16 by 16 in pixel.
  • the file path of the menu icon with the size of 16 by 16 in pixel.
  • the name of a Dashicons helper class to use a font icon, e.g. dashicons-editor-customchar.
  • the string, 'none', to leave div.wp-menu-image empty so an icon can be added via CSS.
  • a base64-encoded SVG using a data URI, which will be colored to match the color scheme. This should begin with 'data:image/svg+xml;base64,'.
$iMenuPosition
string
(optional) the position number that is passed to the $position parameter of the add_menu_page() function.

Since

2.0.0
2.1.6 The $sIcon16x16 parameter accepts a file path.
3.0.0 The scope was changed to public from protected.

Remark

Only one root page can be set per one class instance.
public
# setRootMenuPageBySlug( string $sRootMenuSlug )

Sets the top level menu page by page slug.

The page should be already created or scheduled to be created separately.

Example

$this->setRootMenuPageBySlug( 'edit.php?post_type=apf_posts' );

Parameters

$sRootMenuSlug
string
The page slug of the top-level root page.

Since

2.0.0
3.0.0 The scope was changed to public from protected.
public
# addSubMenuItems( )

Adds sub-menu items on the left sidebar menu of the administration panel.

It supports pages and links. Each of them has the specific array structure.

Example

$this->addSubMenuItems(
      array(
          'title'         => 'Various Form Fields',
          'page_slug'     => 'first_page',
          'screen_icon'   => 'options-general',
      ),
      array(
          'title'         => 'Manage Options',
          'page_slug'     => 'second_page',
          'screen_icon'   => 'link-manager',
      ),
      array(
          'title'         => 'Google',
          'href'          => 'http://www.google.com',
          'show_page_heading_tab' => false, // this removes the title from the page heading tabs.
      )
);

Since

2.0.0
3.0.0 Changed the scope to public.

Remark

The sub menu page slug should be unique because add_submenu_page() can add one callback per page slug.
Accepts variadic parameters; the number of accepted parameters are not limited to three.
public
# addSubMenuItem( array $aSubMenuItem )

Adds the given sub-menu item on the left sidebar menu of the administration panel.

It supports pages and links. Each of them has the specific array structure.

Example

$this->addSubMenuItem(
      array(
          'title'         => 'Read Me',
          'menu_title'    => 'About'
          'page_slug'     => 'my_plugin_readme',
      )
);

Parameters

$aSubMenuItem
array
a sub-menu array. It can be a page or a link. The array structures are as follows:

Sub-menu Page Arguments

  • title - (string) the page title of the page.
  • page_slug - (string) the page slug of the page. Non-alphabetical characters should not be used including dots(.) and hyphens(-).
  • screen_icon - (optional, string) either the ID selector name from the following list or the icon URL. The size of the icon should be 32 by 32 in pixel. This is for WordPress 3.7.x or below.
    edit, post, index, media, upload, link-manager, link, link-category, edit-pages, page, edit-comments, themes, plugins, users, profile, user-edit, tools, admin, options-general, ms-admin, generic

    ( Notes: the generic icon is available WordPress version 3.5 or above.)

  • capability - (optional, string) the access level to the created admin pages defined here. If not set, the overall capability assigned in the class constructor, which is manage_options by default, will be used.
  • order - (optional, integer) the order number of the page. The lager the number is, the lower the position it is placed in the menu.
  • show_page_heading_tab - (optional, boolean) if this is set to false, the page title won't be displayed in the page heading tab. Default: true.
  • show_in_menu - (optional) If this is set to false, the page title won't be displayed in the sidebar menu while the page is still accessible. Default: true.
  • page_title - (optional) [3.3.0+] When the page title differs from the menu title, use this argument.
  • menu_title - (optional) [3.3.0+] When the menu title differs from the menu title, use this argument.
  • style - (optional) [3.6.3+] (string|array) The path or url of a stylesheet which gets loaded in the head tag. Or inline CSS rules. When custom arguments need to be set such as whether it should be inserted in the footer, set an array holding the following arguments.
    • src - (required, string) the source url or path.
    • handle_id - (optional, string) The handle ID of the stylesheet.
    • dependencies - (optional, array) The dependency array.
    • version - (optional, string) The stylesheet version number.
    • media - (optional, string) the description of the field which is inserted into the after the input field tag.
  • script - (optional) [3.6.3+] (string|array) The path or url of a JavaScript script which gets loaded in the head tag. Or an inline JavaScript script. When custom arguments need to be set such as whether it should be inserted in the footer, set an array holding the following arguments.
    • src - (required, string) the source url or path.
    • handle_id - (optional, string) The handle ID of the stylesheet.
    • dependencies - (optional, array) The dependency array.
    • version - (optional, string) The stylesheet version number.
    • translation - (optional, array) an array holding translation key-value pairs.
  • disabled - (optional, boolean) [3.5.10+] If false, in the page heading navigation tab, the link will be disabled. Default: false.
  • attributes - (optional, array) [3.5.10+] An attribute array applied to navigation tab element.
  • show_debug_info - (optional, boolean) [3.8.8+] Whether to show debug information. If WP_DEBUG is false, the debug output will not be displayed. Default: true.

Sub-menu Link Arguments

  • title - (string) the link title.
  • href - (string) the URL of the target link.
  • capability - (optional, string) the access level to show the item, defined here. If not set, the overall capability assigned in the class constructor, which is manage_options by default, will be used.
  • order - (optional, integer) the order number of the page. The lager the number is, the lower the position it is placed in the menu.
  • show_page_heading_tab - (optional, boolean) if this is set to false, the page title won't be displayed in the page heading tab. Default: true.

Since

2.0.0
3.0.0 Changed the scope to public.

Remark

The sub menu page slug should be unique because add_submenu_page() can add one callback per page slug.

Magic methods summary

Properties summary

Related

Indirect known subclasses

AdminPageFramework, AdminPageFramework_Controller, AdminPageFramework_NetworkAdmin, AdminPageFramework_View

If you find undocumented functionality, please report it here.

Admin Page Framework