WooCommerce Code Reference

PageController
in package

PageController

Table of Contents

PAGE_ROOT  = 'wc-admin'
$current_page  : string
Current page ID (or false if not registered with this controller).
$instance  : PageController
Singleton instance of self.
$pages  : array<string|int, mixed>
Registered pages Contains information (breadcrumbs, menu info) about JS powered pages and classic WooCommerce pages.
connect_page()  : mixed
Connect an existing page to wc-admin.
determine_current_page()  : mixed
Determine the current page ID, if it was registered with this controller.
get_breadcrumbs()  : array<string|int, mixed>
Get breadcrumbs for WooCommerce Admin Page navigation.
get_current_page()  : array<string|int, mixed>|bool
Get the current page.
get_current_screen_id()  : string
Returns the current screen ID.
get_instance()  : mixed
We want a single instance of this class so we can accurately track registered menus and pages.
get_pages()  : array<string|int, mixed>
Get registered pages.
get_path_from_id()  : string
Returns the path from an ID.
is_connected_page()  : bool
Returns true if we are on a page connected to this controller.
is_registered_page()  : bool
Returns true if we are on a page registed with this controller.
page_wrapper()  : mixed
Set up a div for the app to render into.
register_page()  : mixed
Adds a JS powered page to wc-admin.

Constants

Properties

Methods

connect_page()

Connect an existing page to wc-admin.

public connect_page(array<string|int, mixed> $options) : mixed
Parameters
$options : array<string|int, mixed>

{ Array describing the page.

@type string id Id to reference the page. @type string|array title Page title. Used in menus and breadcrumbs. @type string|null parent Parent ID. Null for new top level page. @type string path Path for this page. E.g. admin.php?page=wc-settings&tab=checkout @type string capability Capability needed to access the page. @type string icon Icon. Dashicons helper class, base64-encoded SVG, or 'none'. @type int position Menu item position. @type boolean js_page If this is a JS-powered page. }

Return values
mixed

get_breadcrumbs()

Get breadcrumbs for WooCommerce Admin Page navigation.

public get_breadcrumbs() : array<string|int, mixed>
Return values
array<string|int, mixed>Navigation pieces (breadcrumbs).

get_current_page()

Get the current page.

public get_current_page() : array<string|int, mixed>|bool
Return values
array<string|int, mixed>|boolCurrent page or false if not registered with this controller.

get_current_screen_id()

Returns the current screen ID.

public get_current_screen_id() : string

This is slightly different from WP's get_current_screen, in that it attaches an action, so certain pages like 'add new' pages can have different breadcrumbs or handling. It also catches some more unique dynamic pages like taxonomy/attribute management.

Format:

  • {$current_screen->action}-{$current_screen->action}-tab-section
  • {$current_screen->action}-{$current_screen->action}-tab
  • {$current_screen->action}-{$current_screen->action} if no tab is present
  • {$current_screen->action} if no action or tab is present
Return values
stringCurrent screen ID.

get_path_from_id()

Returns the path from an ID.

public get_path_from_id(string $id) : string
Parameters
$id : string

ID to get path for.

Return values
stringPath for the given ID, or the ID on lookup miss.

register_page()

Adds a JS powered page to wc-admin.

public register_page(array<string|int, mixed> $options) : mixed
Parameters
$options : array<string|int, mixed>

{ Array describing the page.

@type string id Id to reference the page. @type string title Page title. Used in menus and breadcrumbs. @type string|null parent Parent ID. Null for new top level page. @type string path Path for this page, full path in app context; ex /analytics/report @type string capability Capability needed to access the page. @type string icon Icon. Dashicons helper class, base64-encoded SVG, or 'none'. @type int position Menu item position. @type int order Navigation item order. }

Return values
mixed