Automattic\WooCommerce\Admin
PageController::register_page()
Adds a JS powered page to wc-admin.
Method of the class: PageController{}
No Hooks.
Return
null
. Nothing (null).
Usage
$PageController = new PageController(); $PageController->register_page( $options );
- $options(array) (required)
Array describing the page.
-
id(string)
Id to reference the page. -
title(string)
Page title. Used in menus and breadcrumbs. -
parent(string|null)
Parent ID. Null for new top level page. -
path(string)
Path for this page, full path in app context; ex /analytics/report -
capability(string)
Capability needed to access the page. -
icon(string)
Icon. Dashicons helper class, base64-encoded SVG, or 'none'. -
position(int)
Menu item position. - order(int)
Navigation item order.
-
PageController::register_page() PageController::register page code WC 9.7.1
public function register_page( $options ) { $defaults = array( 'id' => null, 'parent' => null, 'title' => '', 'page_title' => '', 'capability' => 'view_woocommerce_reports', 'path' => '', 'icon' => '', 'position' => null, 'js_page' => true, ); $options = wp_parse_args( $options, $defaults ); if ( 0 !== strpos( $options['path'], self::PAGE_ROOT ) ) { $options['path'] = self::PAGE_ROOT . '&path=' . $options['path']; } if ( null !== $options['position'] ) { $options['position'] = intval( round( $options['position'] ) ); } if ( empty( $options['page_title'] ) ) { $options['page_title'] = $options['title']; } if ( is_null( $options['parent'] ) ) { add_menu_page( $options['page_title'], $options['title'], $options['capability'], $options['path'], array( __CLASS__, 'page_wrapper' ), $options['icon'], $options['position'] ); } else { $parent_path = $this->get_path_from_id( $options['parent'] ); // @todo check for null path. add_submenu_page( $parent_path, $options['page_title'], $options['title'], $options['capability'], $options['path'], array( __CLASS__, 'page_wrapper' ) ); } $this->connect_page( $options ); }