PHP Класс 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
Автор: =undo= ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$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

Открытые методы

Метод Описание
__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

Описание методов

__construct() публичный Метод

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
Результат WPDKMenu

addDivider() публичный Метод

Add a special submenu as separator
public addDivider ( string $title = '' ) : WPDKSubMenu
$title string
Результат WPDKSubMenu

addSubMenu() публичный Метод

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
Результат WPDKSubMenu

addSubMenuAt() публичный статический Метод

### 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).
Результат array

addSubMenusAt() публичный статический Метод

$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 );
С версии: 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).
Результат mixed

hook() публичный статический Метод

Return the hook id for a view controller
С версии: 1.2.0
public static hook ( string $view_controller ) : string
$view_controller string Class name of view controller
Результат string

isPageWithMenu() публичный статический Метод

Return TRUE if the displayed page is the view controller
С версии: 1.2.0
public static isPageWithMenu ( string $id ) : boolean
$id string The menu id
Результат boolean

menu() публичный статический Метод

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
Результат array

page() публичный статический Метод

Return the page id for a view controller
С версии: 1.2.0
public static page ( string $view_controller ) : string
$view_controller string Class name of view controller
Результат string

render() публичный Метод

Register this menu tree to WordPress menu
public render ( )

renderByArray() публичный статический Метод

$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
Результат array

sanitizeViewController() публичный статический Метод

Return a sanitize view controller for a callable
public static sanitizeViewController ( string | array $view_controller ) : string
$view_controller string | array Callable
Результат string

url() публичный статический Метод

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
Результат string

Описание свойств

$capability публичное свойство

Minumun capabilty require to display this menu
public string $capability
Результат string

$hookName публичное свойство

WorkPress hook name - returned from add_menu_page()
public string $hookName
Результат string

$icon публичное свойство

The url to the icon to be used for this menu.
public string $icon
Результат string

$id публичное свойство

Unique menu ID
public string $id
Результат string

$menuTitle публичное свойство

The top level menu title
public string $menuTitle
Результат string

$position публичное свойство

The position in the menu order this one should appear
public int $position
Результат integer

$subMenus публичное свойство

An array with the sub menus list
public array $subMenus
Результат array