WPDK  1.5.0
WordPress Development Kit
 All Data Structures Files Functions Variables Pages
WPDKMenu Class Reference

Public Member Functions

 __construct ($id, $menu_title, $capability=self::DEFAULT_CAPABILITY, $icon= '', $position=null)
 Construct. More...
 
 addDivider ($title= '')
 Divider. More...
 
 addSubMenu ($menu_title, $view_controller, $capability=WPDKMenu::DEFAULT_CAPABILITY)
 Add sub menus. More...
 
 render ()
 Render. More...
 

Static Public Member Functions

static sanitizeViewController ($view_controller)
 Sanitize. More...
 
static menu ($view_controller)
 
static url ($view_controller)
 
static hook ($view_controller)
 Hook id. More...
 
static page ($view_controller)
 Page id. More...
 
static renderByArray ($menus)
 Render by array. More...
 
static addSubMenuAt (&$menus, $menu_item, $index)
 Add submenu. More...
 
static addSubMenusAt (&$menus, $submenus, $index)
 Brief. More...
 
static isPageWithMenu ($id)
 Check displayed page. More...
 

Data Fields

const DEFAULT_CAPABILITY = 'read'
 Capability. More...
 
const GLOBAL_MENU = 'wpdk_menus'
 Global key. More...
 
 $capability
 Capability. More...
 
 $hookName
 Hook name. More...
 
 $icon
 Icon. More...
 
 $id
 Menu ID. More...
 
 $menuTitle
 Menu title. More...
 
 $position
 Position. More...
 
 $subMenus
 Sub menus. More...
 

Detailed Description

This class is the top level menu model

Overview

$menu = new WPDKMenu( 'wpdk-sample-menu', __( 'WPDK Sample', WPXWPDKSAMPLEMENU_TEXTDOMAIN ), self::MENU_CAPABILITY, $icon_menu );
$menu->addSubMenu( __( 'First item' ), 'WPXWPDKSamplemenuViewController' );
$menu->addDivider();
$menu->addSubMenu( __( 'Second item' ), 'WPXWPDKSamplemenuViewController' );
$menu->addSubMenu( __( 'Options' ), 'WPXWPDKSamplemenuViewController' );
$menu->addDivider( 'More' );
$menu->addSubMenu( __( 'About' ), 'WPXWPDKSamplemenuViewController' );
$menu->render();

WPDK Sample

Author
=undo= info@.nosp@m.wpxt.nosp@m.re.me
Date
2013-02-22
Version
1.0.0

Definition at line 28 of file wpdk-menu.php.

Constructor & Destructor Documentation

__construct (   $id,
  $menu_title,
  $capability = self::DEFAULT_CAPABILITY,
  $icon = '',
  $position = null 
)

Construct.

Create an instance of WPDKMenu class

Parameters
string$idmenu unique string id
string$menu_titleThe menu title
string$capabilityOptional. Minimun capabilties to show this item. Default WPDKMenu::DEFAULT_CAPABILITY
string$iconOptional. The url to the icon to be used for this menu. Using 'none' would leave div.wp-menu-image empty so an icon can be added as background with CSS.
int$positionOptional. The position in the menu order this one should appear
Returns
WPDKMenu

Definition at line 113 of file wpdk-menu.php.

Member Function Documentation

addDivider (   $title = '')

Divider.

Add a special submenu as separator

Parameters
string$title
Returns
WPDKSubMenu

Definition at line 320 of file wpdk-menu.php.

addSubMenu (   $menu_title,
  $view_controller,
  $capability = WPDKMenu::DEFAULT_CAPABILITY 
)

Add sub menus.

Return an instance of WPDKSubMenu after add a sub menu to this main menu

Parameters
string$menu_titleMenu title
string$view_controllerName of view controller
string$capabilityOptional. Minimun capabilties to show this item. Default WPDKMenu::DEFAULT_CAPABILITY
Returns
WPDKSubMenu

Definition at line 341 of file wpdk-menu.php.

static addSubMenuAt ( $menus,
  $menu_item,
  $index 
)
static

Add submenu.

Add a submenu item at index position into the $menus array,

Sample

$menus = array(
  'wpx_ras_main' => array(
    'menuTitle'  => __( 'REST API Server', WPXRESTAPISERVER_TEXTDOMAIN ),
    'capability' => self::MENU_CAPABILITY,
    'icon'       => $icon_menu,
    'subMenus'   => array(

      array(
        'menuTitle' =>  __( 'Servers', WPXRESTAPISERVER_TEXTDOMAIN ),
        'viewController' => 'WPXRESTAPIServerServersListTableViewController',
        'capability'     => self::MENU_CAPABILITY,
      ),

      WPDKSubMenuDivider::DIVIDER,

      array(
        'menuTitle' =>  __( 'Preferences' ),
        'viewController' => 'WPXRESTAPIServerConfigurationCoreViewController',
        'capability'     => self::MENU_CAPABILITY,
      ),
      array(
        'menuTitle' =>  __( 'About' ),
        'capability'     => self::MENU_CAPABILITY,
        'viewController' => 'WPXRESTAPIServerAboutViewController',
      ),
    )
  )
);

$new = array(
  'menuTitle'      => __( 'New Menu' ),
  'viewController' => 'WPXRESTAPIServerConfigurationCoreViewController',
  'capability'     => self::MENU_CAPABILITY,
);

WPDKMenu::addSubMenuAt( $menus, $new, 2 );

WPDKMenu::renderByArray( $menus );
Parameters
array$menusArray menu used in WPDKMenu::renderByArray() method
array$menu_itemSingle new array to add
int$indexStart position from the first menu item (zero base).
Returns
array

Definition at line 426 of file wpdk-menu.php.

static addSubMenusAt ( $menus,
  $submenus,
  $index 
)
static

Brief.

Recursive version of self::addSubMenuAt()

$submenus = array(
  WPDKSubMenuDivider::DIVIDER,
  array(
    'menuTitle'      => __( 'Extensions', WPXTREME_TEXTDOMAIN ),
    'capability'     => self::MENU_CAPABILITY,
    'viewController' => array( $this, 'about' ),
  ),
  array(
    'menuTitle'      => __( 'About', WPXTREME_TEXTDOMAIN ),
    'capability'     => self::MENU_CAPABILITY,
    'viewController' => array( $this, 'about' ),
  )
);

WPDKMenu::addSubMenusAt( $this->menus, $submenus, -1 );
Since
1.3.1
Parameters
array$menusArray menu used in WPDKMenu::renderByArray() method
array$submenusArray of new menu
int$indexStart position from the first menu item (zero base).
Returns
mixed

Definition at line 467 of file wpdk-menu.php.

static hook (   $view_controller)
static

Hook id.

Return the hook id for a view controller

Since
1.2.0
Parameters
string$view_controllerClass name of view controller
Returns
string

Definition at line 201 of file wpdk-menu.php.

static isPageWithMenu (   $id)
static

Check displayed page.

Return TRUE if the displayed page is the view controller

Since
1.2.0
Parameters
string$idThe menu id
Returns
bool

Definition at line 495 of file wpdk-menu.php.

static menu (   $view_controller)
static

Return the WPDK menu info by name of view controller of submenu item

Parameters
string | array$view_controllerAny callable or view controller class name
Returns
array

Definition at line 152 of file wpdk-menu.php.

static page (   $view_controller)
static

Page id.

Return the page id for a view controller

Since
1.2.0
Parameters
string$view_controllerClass name of view controller
Returns
string

Definition at line 221 of file wpdk-menu.php.

render ( )

Render.

Register this menu tree to WordPress menu

Definition at line 359 of file wpdk-menu.php.

static renderByArray (   $menus)
static

Render by array.

Return an array with WPDKMenu instance as render a menu from an array

$menus = array(
  'wpdk-sample-menu' => array(
    'menuTitle'  => __( 'WPDK Sample', WPXWPDKSAMPLEMENU_TEXTDOMAIN ),
    'capability' => self::MENU_CAPABILITY,
    'icon'       => $icon_menu,
    'subMenus'   => array(
      array(
        'menuTitle' =>  __( 'First item' ),
        'viewController' => 'WPXWPDKSamplemenuViewController',
      ),
      WPDKSubMenuDivider::DIVIDER,
      array(
        'menuTitle' =>  __( 'Second item' ),
        'viewController' => 'WPXWPDKSamplemenuViewController',
      ),
      array(
        'menuTitle' =>  __( 'Options' ),
        'viewController' => 'WPXWPDKSamplemenuViewController',
      ),
      array( WPDKSubMenuDivider::DIVIDER => 'More' ),
      array(
        'menuTitle' =>  __( 'About' ),
        'viewController' => 'WPXWPDKSamplemenuViewController',
      ),
    )
  )
);
Parameters
array$menusA key value pairs array with the list of menu
Returns
array

Definition at line 268 of file wpdk-menu.php.

static sanitizeViewController (   $view_controller)
static

Sanitize.

Return a sanitize view controller for a callable

Parameters
string | array$view_controllerCallable
Returns
string

Definition at line 132 of file wpdk-menu.php.

static url (   $view_controller)
static

Return the compute URL of menu item from view controller name

Parameters
string$view_controllerClass name of view controller
Returns
string

Definition at line 174 of file wpdk-menu.php.

Field Documentation

string $capability

Capability.

Minumun capabilty require to display this menu

Definition at line 49 of file wpdk-menu.php.

string $hookName

Hook name.

WorkPress hook name - returned from add_menu_page()

Definition at line 57 of file wpdk-menu.php.

string $icon

Icon.

The url to the icon to be used for this menu.

Definition at line 65 of file wpdk-menu.php.

string $id

Menu ID.

Unique menu ID

Definition at line 73 of file wpdk-menu.php.

string $menuTitle

Menu title.

The top level menu title

Definition at line 81 of file wpdk-menu.php.

int $position

Position.

The position in the menu order this one should appear

Definition at line 89 of file wpdk-menu.php.

array $subMenus

Sub menus.

An array with the sub menus list

Definition at line 97 of file wpdk-menu.php.

const DEFAULT_CAPABILITY = 'read'

Capability.

Default capability

Definition at line 35 of file wpdk-menu.php.

const GLOBAL_MENU = 'wpdk_menus'

Global key.

The global key for access to the wpdk menu list

Definition at line 41 of file wpdk-menu.php.


The documentation for this class was generated from the following file: