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])
Afficher le fichier Open project: wpxtreme/wpdk Class Usage Examples

Méthodes publiques

Свойство 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

Méthodes publiques

Méthode 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 méthode

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
Résultat WPDKMenu

addDivider() public méthode

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

addSubMenu() public méthode

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
Résultat WPDKSubMenu

addSubMenuAt() public static méthode

### 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).
Résultat array

addSubMenusAt() public static méthode

$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).
Résultat mixed

hook() public static méthode

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
Résultat string

isPageWithMenu() public static méthode

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
Résultat boolean

menu() public static méthode

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
Résultat array

page() public static méthode

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
Résultat string

render() public méthode

Register this menu tree to WordPress menu
public render ( )

renderByArray() public static méthode

$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
Résultat array

sanitizeViewController() public static méthode

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

url() public static méthode

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
Résultat string

Property Details

$capability public_oe property

Minumun capabilty require to display this menu
public string $capability
Résultat string

$hookName public_oe property

WorkPress hook name - returned from add_menu_page()
public string $hookName
Résultat string

$icon public_oe property

The url to the icon to be used for this menu.
public string $icon
Résultat string

$id public_oe property

Unique menu ID
public string $id
Résultat string

$menuTitle public_oe property

The top level menu title
public string $menuTitle
Résultat string

$position public_oe property

The position in the menu order this one should appear
public int $position
Résultat integer

$subMenus public_oe property

An array with the sub menus list
public array $subMenus
Résultat array