Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Admin
File: PageController.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* PageController
[2] Fix | Delete
*/
[3] Fix | Delete
[4] Fix | Delete
namespace Automattic\WooCommerce\Admin;
[5] Fix | Delete
[6] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Loader;
[7] Fix | Delete
use Automattic\WooCommerce\Admin\Features\Features;
[8] Fix | Delete
[9] Fix | Delete
use WC_Gateway_BACS;
[10] Fix | Delete
use WC_Gateway_Cheque;
[11] Fix | Delete
use WC_Gateway_COD;
[12] Fix | Delete
use WC_Gateway_Paypal;
[13] Fix | Delete
[14] Fix | Delete
defined( 'ABSPATH' ) || exit;
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* PageController
[18] Fix | Delete
*/
[19] Fix | Delete
class PageController {
[20] Fix | Delete
/**
[21] Fix | Delete
* App entry point.
[22] Fix | Delete
*/
[23] Fix | Delete
const APP_ENTRY_POINT = 'wc-admin';
[24] Fix | Delete
[25] Fix | Delete
// JS-powered page root.
[26] Fix | Delete
const PAGE_ROOT = 'wc-admin';
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* Singleton instance of self.
[30] Fix | Delete
*
[31] Fix | Delete
* @var PageController
[32] Fix | Delete
*/
[33] Fix | Delete
private static $instance = false;
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* Current page ID (or false if not registered with this controller).
[37] Fix | Delete
*
[38] Fix | Delete
* @var string
[39] Fix | Delete
*/
[40] Fix | Delete
private $current_page = null;
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Registered pages
[44] Fix | Delete
* Contains information (breadcrumbs, menu info) about JS powered pages and classic WooCommerce pages.
[45] Fix | Delete
*
[46] Fix | Delete
* @var array
[47] Fix | Delete
*/
[48] Fix | Delete
private $pages = array();
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* We want a single instance of this class so we can accurately track registered menus and pages.
[52] Fix | Delete
*/
[53] Fix | Delete
public static function get_instance() {
[54] Fix | Delete
if ( ! self::$instance ) {
[55] Fix | Delete
self::$instance = new self();
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
return self::$instance;
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* Constructor.
[63] Fix | Delete
* Hooks added here should be removed in `wc_admin_initialize` via the feature plugin.
[64] Fix | Delete
*/
[65] Fix | Delete
public function __construct() {
[66] Fix | Delete
add_action( 'admin_menu', array( $this, 'register_page_handler' ) );
[67] Fix | Delete
add_action( 'admin_menu', array( $this, 'register_store_details_page' ) );
[68] Fix | Delete
[69] Fix | Delete
// priority is 20 to run after https://github.com/woocommerce/woocommerce/blob/a55ae325306fc2179149ba9b97e66f32f84fdd9c/includes/admin/class-wc-admin-menus.php#L165.
[70] Fix | Delete
add_action( 'admin_head', array( $this, 'remove_app_entry_page_menu_item' ), 20 );
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Connect an existing page to wc-admin.
[75] Fix | Delete
*
[76] Fix | Delete
* @param array $options {
[77] Fix | Delete
* Array describing the page.
[78] Fix | Delete
*
[79] Fix | Delete
* @type string id Id to reference the page.
[80] Fix | Delete
* @type string|array title Page title. Used in menus and breadcrumbs.
[81] Fix | Delete
* @type string|null parent Parent ID. Null for new top level page.
[82] Fix | Delete
* @type string path Path for this page. E.g. admin.php?page=wc-settings&tab=checkout
[83] Fix | Delete
* @type string capability Capability needed to access the page.
[84] Fix | Delete
* @type string icon Icon. Dashicons helper class, base64-encoded SVG, or 'none'.
[85] Fix | Delete
* @type int position Menu item position.
[86] Fix | Delete
* @type boolean js_page If this is a JS-powered page.
[87] Fix | Delete
* }
[88] Fix | Delete
*/
[89] Fix | Delete
public function connect_page( $options ) {
[90] Fix | Delete
if ( ! is_array( $options['title'] ) ) {
[91] Fix | Delete
$options['title'] = array( $options['title'] );
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
/**
[95] Fix | Delete
* Filter the options when connecting or registering a page.
[96] Fix | Delete
*
[97] Fix | Delete
* Use the `js_page` option to determine if registering.
[98] Fix | Delete
*
[99] Fix | Delete
* @param array $options {
[100] Fix | Delete
* Array describing the page.
[101] Fix | Delete
*
[102] Fix | Delete
* @type string id Id to reference the page.
[103] Fix | Delete
* @type string|array title Page title. Used in menus and breadcrumbs.
[104] Fix | Delete
* @type string|null parent Parent ID. Null for new top level page.
[105] Fix | Delete
* @type string screen_id The screen ID that represents the connected page. (Not required for registering).
[106] Fix | Delete
* @type string path Path for this page. E.g. admin.php?page=wc-settings&tab=checkout
[107] Fix | Delete
* @type string capability Capability needed to access the page.
[108] Fix | Delete
* @type string icon Icon. Dashicons helper class, base64-encoded SVG, or 'none'.
[109] Fix | Delete
* @type int position Menu item position.
[110] Fix | Delete
* @type boolean js_page If this is a JS-powered page.
[111] Fix | Delete
* }
[112] Fix | Delete
*/
[113] Fix | Delete
$options = apply_filters( 'woocommerce_navigation_connect_page_options', $options );
[114] Fix | Delete
[115] Fix | Delete
// @todo check for null ID, or collision.
[116] Fix | Delete
$this->pages[ $options['id'] ] = $options;
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
/**
[120] Fix | Delete
* Determine the current page ID, if it was registered with this controller.
[121] Fix | Delete
*/
[122] Fix | Delete
public function determine_current_page() {
[123] Fix | Delete
$current_url = '';
[124] Fix | Delete
$current_screen_id = $this->get_current_screen_id();
[125] Fix | Delete
[126] Fix | Delete
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
[127] Fix | Delete
$current_url = esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) );
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
$current_query = wp_parse_url( $current_url, PHP_URL_QUERY );
[131] Fix | Delete
parse_str( (string) $current_query, $current_pieces );
[132] Fix | Delete
$current_path = empty( $current_pieces['page'] ) ? '' : $current_pieces['page'];
[133] Fix | Delete
$current_path .= empty( $current_pieces['path'] ) ? '' : '&path=' . $current_pieces['path'];
[134] Fix | Delete
[135] Fix | Delete
foreach ( $this->pages as $page ) {
[136] Fix | Delete
if ( isset( $page['js_page'] ) && $page['js_page'] ) {
[137] Fix | Delete
// Check registered admin pages.
[138] Fix | Delete
if (
[139] Fix | Delete
$page['path'] === $current_path
[140] Fix | Delete
) {
[141] Fix | Delete
$this->current_page = $page;
[142] Fix | Delete
return;
[143] Fix | Delete
}
[144] Fix | Delete
} else {
[145] Fix | Delete
// Check connected admin pages.
[146] Fix | Delete
if (
[147] Fix | Delete
isset( $page['screen_id'] ) &&
[148] Fix | Delete
$page['screen_id'] === $current_screen_id
[149] Fix | Delete
) {
[150] Fix | Delete
$this->current_page = $page;
[151] Fix | Delete
return;
[152] Fix | Delete
}
[153] Fix | Delete
}
[154] Fix | Delete
}
[155] Fix | Delete
$this->current_page = false;
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
[159] Fix | Delete
/**
[160] Fix | Delete
* Get breadcrumbs for WooCommerce Admin Page navigation.
[161] Fix | Delete
*
[162] Fix | Delete
* @return array Navigation pieces (breadcrumbs).
[163] Fix | Delete
*/
[164] Fix | Delete
public function get_breadcrumbs() {
[165] Fix | Delete
$current_page = $this->get_current_page();
[166] Fix | Delete
[167] Fix | Delete
// Bail if this isn't a page registered with this controller.
[168] Fix | Delete
if ( false === $current_page ) {
[169] Fix | Delete
// Filter documentation below.
[170] Fix | Delete
return apply_filters( 'woocommerce_navigation_get_breadcrumbs', array( '' ), $current_page );
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
$page_title = ! empty( $current_page['page_title'] ) ? $current_page['page_title'] : $current_page['title'];
[174] Fix | Delete
$page_title = (array) $page_title;
[175] Fix | Delete
if ( 1 === count( $page_title ) ) {
[176] Fix | Delete
$breadcrumbs = $page_title;
[177] Fix | Delete
} else {
[178] Fix | Delete
// If this page has multiple title pieces, only link the first one.
[179] Fix | Delete
$breadcrumbs = array_merge(
[180] Fix | Delete
array(
[181] Fix | Delete
array( $current_page['path'], reset( $page_title ) ),
[182] Fix | Delete
),
[183] Fix | Delete
array_slice( $page_title, 1 )
[184] Fix | Delete
);
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
if ( isset( $current_page['parent'] ) ) {
[188] Fix | Delete
$parent_id = $current_page['parent'];
[189] Fix | Delete
[190] Fix | Delete
while ( $parent_id ) {
[191] Fix | Delete
if ( isset( $this->pages[ $parent_id ] ) ) {
[192] Fix | Delete
$parent = $this->pages[ $parent_id ];
[193] Fix | Delete
[194] Fix | Delete
if ( 0 === strpos( $parent['path'], self::PAGE_ROOT ) ) {
[195] Fix | Delete
$parent['path'] = 'admin.php?page=' . $parent['path'];
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
array_unshift( $breadcrumbs, array( $parent['path'], reset( $parent['title'] ) ) );
[199] Fix | Delete
$parent_id = isset( $parent['parent'] ) ? $parent['parent'] : false;
[200] Fix | Delete
} else {
[201] Fix | Delete
$parent_id = false;
[202] Fix | Delete
}
[203] Fix | Delete
}
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
$woocommerce_breadcrumb = array( 'admin.php?page=' . self::PAGE_ROOT, __( 'WooCommerce', 'woocommerce' ) );
[207] Fix | Delete
[208] Fix | Delete
array_unshift( $breadcrumbs, $woocommerce_breadcrumb );
[209] Fix | Delete
[210] Fix | Delete
/**
[211] Fix | Delete
* The navigation breadcrumbs for the current page.
[212] Fix | Delete
*
[213] Fix | Delete
* @param array $breadcrumbs Navigation pieces (breadcrumbs).
[214] Fix | Delete
* @param array|boolean $current_page The connected page data or false if not identified.
[215] Fix | Delete
*/
[216] Fix | Delete
return apply_filters( 'woocommerce_navigation_get_breadcrumbs', $breadcrumbs, $current_page );
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
/**
[220] Fix | Delete
* Get the current page.
[221] Fix | Delete
*
[222] Fix | Delete
* @return array|boolean Current page or false if not registered with this controller.
[223] Fix | Delete
*/
[224] Fix | Delete
public function get_current_page() {
[225] Fix | Delete
// If 'current_screen' hasn't fired yet, the current page calculation
[226] Fix | Delete
// will fail which causes `false` to be returned for all subsequent calls.
[227] Fix | Delete
if ( ! did_action( 'current_screen' ) ) {
[228] Fix | Delete
_doing_it_wrong( __FUNCTION__, esc_html__( 'Current page retrieval should be called on or after the `current_screen` hook.', 'woocommerce' ), '0.16.0' );
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
if ( is_null( $this->current_page ) ) {
[232] Fix | Delete
$this->determine_current_page();
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
return $this->current_page;
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
[239] Fix | Delete
/**
[240] Fix | Delete
* Returns the current screen ID.
[241] Fix | Delete
*
[242] Fix | Delete
* This is slightly different from WP's get_current_screen, in that it attaches an action,
[243] Fix | Delete
* so certain pages like 'add new' pages can have different breadcrumbs or handling.
[244] Fix | Delete
* It also catches some more unique dynamic pages like taxonomy/attribute management.
[245] Fix | Delete
*
[246] Fix | Delete
* Format:
[247] Fix | Delete
* - {$current_screen->action}-{$current_screen->action}-tab-section
[248] Fix | Delete
* - {$current_screen->action}-{$current_screen->action}-tab
[249] Fix | Delete
* - {$current_screen->action}-{$current_screen->action} if no tab is present
[250] Fix | Delete
* - {$current_screen->action} if no action or tab is present
[251] Fix | Delete
*
[252] Fix | Delete
* @return string Current screen ID.
[253] Fix | Delete
*/
[254] Fix | Delete
public function get_current_screen_id() {
[255] Fix | Delete
// Return early if this is a REST API request.
[256] Fix | Delete
if ( wp_is_serving_rest_request() ) {
[257] Fix | Delete
/**
[258] Fix | Delete
* Filter the current screen ID for REST API requests.
[259] Fix | Delete
*
[260] Fix | Delete
* @since 3.9.0
[261] Fix | Delete
*
[262] Fix | Delete
* @param string|boolean $screen_id The screen id or false if not identified.
[263] Fix | Delete
* @param WP_Screen $current_screen The current WP_Screen.
[264] Fix | Delete
*/
[265] Fix | Delete
return apply_filters( 'woocommerce_navigation_current_screen_id', false, null );
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
$current_screen = get_current_screen();
[269] Fix | Delete
if ( ! $current_screen ) {
[270] Fix | Delete
// Filter documentation below.
[271] Fix | Delete
return apply_filters( 'woocommerce_navigation_current_screen_id', false, $current_screen );
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
$screen_pieces = array( $current_screen->id );
[275] Fix | Delete
[276] Fix | Delete
if ( $current_screen->action ) {
[277] Fix | Delete
$screen_pieces[] = $current_screen->action;
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
if (
[281] Fix | Delete
! empty( $current_screen->taxonomy ) &&
[282] Fix | Delete
isset( $current_screen->post_type ) &&
[283] Fix | Delete
'product' === $current_screen->post_type
[284] Fix | Delete
) {
[285] Fix | Delete
// Editing a product attribute.
[286] Fix | Delete
if ( 0 === strpos( $current_screen->taxonomy, 'pa_' ) ) {
[287] Fix | Delete
$screen_pieces = array( 'product_page_product_attribute-edit' );
[288] Fix | Delete
}
[289] Fix | Delete
[290] Fix | Delete
// Editing a product taxonomy term.
[291] Fix | Delete
if ( ! empty( $_GET['tag_ID'] ) ) {
[292] Fix | Delete
$screen_pieces = array( $current_screen->taxonomy );
[293] Fix | Delete
}
[294] Fix | Delete
}
[295] Fix | Delete
[296] Fix | Delete
// Pages with default tab values.
[297] Fix | Delete
$pages_with_tabs = apply_filters(
[298] Fix | Delete
'woocommerce_navigation_pages_with_tabs',
[299] Fix | Delete
array(
[300] Fix | Delete
'wc-reports' => 'orders',
[301] Fix | Delete
'wc-settings' => 'general',
[302] Fix | Delete
'wc-status' => 'status',
[303] Fix | Delete
'wc-addons' => 'browse-extensions',
[304] Fix | Delete
)
[305] Fix | Delete
);
[306] Fix | Delete
[307] Fix | Delete
// Tabs that have sections as well.
[308] Fix | Delete
$wc_emails = \WC_Emails::instance();
[309] Fix | Delete
$wc_email_ids = array_map( 'sanitize_title', array_keys( $wc_emails->get_emails() ) );
[310] Fix | Delete
[311] Fix | Delete
$tabs_with_sections = apply_filters(
[312] Fix | Delete
'woocommerce_navigation_page_tab_sections',
[313] Fix | Delete
array(
[314] Fix | Delete
'products' => array( '', 'inventory', 'downloadable', 'download_urls', 'advanced' ),
[315] Fix | Delete
'shipping' => array( '', 'options', 'classes', 'pickup_location' ),
[316] Fix | Delete
'checkout' => array( WC_Gateway_BACS::ID, WC_Gateway_Cheque::ID, WC_Gateway_COD::ID, WC_Gateway_Paypal::ID ),
[317] Fix | Delete
'email' => $wc_email_ids,
[318] Fix | Delete
'advanced' => array(
[319] Fix | Delete
'',
[320] Fix | Delete
'keys',
[321] Fix | Delete
'webhooks',
[322] Fix | Delete
'legacy_api',
[323] Fix | Delete
'woocommerce_com',
[324] Fix | Delete
'features',
[325] Fix | Delete
'blueprint',
[326] Fix | Delete
),
[327] Fix | Delete
'browse-extensions' => array( 'helper' ),
[328] Fix | Delete
)
[329] Fix | Delete
);
[330] Fix | Delete
[331] Fix | Delete
if ( ! empty( $_GET['page'] ) ) {
[332] Fix | Delete
$page = wc_clean( wp_unslash( $_GET['page'] ) );
[333] Fix | Delete
if ( in_array( $page, array_keys( $pages_with_tabs ) ) ) {
[334] Fix | Delete
if ( ! empty( $_GET['tab'] ) ) {
[335] Fix | Delete
$tab = wc_clean( wp_unslash( $_GET['tab'] ) );
[336] Fix | Delete
} else {
[337] Fix | Delete
$tab = $pages_with_tabs[ $page ];
[338] Fix | Delete
}
[339] Fix | Delete
[340] Fix | Delete
$screen_pieces[] = $tab;
[341] Fix | Delete
[342] Fix | Delete
if ( ! empty( $_GET['section'] ) ) {
[343] Fix | Delete
$section = wc_clean( wp_unslash( $_GET['section'] ) );
[344] Fix | Delete
if (
[345] Fix | Delete
isset( $tabs_with_sections[ $tab ] ) &&
[346] Fix | Delete
in_array( $section, array_values( $tabs_with_sections[ $tab ] ), true )
[347] Fix | Delete
) {
[348] Fix | Delete
$screen_pieces[] = $section;
[349] Fix | Delete
}
[350] Fix | Delete
}
[351] Fix | Delete
[352] Fix | Delete
// Editing a shipping zone.
[353] Fix | Delete
if ( ( 'shipping' === $tab ) && isset( $_GET['zone_id'] ) ) {
[354] Fix | Delete
$screen_pieces[] = 'edit_zone';
[355] Fix | Delete
}
[356] Fix | Delete
}
[357] Fix | Delete
}
[358] Fix | Delete
[359] Fix | Delete
/**
[360] Fix | Delete
* The current screen id.
[361] Fix | Delete
*
[362] Fix | Delete
* Used for identifying pages to render the WooCommerce Admin header.
[363] Fix | Delete
*
[364] Fix | Delete
* @param string|boolean $screen_id The screen id or false if not identified.
[365] Fix | Delete
* @param WP_Screen $current_screen The current WP_Screen.
[366] Fix | Delete
*/
[367] Fix | Delete
return apply_filters( 'woocommerce_navigation_current_screen_id', implode( '-', $screen_pieces ), $current_screen );
[368] Fix | Delete
}
[369] Fix | Delete
[370] Fix | Delete
/**
[371] Fix | Delete
* Returns the path from an ID.
[372] Fix | Delete
*
[373] Fix | Delete
* @param string $id ID to get path for.
[374] Fix | Delete
* @return string Path for the given ID, or the ID on lookup miss.
[375] Fix | Delete
*/
[376] Fix | Delete
public function get_path_from_id( $id ) {
[377] Fix | Delete
if ( isset( $this->pages[ $id ] ) && isset( $this->pages[ $id ]['path'] ) ) {
[378] Fix | Delete
return $this->pages[ $id ]['path'];
[379] Fix | Delete
}
[380] Fix | Delete
return $id;
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
/**
[384] Fix | Delete
* Returns true if we are on a page connected to this controller.
[385] Fix | Delete
*
[386] Fix | Delete
* @return boolean
[387] Fix | Delete
*/
[388] Fix | Delete
public function is_connected_page() {
[389] Fix | Delete
$current_page = $this->get_current_page();
[390] Fix | Delete
[391] Fix | Delete
if ( false === $current_page ) {
[392] Fix | Delete
$is_connected_page = false;
[393] Fix | Delete
} else {
[394] Fix | Delete
$is_connected_page = isset( $current_page['js_page'] ) ? ! $current_page['js_page'] : true;
[395] Fix | Delete
}
[396] Fix | Delete
[397] Fix | Delete
// Disable embed on the block editor.
[398] Fix | Delete
$current_screen = did_action( 'current_screen' ) ? get_current_screen() : false;
[399] Fix | Delete
if ( ! empty( $current_screen ) && method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
[400] Fix | Delete
$is_connected_page = false;
[401] Fix | Delete
}
[402] Fix | Delete
[403] Fix | Delete
/**
[404] Fix | Delete
* Whether or not the current page is an existing page connected to this controller.
[405] Fix | Delete
*
[406] Fix | Delete
* Used to determine if the WooCommerce Admin header should be rendered.
[407] Fix | Delete
*
[408] Fix | Delete
* @param boolean $is_connected_page True if the current page is connected.
[409] Fix | Delete
* @param array|boolean $current_page The connected page data or false if not identified.
[410] Fix | Delete
*/
[411] Fix | Delete
return apply_filters( 'woocommerce_navigation_is_connected_page', $is_connected_page, $current_page );
[412] Fix | Delete
}
[413] Fix | Delete
[414] Fix | Delete
/**
[415] Fix | Delete
* Returns true if we are on a page registered with this controller.
[416] Fix | Delete
*
[417] Fix | Delete
* @return boolean
[418] Fix | Delete
*/
[419] Fix | Delete
public function is_registered_page() {
[420] Fix | Delete
$current_page = $this->get_current_page();
[421] Fix | Delete
[422] Fix | Delete
if ( false === $current_page ) {
[423] Fix | Delete
$is_registered_page = false;
[424] Fix | Delete
} else {
[425] Fix | Delete
$is_registered_page = isset( $current_page['js_page'] ) && $current_page['js_page'];
[426] Fix | Delete
}
[427] Fix | Delete
[428] Fix | Delete
/**
[429] Fix | Delete
* Whether or not the current page was registered with this controller.
[430] Fix | Delete
*
[431] Fix | Delete
* Used to determine if this is a JS-powered WooCommerce Admin page.
[432] Fix | Delete
*
[433] Fix | Delete
* @param boolean $is_registered_page True if the current page was registered with this controller.
[434] Fix | Delete
* @param array|boolean $current_page The registered page data or false if not identified.
[435] Fix | Delete
*/
[436] Fix | Delete
return apply_filters( 'woocommerce_navigation_is_registered_page', $is_registered_page, $current_page );
[437] Fix | Delete
}
[438] Fix | Delete
[439] Fix | Delete
/**
[440] Fix | Delete
* Adds a JS powered page to wc-admin.
[441] Fix | Delete
*
[442] Fix | Delete
* @param array $options {
[443] Fix | Delete
* Array describing the page.
[444] Fix | Delete
*
[445] Fix | Delete
* @type string id Id to reference the page.
[446] Fix | Delete
* @type string title Page title. Used in menus and breadcrumbs.
[447] Fix | Delete
* @type string|null parent Parent ID. Null for new top level page.
[448] Fix | Delete
* @type string path Path for this page, full path in app context; ex /analytics/report
[449] Fix | Delete
* @type string capability Capability needed to access the page.
[450] Fix | Delete
* @type string icon Icon. Dashicons helper class, base64-encoded SVG, or 'none'.
[451] Fix | Delete
* @type int position Menu item position.
[452] Fix | Delete
* @type int order Navigation item order.
[453] Fix | Delete
* }
[454] Fix | Delete
*/
[455] Fix | Delete
public function register_page( $options ) {
[456] Fix | Delete
$defaults = array(
[457] Fix | Delete
'id' => null,
[458] Fix | Delete
'parent' => null,
[459] Fix | Delete
'title' => '',
[460] Fix | Delete
'page_title' => '',
[461] Fix | Delete
'capability' => 'view_woocommerce_reports',
[462] Fix | Delete
'path' => '',
[463] Fix | Delete
'icon' => '',
[464] Fix | Delete
'position' => null,
[465] Fix | Delete
'js_page' => true,
[466] Fix | Delete
);
[467] Fix | Delete
[468] Fix | Delete
$options = wp_parse_args( $options, $defaults );
[469] Fix | Delete
[470] Fix | Delete
if ( 0 !== strpos( $options['path'], self::PAGE_ROOT ) ) {
[471] Fix | Delete
$options['path'] = self::PAGE_ROOT . '&path=' . $options['path'];
[472] Fix | Delete
}
[473] Fix | Delete
[474] Fix | Delete
if ( null !== $options['position'] ) {
[475] Fix | Delete
$options['position'] = intval( round( $options['position'] ) );
[476] Fix | Delete
}
[477] Fix | Delete
[478] Fix | Delete
if ( empty( $options['page_title'] ) ) {
[479] Fix | Delete
$options['page_title'] = $options['title'];
[480] Fix | Delete
}
[481] Fix | Delete
[482] Fix | Delete
if ( is_null( $options['parent'] ) ) {
[483] Fix | Delete
add_menu_page(
[484] Fix | Delete
$options['page_title'],
[485] Fix | Delete
$options['title'],
[486] Fix | Delete
$options['capability'],
[487] Fix | Delete
$options['path'],
[488] Fix | Delete
array( __CLASS__, 'page_wrapper' ),
[489] Fix | Delete
$options['icon'],
[490] Fix | Delete
$options['position']
[491] Fix | Delete
);
[492] Fix | Delete
} else {
[493] Fix | Delete
$parent_path = $this->get_path_from_id( $options['parent'] );
[494] Fix | Delete
// @todo check for null path.
[495] Fix | Delete
add_submenu_page(
[496] Fix | Delete
$parent_path,
[497] Fix | Delete
$options['page_title'],
[498] Fix | Delete
$options['title'],
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function