WooCommerce Code Reference

PageController
in package

PageController

Table of Contents

APP_ENTRY_POINT  = 'wc-admin'
App entry point.
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.
__construct()  : mixed
Constructor.
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_admin_or_embed_page()  : mixed
Returns true if we are on a JS powered admin page or a "classic" (non JS app) powered admin page (an embedded page).
is_admin_page()  : mixed
Returns true if we are on a JS powered admin page.
is_connected_page()  : bool
Returns true if we are on a page connected to this controller.
is_embed_page()  : mixed
Returns true if we are on a "classic" (non JS app) powered admin page.
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.
register_page_handler()  : mixed
Connects existing WooCommerce pages.
register_store_details_page()  : mixed
Registers the store details (profiler) page.
remove_app_entry_page_menu_item()  : mixed
Remove the menu item for the app entry point page.

Constants

Properties

$current_page

Current page ID (or false if not registered with this controller).

private string $current_page = null

$pages

Registered pages Contains information (breadcrumbs, menu info) about JS powered pages and classic WooCommerce pages.

private array<string|int, mixed> $pages = array()

Methods

__construct()

Constructor.

public __construct() : mixed

Hooks added here should be removed in wc_admin_initialize via the feature plugin.

Return values
mixed

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

determine_current_page()

Determine the current page ID, if it was registered with this controller.

public determine_current_page() : mixed
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_instance()

We want a single instance of this class so we can accurately track registered menus and pages.

public static get_instance() : mixed
Return values
mixed

get_pages()

Get registered pages.

public get_pages() : array<string|int, mixed>
Return values
array<string|int, mixed>

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.

is_admin_or_embed_page()

Returns true if we are on a JS powered admin page or a "classic" (non JS app) powered admin page (an embedded page).

public static is_admin_or_embed_page() : mixed
Return values
mixed

is_admin_page()

Returns true if we are on a JS powered admin page.

public static is_admin_page() : mixed
Return values
mixed

is_connected_page()

Returns true if we are on a page connected to this controller.

public is_connected_page() : bool
Return values
bool

is_embed_page()

Returns true if we are on a "classic" (non JS app) powered admin page.

public static is_embed_page() : mixed

TODO: See usage in admin.php. This needs refactored and implemented properly in core.

Return values
mixed

is_registered_page()

Returns true if we are on a page registed with this controller.

public is_registered_page() : bool
Return values
bool

page_wrapper()

Set up a div for the app to render into.

public static page_wrapper() : mixed
Return values
mixed

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

register_page_handler()

Connects existing WooCommerce pages.

public register_page_handler() : mixed
Tags
todo

The entry point for the embed needs moved to this class as well.

Return values
mixed

register_store_details_page()

Registers the store details (profiler) page.

public register_store_details_page() : mixed
Return values
mixed

remove_app_entry_page_menu_item()

Remove the menu item for the app entry point page.

public remove_app_entry_page_menu_item() : mixed
Return values
mixed