PHP Class WPDKMenu

## 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 * https://github.com/wpXtreme/wpdk-sample-menu
Author: =undo= ([email protected])
Datei anzeigen Open project: wpxtreme/wpdk Class Usage Examples

Public Properties

Property Type Description
$capability string Minumun capabilty require to display this menu
$hookName string WorkPress hook name - returned from add_menu_page()
$icon string The url to the icon to be used for this menu.
$id string Unique menu ID
$menuTitle string The top level menu title
$position integer The position in the menu order this one should appear
$subMenus array An array with the sub menus list

Public Methods

Method Description
__construct ( string $id, string $menu_title, string $capability = self::DEFAULT_CAPABILITY, string $icon = '', integer $position = null ) : WPDKMenu Create an instance of WPDKMenu class
addDivider ( string $title = '' ) : WPDKSubMenu Add a special submenu as separator
addSubMenu ( string $menu_title, string $view_controller, string $capability = WPDKMenu::DEFAULT_CAPABILITY ) : WPDKSubMenu Return an instance of WPDKSubMenu after add a sub menu to this main menu
addSubMenuAt ( array &$menus, array $menu_item, integer $index ) : array Add a submenu item at index position into the $menus array,
addSubMenusAt ( array &$menus, array $submenus, integer $index ) : mixed Recursive version of self::addSubMenuAt()
hook ( string $view_controller ) : string Return the hook id for a view controller
isPageWithMenu ( string $id ) : boolean Return TRUE if the displayed page is the view controller
menu ( string | array $view_controller ) : array Return the WPDK menu info by name of view controller of submenu item
page ( string $view_controller ) : string Return the page id for a view controller
render ( ) Register this menu tree to WordPress menu
renderByArray ( array $menus ) : array Return an array with WPDKMenu instance as render a menu from an array
sanitizeViewController ( string | array $view_controller ) : string Return a sanitize view controller for a callable
url ( string $view_controller ) : string Return the compute URL of menu item from view controller name

Method Details

__construct() public method

Create an instance of WPDKMenu class
public __construct ( string $id, string $menu_title, string $capability = self::DEFAULT_CAPABILITY, string $icon = '', integer $position = null ) : WPDKMenu
$id string menu unique string id
$menu_title string The menu title
$capability string Optional. Minimun capabilties to show this item. Default WPDKMenu::DEFAULT_CAPABILITY
$icon string Optional. 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.
$position integer Optional. The position in the menu order this one should appear
return WPDKMenu

addDivider() public method

Add a special submenu as separator
public addDivider ( string $title = '' ) : WPDKSubMenu
$title string
return WPDKSubMenu

addSubMenu() public method

Return an instance of WPDKSubMenu after add a sub menu to this main menu
public addSubMenu ( string $menu_title, string $view_controller, string $capability = WPDKMenu::DEFAULT_CAPABILITY ) : WPDKSubMenu
$menu_title string Menu title
$view_controller string Name of view controller
$capability string Optional. Minimun capabilties to show this item. Default WPDKMenu::DEFAULT_CAPABILITY
return WPDKSubMenu

addSubMenuAt() public static method

### 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 );
public static addSubMenuAt ( array &$menus, array $menu_item, integer $index ) : array
$menus array Array menu used in WPDKMenu::renderByArray() method
$menu_item array Single new array to add
$index integer Start position from the first menu item (zero base).
return array

addSubMenusAt() public static method

$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
public static addSubMenusAt ( array &$menus, array $submenus, integer $index ) : mixed
$menus array Array menu used in WPDKMenu::renderByArray() method
$submenus array Array of new menu
$index integer Start position from the first menu item (zero base).
return mixed

hook() public static method

Return the hook id for a view controller
Since: 1.2.0
public static hook ( string $view_controller ) : string
$view_controller string Class name of view controller
return string

isPageWithMenu() public static method

Return TRUE if the displayed page is the view controller
Since: 1.2.0
public static isPageWithMenu ( string $id ) : boolean
$id string The menu id
return boolean

menu() public static method

Return the WPDK menu info by name of view controller of submenu item
public static menu ( string | array $view_controller ) : array
$view_controller string | array Any callable or view controller class name
return array

page() public static method

Return the page id for a view controller
Since: 1.2.0
public static page ( string $view_controller ) : string
$view_controller string Class name of view controller
return string

render() public method

Register this menu tree to WordPress menu
public render ( )

renderByArray() public static method

$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', ), ) ) );
public static renderByArray ( array $menus ) : array
$menus array A key value pairs array with the list of menu
return array

sanitizeViewController() public static method

Return a sanitize view controller for a callable
public static sanitizeViewController ( string | array $view_controller ) : string
$view_controller string | array Callable
return string

url() public static method

Return the compute URL of menu item from view controller name
public static url ( string $view_controller ) : string
$view_controller string Class name of view controller
return string

Property Details

$capability public_oe property

Minumun capabilty require to display this menu
public string $capability
return string

$hookName public_oe property

WorkPress hook name - returned from add_menu_page()
public string $hookName
return string

$icon public_oe property

The url to the icon to be used for this menu.
public string $icon
return string

$id public_oe property

Unique menu ID
public string $id
return string

$menuTitle public_oe property

The top level menu title
public string $menuTitle
return string

$position public_oe property

The position in the menu order this one should appear
public int $position
return integer

$subMenus public_oe property

An array with the sub menus list
public array $subMenus
return array