2018-04-17 23:51:48 +00:00
|
|
|
<?php
|
2018-10-23 15:55:37 +00:00
|
|
|
/**
|
|
|
|
* Common lib functions
|
|
|
|
*
|
|
|
|
* @package WooCommerce Admin
|
|
|
|
*/
|
|
|
|
|
2018-04-17 23:51:48 +00:00
|
|
|
/**
|
|
|
|
* Retrieves the root plugin path.
|
|
|
|
*
|
2018-05-07 13:38:13 +00:00
|
|
|
* @param string $file Optional relative path of the desired file.
|
|
|
|
*
|
2018-04-17 23:51:48 +00:00
|
|
|
* @return string Root path to the gutenberg custom fields plugin.
|
|
|
|
*/
|
2018-07-10 12:48:06 +00:00
|
|
|
function wc_admin_dir_path( $file = '' ) {
|
2018-10-22 16:20:14 +00:00
|
|
|
return plugin_dir_path( dirname( __FILE__ ) ) . $file;
|
2018-04-17 23:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves a URL to a file in the gutenberg custom fields plugin.
|
|
|
|
*
|
|
|
|
* @param string $path Relative path of the desired file.
|
|
|
|
*
|
|
|
|
* @return string Fully qualified URL pointing to the desired file.
|
|
|
|
*/
|
2018-07-10 12:48:06 +00:00
|
|
|
function wc_admin_url( $path ) {
|
2018-04-17 23:51:48 +00:00
|
|
|
return plugins_url( $path, dirname( __FILE__ ) );
|
|
|
|
}
|
2018-06-26 14:49:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current screen ID.
|
|
|
|
* 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}, or just {$current_screen->action} if no action is found
|
|
|
|
*
|
|
|
|
* @return string Current screen ID.
|
|
|
|
*/
|
2018-07-10 12:48:06 +00:00
|
|
|
function wc_admin_get_current_screen_id() {
|
|
|
|
$current_screen = get_current_screen();
|
2018-06-26 14:49:42 +00:00
|
|
|
if ( ! $current_screen ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$current_screen_id = $current_screen->action ? $current_screen->action . '-' . $current_screen->id : $current_screen->id;
|
|
|
|
|
2018-10-22 16:20:14 +00:00
|
|
|
if ( ! empty( $_GET['taxonomy'] ) && ! empty( $_GET['post_type'] ) && 'product' === $_GET['post_type'] ) {
|
2018-06-26 14:49:42 +00:00
|
|
|
$current_screen_id = 'product_page_product_attributes';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $current_screen_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns breadcrumbs for the current page.
|
|
|
|
*
|
|
|
|
* TODO When merging to core, we should explore a better API for defining breadcrumbs, instead of just defining an array.
|
|
|
|
*/
|
2018-07-10 12:48:06 +00:00
|
|
|
function wc_admin_get_embed_breadcrumbs() {
|
|
|
|
$current_screen_id = wc_admin_get_current_screen_id();
|
2018-06-26 14:49:42 +00:00
|
|
|
|
2018-10-23 15:55:37 +00:00
|
|
|
// If a page has a tab, we can append that to the screen ID and show another pagination level.
|
2018-06-26 14:49:42 +00:00
|
|
|
$pages_with_tabs = array(
|
|
|
|
'wc-reports' => 'orders',
|
|
|
|
'wc-settings' => 'general',
|
|
|
|
'wc-status' => 'status',
|
|
|
|
);
|
2018-10-23 23:12:49 +00:00
|
|
|
$tab = '';
|
2018-11-13 19:08:01 +00:00
|
|
|
$get_tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : '';
|
2018-10-23 23:12:49 +00:00
|
|
|
if ( isset( $_GET['page'] ) ) {
|
2018-11-13 19:08:01 +00:00
|
|
|
$page = sanitize_text_field( wp_unslash( $_GET['page'] ) );
|
|
|
|
if ( in_array( $page, array_keys( $pages_with_tabs ) ) ) {
|
|
|
|
$tab = ! empty( $get_tab ) ? $get_tab . '-' : $pages_with_tabs[ $page ] . '-';
|
2018-06-26 14:49:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-22 16:20:14 +00:00
|
|
|
$breadcrumbs = apply_filters(
|
|
|
|
'wc_admin_get_breadcrumbs',
|
|
|
|
array(
|
|
|
|
'edit-shop_order' => __( 'Orders', 'wc-admin' ),
|
|
|
|
'add-shop_order' => array(
|
|
|
|
array( '/edit.php?post_type=shop_order', __( 'Orders', 'wc-admin' ) ),
|
|
|
|
__( 'Add New', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'shop_order' => array(
|
|
|
|
array( '/edit.php?post_type=shop_order', __( 'Orders', 'wc-admin' ) ),
|
|
|
|
__( 'Edit Order', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'edit-shop_coupon' => __( 'Coupons', 'wc-admin' ),
|
|
|
|
'add-shop_coupon' => array(
|
|
|
|
array( 'edit.php?post_type=shop_coupon', __( 'Coupons', 'wc-admin' ) ),
|
|
|
|
__( 'Add New', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'shop_coupon' => array(
|
|
|
|
array( 'edit.php?post_type=shop_coupon', __( 'Coupons', 'wc-admin' ) ),
|
|
|
|
__( 'Edit Coupon', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'woocommerce_page_wc-reports' => array(
|
|
|
|
array( 'admin.php?page=wc-reports', __( 'Reports', 'wc-admin' ) ),
|
|
|
|
),
|
|
|
|
'orders-woocommerce_page_wc-reports' => array(
|
|
|
|
array( 'admin.php?page=wc-reports', __( 'Reports', 'wc-admin' ) ),
|
|
|
|
__( 'Orders', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'customers-woocommerce_page_wc-reports' => array(
|
|
|
|
array( 'admin.php?page=wc-reports', __( 'Reports', 'wc-admin' ) ),
|
|
|
|
__( 'Customers', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'stock-woocommerce_page_wc-reports' => array(
|
|
|
|
array( 'admin.php?page=wc-reports', __( 'Reports', 'wc-admin' ) ),
|
|
|
|
__( 'Stock', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'taxes-woocommerce_page_wc-reports' => array(
|
|
|
|
array( 'admin.php?page=wc-reports', __( 'Reports', 'wc-admin' ) ),
|
|
|
|
__( 'Taxes', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'woocommerce_page_wc-settings' => array(
|
|
|
|
array( 'admin.php?page=wc-settings', __( 'Settings', 'wc-admin' ) ),
|
|
|
|
),
|
|
|
|
'general-woocommerce_page_wc-settings' => array(
|
|
|
|
array( 'admin.php?page=wc-settings', __( 'Settings', 'wc-admin' ) ),
|
|
|
|
__( 'General', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'products-woocommerce_page_wc-settings' => array(
|
|
|
|
array( 'admin.php?page=wc-settings', __( 'Settings', 'wc-admin' ) ),
|
|
|
|
__( 'Products', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'tax-woocommerce_page_wc-settings' => array(
|
|
|
|
array( 'admin.php?page=wc-settings', __( 'Settings', 'wc-admin' ) ),
|
|
|
|
__( 'Tax', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'shipping-woocommerce_page_wc-settings' => array(
|
|
|
|
array( 'admin.php?page=wc-settings', __( 'Settings', 'wc-admin' ) ),
|
|
|
|
__( 'Shipping', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'checkout-woocommerce_page_wc-settings' => array(
|
|
|
|
array( 'admin.php?page=wc-settings', __( 'Settings', 'wc-admin' ) ),
|
|
|
|
__( 'Payments', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'email-woocommerce_page_wc-settings' => array(
|
|
|
|
array( 'admin.php?page=wc-settings', __( 'Settings', 'wc-admin' ) ),
|
|
|
|
__( 'Emails', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'advanced-woocommerce_page_wc-settings' => array(
|
|
|
|
array( 'admin.php?page=wc-settings', __( 'Settings', 'wc-admin' ) ),
|
|
|
|
__( 'Advanced', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'woocommerce_page_wc-status' => array(
|
|
|
|
__( 'Status', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'status-woocommerce_page_wc-status' => array(
|
|
|
|
array( 'admin.php?page=wc-status', __( 'Status', 'wc-admin' ) ),
|
|
|
|
__( 'System Status', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'tools-woocommerce_page_wc-status' => array(
|
|
|
|
array( 'admin.php?page=wc-status', __( 'Status', 'wc-admin' ) ),
|
|
|
|
__( 'Tools', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'logs-woocommerce_page_wc-status' => array(
|
|
|
|
array( 'admin.php?page=wc-status', __( 'Status', 'wc-admin' ) ),
|
|
|
|
__( 'Logs', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'connect-woocommerce_page_wc-status' => array(
|
|
|
|
array( 'admin.php?page=wc-status', __( 'Status', 'wc-admin' ) ),
|
|
|
|
__( 'WooCommerce Services Status', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'woocommerce_page_wc-addons' => __( 'Extensions', 'wc-admin' ),
|
|
|
|
'edit-product' => __( 'Products', 'wc-admin' ),
|
|
|
|
'product_page_product_importer' => array(
|
|
|
|
array( 'edit.php?post_type=product', __( 'Products', 'wc-admin' ) ),
|
|
|
|
__( 'Import', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'product_page_product_exporter' => array(
|
|
|
|
array( 'edit.php?post_type=product', __( 'Products', 'wc-admin' ) ),
|
|
|
|
__( 'Export', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'add-product' => array(
|
|
|
|
array( 'edit.php?post_type=product', __( 'Products', 'wc-admin' ) ),
|
|
|
|
__( 'Add New', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'product' => array(
|
|
|
|
array( 'edit.php?post_type=product', __( 'Products', 'wc-admin' ) ),
|
|
|
|
__( 'Edit Product', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'edit-product_cat' => array(
|
|
|
|
array( 'edit.php?post_type=product', __( 'Products', 'wc-admin' ) ),
|
|
|
|
__( 'Categories', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'edit-product_tag' => array(
|
|
|
|
array( 'edit.php?post_type=product', __( 'Products', 'wc-admin' ) ),
|
|
|
|
__( 'Tags', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
'product_page_product_attributes' => array(
|
|
|
|
array( 'edit.php?post_type=product', __( 'Products', 'wc-admin' ) ),
|
|
|
|
__( 'Attributes', 'wc-admin' ),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
2018-06-26 14:49:42 +00:00
|
|
|
|
2018-10-22 16:20:14 +00:00
|
|
|
if ( ! empty( $breadcrumbs[ $tab . $current_screen_id ] ) ) {
|
2018-06-26 14:49:42 +00:00
|
|
|
return $breadcrumbs[ $tab . $current_screen_id ];
|
2018-10-22 16:20:14 +00:00
|
|
|
} elseif ( ! empty( $breadcrumbs[ $current_screen_id ] ) ) {
|
2018-06-26 14:49:42 +00:00
|
|
|
return $breadcrumbs[ $current_screen_id ];
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-22 16:20:14 +00:00
|
|
|
* `wc_admin_get_embed_enabled_screen_ids`, `wc_admin_get_embed_enabled_plugin_screen_ids`,
|
|
|
|
* `wc_admin_get_embed_enabled_screen_ids` should be considered temporary functions for the feature plugin.
|
|
|
|
* This is separate from WC's screen_id functions so that extensions explictly have to opt-in to the feature plugin.
|
|
|
|
* TODO When merging to core, we should explore a better API for opting into the new header for extensions.
|
2018-06-26 14:49:42 +00:00
|
|
|
*/
|
2018-07-10 12:48:06 +00:00
|
|
|
function wc_admin_get_embed_enabled_core_screen_ids() {
|
2018-06-26 14:49:42 +00:00
|
|
|
$screens = array(
|
|
|
|
'edit-shop_order',
|
|
|
|
'shop_order',
|
|
|
|
'add-shop_order',
|
|
|
|
'edit-shop_coupon',
|
|
|
|
'shop_coupon',
|
|
|
|
'add-shop_coupon',
|
|
|
|
'woocommerce_page_wc-reports',
|
|
|
|
'woocommerce_page_wc-settings',
|
|
|
|
'woocommerce_page_wc-status',
|
|
|
|
'woocommerce_page_wc-addons',
|
|
|
|
'edit-product',
|
|
|
|
'product_page_product_importer',
|
|
|
|
'product_page_product_exporter',
|
|
|
|
'add-product',
|
|
|
|
'product',
|
|
|
|
'edit-product_cat',
|
|
|
|
'edit-product_tag',
|
|
|
|
'product_page_product_attributes',
|
|
|
|
);
|
2018-07-10 12:48:06 +00:00
|
|
|
return apply_filters( 'wc_admin_get_embed_enabled_core_screens_ids', $screens );
|
2018-06-26 14:49:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If any extensions want to show the new header, they can register their screen ids.
|
|
|
|
* Separate so extensions can register support for the feature plugin separately.
|
|
|
|
*/
|
2018-07-10 12:48:06 +00:00
|
|
|
function wc_admin_get_embed_enabled_plugin_screen_ids() {
|
2018-06-26 14:49:42 +00:00
|
|
|
$screens = array();
|
2018-07-10 12:48:06 +00:00
|
|
|
return apply_filters( 'wc_admin_get_embed_enabled_plugin_screens_ids', $screens );
|
2018-06-26 14:49:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns core and plugin screen IDs for a list of screens the new header should be enabled on.
|
|
|
|
*/
|
2018-07-10 12:48:06 +00:00
|
|
|
function wc_admin_get_embed_enabled_screen_ids() {
|
|
|
|
return array_merge( wc_admin_get_embed_enabled_core_screen_ids(), wc_admin_get_embed_enabled_plugin_screen_ids() );
|
2018-06-26 14:49:42 +00:00
|
|
|
}
|
2018-06-20 17:43:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an object defining the currecy options for the site's current currency
|
|
|
|
*
|
|
|
|
* @return array Settings for the current currency {
|
|
|
|
* Array of settings.
|
|
|
|
*
|
2018-06-20 18:21:02 +00:00
|
|
|
* @type string $code Currency code.
|
2018-06-20 17:43:53 +00:00
|
|
|
* @type string $precision Number of decimals.
|
|
|
|
* @type string $symbol Symbol for currency.
|
|
|
|
* }
|
|
|
|
*/
|
2018-07-10 12:48:06 +00:00
|
|
|
function wc_admin_currency_settings() {
|
2018-06-20 17:43:53 +00:00
|
|
|
$code = get_woocommerce_currency();
|
|
|
|
|
|
|
|
return apply_filters(
|
2018-10-22 16:20:14 +00:00
|
|
|
'wc_currency_settings',
|
|
|
|
array(
|
2018-06-20 18:21:02 +00:00
|
|
|
'code' => $code,
|
2018-06-20 17:43:53 +00:00
|
|
|
'precision' => wc_get_price_decimals(),
|
|
|
|
'symbol' => get_woocommerce_currency_symbol( $code ),
|
2018-12-14 00:08:31 +00:00
|
|
|
'position' => get_option( 'woocommerce_currency_pos' ),
|
2018-06-20 17:43:53 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|