2013-07-24 16:01:36 +00:00
< ? php
/**
2015-11-11 09:22:43 +00:00
* Setup menus in WP admin .
2013-07-24 16:01:36 +00:00
*
2018-02-10 06:38:33 +00:00
* @ package WooCommerce\Admin
2018-02-05 19:28:26 +00:00
* @ version 2.5 . 0
2013-07-24 16:01:36 +00:00
*/
2018-02-10 06:38:33 +00:00
defined ( 'ABSPATH' ) || exit ;
2013-07-24 16:01:36 +00:00
2017-11-08 19:33:04 +00:00
if ( class_exists ( 'WC_Admin_Menus' , false ) ) {
return new WC_Admin_Menus ();
}
2013-07-24 16:01:36 +00:00
/**
2015-11-03 12:28:01 +00:00
* WC_Admin_Menus Class .
2013-07-24 16:01:36 +00:00
*/
class WC_Admin_Menus {
/**
* Hook in tabs .
*/
public function __construct () {
2017-11-08 19:33:04 +00:00
// Add menus.
2021-02-11 16:48:36 +00:00
add_action ( 'admin_menu' , array ( $this , 'menu_highlight' ) );
add_action ( 'admin_menu' , array ( $this , 'menu_order_count' ) );
2013-07-24 16:01:36 +00:00
add_action ( 'admin_menu' , array ( $this , 'admin_menu' ), 9 );
add_action ( 'admin_menu' , array ( $this , 'reports_menu' ), 20 );
add_action ( 'admin_menu' , array ( $this , 'settings_menu' ), 50 );
add_action ( 'admin_menu' , array ( $this , 'status_menu' ), 60 );
2014-04-29 13:03:10 +00:00
if ( apply_filters ( 'woocommerce_show_addons_page' , true ) ) {
2013-08-06 13:04:24 +00:00
add_action ( 'admin_menu' , array ( $this , 'addons_menu' ), 70 );
2014-04-29 13:03:10 +00:00
}
2013-08-06 13:04:24 +00:00
2013-07-24 16:01:36 +00:00
add_filter ( 'menu_order' , array ( $this , 'menu_order' ) );
add_filter ( 'custom_menu_order' , array ( $this , 'custom_menu_order' ) );
2018-02-05 19:37:09 +00:00
add_filter ( 'set-screen-option' , array ( $this , 'set_screen_option' ), 10 , 3 );
2021-07-29 13:49:12 +00:00
add_filter ( 'parent_file' , array ( $this , 'update_menu_highlight' ) );
2014-09-19 07:06:28 +00:00
2017-03-28 19:06:26 +00:00
// Add endpoints custom URLs in Appearance > Menus > Pages.
add_action ( 'admin_head-nav-menus.php' , array ( $this , 'add_nav_menu_meta_boxes' ) );
2015-05-27 14:55:32 +00:00
2017-11-08 19:33:04 +00:00
// Admin bar menus.
2015-05-27 14:55:32 +00:00
if ( apply_filters ( 'woocommerce_show_admin_bar_visit_store' , true ) ) {
add_action ( 'admin_bar_menu' , array ( $this , 'admin_bar_menus' ), 31 );
}
2019-03-20 11:34:02 +00:00
// Handle saving settings earlier than load-{page} hook to avoid race conditions in conditional menus.
add_action ( 'wp_loaded' , array ( $this , 'save_settings' ) );
2013-07-24 16:01:36 +00:00
}
/**
2015-11-03 12:28:01 +00:00
* Add menu items .
2013-07-24 16:01:36 +00:00
*/
public function admin_menu () {
2014-06-08 20:33:11 +00:00
global $menu ;
2013-07-24 16:01:36 +00:00
2021-02-10 20:12:47 +00:00
$woocommerce_icon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDI0IDEwMjQiPjxwYXRoIGZpbGw9IiNhMmFhYjIiIGQ9Ik02MTIuMTkyIDQyNi4zMzZjMC02Ljg5Ni0zLjEzNi01MS42LTI4LTUxLjYtMzcuMzYgMC00Ni43MDQgNzIuMjU2LTQ2LjcwNCA4Mi42MjQgMCAzLjQwOCAzLjE1MiA1OC40OTYgMjguMDMyIDU4LjQ5NiAzNC4xOTItLjAzMiA0Ni42NzItNzIuMjg4IDQ2LjY3Mi04OS41MnptMjAyLjE5MiAwYzAtNi44OTYtMy4xNTItNTEuNi0yOC4wMzItNTEuNi0zNy4yOCAwLTQ2LjYwOCA3Mi4yNTYtNDYuNjA4IDgyLjYyNCAwIDMuNDA4IDMuMDcyIDU4LjQ5NiAyNy45NTIgNTguNDk2IDM0LjE5Mi0uMDMyIDQ2LjY4OC03Mi4yODggNDYuNjg4LTg5LjUyek0xNDEuMjk2Ljc2OGMtNjguMjI0IDAtMTIzLjUwNCA1NS40ODgtMTIzLjUwNCAxMjMuOTJ2NjUwLjcyYzAgNjguNDMyIDU1LjI5NiAxMjMuOTIgMTIzLjUwNCAxMjMuOTJoMzM5LjgwOGwxMjMuNTA0IDEyMy45MzZWODk5LjMyOGgyNzguMDQ4YzY4LjIyNCAwIDEyMy41Mi01NS40NzIgMTIzLjUyLTEyMy45MnYtNjUwLjcyYzAtNjguNDMyLTU1LjI5Ni0xMjMuOTItMTIzLjUyLTEyMy45MmgtNzQxLjM2em01MjYuODY0IDQyMi4xNmMwIDU1LjA4OC0zMS4wODggMTU0Ljg4LTEwMi42NCAxNTQuODgtNi4yMDggMC0xOC40OTYtMy42MTYtMjUuNDI0LTYuMDE2LTMyLjUxMi0xMS4xNjgtNTAuMTkyLTQ5LjY5Ni01Mi4zNTItNjYuMjU2IDAgMC0zLjA3Mi0xNy43OTItMy4wNzItNDAuNzUyIDAtMjIuOTkyIDMuMDcyLTQ1LjMyOCAzLjA3Mi00NS4zMjggMTUuNTUyLTc1LjcyOCA0My41NTItMTA2LjczNiA5Ni40NDgtMTA2LjczNiA1OS4wNzItLjAzMiA4My45NjggNTguNTI4IDgzLjk2OCAxMTAuMjA4ek00ODYuNDk2IDMwMi40YzAgMy4zOTItNDMuNTUyIDE0MS4xNjgtNDMuNTUyIDIxMy40MjR2NzUuNzEyYy0yLjU5MiAxMi4wOC00LjE2IDI0LjE0NC0yMS44MjQgMjQuMTQ0LTQ2LjYwOCAwLTg4Ljg4LTE1MS40NzItOTIuMDE2LTE2MS44NC02LjIwOCA2Ljg5Ni02Mi4yNCAxNjEuODQtOTYuNDQ4IDE2MS44NC0yNC44NjQgMC00My41NTItMTEzLjY0OC00Ni42MDgtMTIzLjkzNkMxNzYuNzA0IDQzNi42NzIgMTYwIDMzNC4yMjQgMTYwIDMyNy4zMjhjMC0yMC42NzIgMS4xNTItMzguNzM2IDI2LjA0OC0zOC43MzYgNi4yMDggMCAyMS42IDYuMDY0IDIzLjcxMiAxNy4xNjggMTEuNjQ4IDYyLjAzMiAxNi42ODggMTIwLjUxMiAyOS4xNjggMTg1Ljk2OCAxLjg1NiAyLjkyOCAxLjUwNCA3LjAwOCA0LjU2IDEwLjQzMiAzLjE1Mi0xMC4yODggNjYuOTI4LTE2OC43ODQgOTQuOTYtMTY4Ljc4NCAyMi41NDQgMCAzMC40IDQ0LjU5MiAzMy41MzYgNjEuODI0IDYuMjA4IDIwLjY1NiAxMy4wODggNTUuMjE2IDIyLjQxNiA4Mi43NTIgMC0xMy43NzYgMTIuNDgtMjAzLjEyIDY1LjM5Mi0yMDMuMTIgMTguNTkyLjAzMiAyNi43MDQgNi45MjggMjYuNzA0IDI3LjU2OHpNODcwLjMyIDQyMi45MjhjMCA1NS4wODgtMzEuMDg4IDE1NC44OC0xMDIuNjQgMTU0Ljg4LTYuMTkyIDAtMTguNDQ4LTMuNjE2LTI1LjQyNC02LjAxNi0zMi40MzItMTEuMTY4LTUwLjE3Ni00OS42OTYtNTIuMjg4LTY2LjI1NiAwIDAtMy44ODgtMTcuOTItMy44ODgtNDAuODk2czMuODg4LTQ1LjE4NCAzLjg4OC00NS4xODRjMTUuNTUyLTc1LjcyOCA0My40ODgtMTA2LjczNiA5Ni4zODQtMTA2LjczNiA1OS4xMDQtLjAzMiA4My45NjggNTguNTI4IDgzLjk2OCAxMTAuMjA4eiIvPjwvc3ZnPg==' ;
2020-06-25 23:01:12 +00:00
if ( current_user_can ( 'edit_others_shop_orders' ) ) {
2017-11-08 19:33:04 +00:00
$menu [] = array ( '' , 'read' , 'separator-woocommerce' , '' , 'wp-menu-separator woocommerce' ); // WPCS: override ok.
2014-09-16 02:32:34 +00:00
}
2013-07-24 16:01:36 +00:00
2021-02-10 20:12:47 +00:00
add_menu_page ( __ ( 'WooCommerce' , 'woocommerce' ), __ ( 'WooCommerce' , 'woocommerce' ), 'edit_others_shop_orders' , 'woocommerce' , null , $woocommerce_icon , '55.5' );
2013-07-24 16:01:36 +00:00
2014-09-16 02:32:34 +00:00
add_submenu_page ( 'edit.php?post_type=product' , __ ( 'Attributes' , 'woocommerce' ), __ ( 'Attributes' , 'woocommerce' ), 'manage_product_terms' , 'product_attributes' , array ( $this , 'attributes_page' ) );
2013-07-24 16:01:36 +00:00
}
/**
2015-11-03 12:28:01 +00:00
* Add menu item .
2013-07-24 16:01:36 +00:00
*/
public function reports_menu () {
2020-06-25 23:01:12 +00:00
if ( current_user_can ( 'edit_others_shop_orders' ) ) {
2018-02-05 19:28:26 +00:00
add_submenu_page ( 'woocommerce' , __ ( 'Reports' , 'woocommerce' ), __ ( 'Reports' , 'woocommerce' ), 'view_woocommerce_reports' , 'wc-reports' , array ( $this , 'reports_page' ) );
2015-02-24 12:29:03 +00:00
} else {
2021-02-12 15:37:23 +00:00
add_menu_page ( __ ( 'Sales reports' , 'woocommerce' ), __ ( 'Sales reports' , 'woocommerce' ), 'view_woocommerce_reports' , 'wc-reports' , array ( $this , 'reports_page' ), 'dashicons-chart-bar' , '55.6' );
2015-02-24 12:29:03 +00:00
}
2013-07-24 16:01:36 +00:00
}
/**
2015-11-03 12:28:01 +00:00
* Add menu item .
2013-07-24 16:01:36 +00:00
*/
public function settings_menu () {
2018-02-05 19:28:26 +00:00
$settings_page = add_submenu_page ( 'woocommerce' , __ ( 'WooCommerce settings' , 'woocommerce' ), __ ( 'Settings' , 'woocommerce' ), 'manage_woocommerce' , 'wc-settings' , array ( $this , 'settings_page' ) );
2013-07-24 16:01:36 +00:00
add_action ( 'load-' . $settings_page , array ( $this , 'settings_page_init' ) );
}
/**
* Loads gateways and shipping methods into memory for use within settings .
*/
public function settings_page_init () {
2013-07-26 14:36:28 +00:00
WC () -> payment_gateways ();
WC () -> shipping ();
2017-07-25 18:43:26 +00:00
2017-11-08 19:33:04 +00:00
// Include settings pages.
2017-07-25 18:43:26 +00:00
WC_Admin_Settings :: get_settings_pages ();
2017-11-08 19:33:04 +00:00
// Add any posted messages.
if ( ! empty ( $_GET [ 'wc_error' ] ) ) { // WPCS: input var okay, CSRF ok.
WC_Admin_Settings :: add_error ( wp_kses_post ( wp_unslash ( $_GET [ 'wc_error' ] ) ) ); // WPCS: input var okay, CSRF ok.
2017-07-25 18:43:26 +00:00
}
2017-11-08 19:33:04 +00:00
if ( ! empty ( $_GET [ 'wc_message' ] ) ) { // WPCS: input var okay, CSRF ok.
WC_Admin_Settings :: add_message ( wp_kses_post ( wp_unslash ( $_GET [ 'wc_message' ] ) ) ); // WPCS: input var okay, CSRF ok.
2017-07-25 18:43:26 +00:00
}
2018-02-05 19:26:38 +00:00
do_action ( 'woocommerce_settings_page_init' );
2013-07-24 16:01:36 +00:00
}
2019-03-20 11:34:02 +00:00
/**
* Handle saving of settings .
*
* @ return void
*/
public function save_settings () {
global $current_tab , $current_section ;
// We should only save on the settings page.
2019-12-13 19:58:14 +00:00
if ( ! is_admin () || ! isset ( $_GET [ 'page' ] ) || 'wc-settings' !== $_GET [ 'page' ] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
2019-03-20 11:34:02 +00:00
return ;
}
// Include settings pages.
WC_Admin_Settings :: get_settings_pages ();
// Get current tab/section.
$current_tab = empty ( $_GET [ 'tab' ] ) ? 'general' : sanitize_title ( wp_unslash ( $_GET [ 'tab' ] ) ); // WPCS: input var okay, CSRF ok.
$current_section = empty ( $_REQUEST [ 'section' ] ) ? '' : sanitize_title ( wp_unslash ( $_REQUEST [ 'section' ] ) ); // WPCS: input var okay, CSRF ok.
// Save settings if data has been posted.
if ( '' !== $current_section && apply_filters ( " woocommerce_save_settings_ { $current_tab } _ { $current_section } " , ! empty ( $_POST [ 'save' ] ) ) ) { // WPCS: input var okay, CSRF ok.
WC_Admin_Settings :: save ();
} elseif ( '' === $current_section && apply_filters ( " woocommerce_save_settings_ { $current_tab } " , ! empty ( $_POST [ 'save' ] ) ) ) { // WPCS: input var okay, CSRF ok.
WC_Admin_Settings :: save ();
}
}
2013-07-24 16:01:36 +00:00
/**
2015-11-03 12:28:01 +00:00
* Add menu item .
2013-07-24 16:01:36 +00:00
*/
public function status_menu () {
2018-02-05 19:28:26 +00:00
add_submenu_page ( 'woocommerce' , __ ( 'WooCommerce status' , 'woocommerce' ), __ ( 'Status' , 'woocommerce' ), 'manage_woocommerce' , 'wc-status' , array ( $this , 'status_page' ) );
2013-07-24 16:01:36 +00:00
}
2013-08-06 13:04:24 +00:00
/**
2015-11-03 12:28:01 +00:00
* Addons menu item .
2013-08-06 13:04:24 +00:00
*/
public function addons_menu () {
2017-08-30 14:19:06 +00:00
$count_html = WC_Helper_Updater :: get_updates_count_html ();
2017-11-08 19:33:04 +00:00
/* translators: %s: extensions count */
2021-07-30 09:00:53 +00:00
$menu_title = sprintf ( __ ( 'My Subscriptions %s' , 'woocommerce' ), $count_html );
2021-08-06 11:26:22 +00:00
add_submenu_page ( 'woocommerce' , __ ( 'WooCommerce Marketplace' , 'woocommerce' ), __ ( 'Marketplace' , 'woocommerce' ), 'manage_woocommerce' , 'wc-addons' , array ( $this , 'addons_page' ) );
2021-08-05 15:53:18 +00:00
add_submenu_page ( 'woocommerce' , __ ( 'My WooCommerce.com Subscriptions' , 'woocommerce' ), $menu_title , 'manage_woocommerce' , 'wc-addons§ion=helper' , array ( $this , 'addons_page' ) );
2013-08-06 13:04:24 +00:00
}
2013-07-24 16:01:36 +00:00
/**
* Highlights the correct top level admin menu item for post type add screens .
*/
public function menu_highlight () {
2015-01-21 11:05:58 +00:00
global $parent_file , $submenu_file , $post_type ;
switch ( $post_type ) {
2017-11-08 19:33:04 +00:00
case 'shop_order' :
case 'shop_coupon' :
$parent_file = 'woocommerce' ; // WPCS: override ok.
break ;
case 'product' :
2013-07-24 16:01:36 +00:00
$screen = get_current_screen ();
2016-02-05 12:16:41 +00:00
if ( $screen && taxonomy_is_product_attribute ( $screen -> taxonomy ) ) {
2017-11-08 19:33:04 +00:00
$submenu_file = 'product_attributes' ; // WPCS: override ok.
$parent_file = 'edit.php?post_type=product' ; // WPCS: override ok.
2013-07-24 16:01:36 +00:00
}
2017-11-08 19:33:04 +00:00
break ;
2013-07-24 16:01:36 +00:00
}
2015-01-21 11:05:58 +00:00
}
2013-07-24 16:01:36 +00:00
2015-01-21 11:05:58 +00:00
/**
2015-11-03 12:28:01 +00:00
* Adds the order processing count to the menu .
2015-01-21 11:05:58 +00:00
*/
public function menu_order_count () {
global $submenu ;
if ( isset ( $submenu [ 'woocommerce' ] ) ) {
2017-11-08 19:33:04 +00:00
// Remove 'WooCommerce' sub menu item.
2015-01-21 11:05:58 +00:00
unset ( $submenu [ 'woocommerce' ][ 0 ] );
2017-11-08 19:33:04 +00:00
// Add count if user has access.
2020-04-29 21:19:25 +00:00
if ( apply_filters ( 'woocommerce_include_processing_order_count_in_menu' , true ) && current_user_can ( 'edit_others_shop_orders' ) ) {
2020-03-31 20:43:50 +00:00
$order_count = apply_filters ( 'woocommerce_menu_order_count' , wc_processing_order_count () );
2019-03-08 22:18:31 +00:00
if ( $order_count ) {
foreach ( $submenu [ 'woocommerce' ] as $key => $menu_item ) {
if ( 0 === strpos ( $menu_item [ 0 ], _x ( 'Orders' , 'Admin menu name' , 'woocommerce' ) ) ) {
2020-03-31 20:43:50 +00:00
$submenu [ 'woocommerce' ][ $key ][ 0 ] .= ' <span class="awaiting-mod update-plugins count-' . esc_attr ( $order_count ) . '"><span class="processing-count">' . number_format_i18n ( $order_count ) . '</span></span>' ; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
2019-03-08 22:18:31 +00:00
break ;
}
2013-07-24 16:01:36 +00:00
}
}
}
}
}
/**
* Reorder the WC menu items in admin .
*
2017-11-08 19:33:04 +00:00
* @ param int $menu_order Menu order .
2013-07-24 16:01:36 +00:00
* @ return array
*/
public function menu_order ( $menu_order ) {
2017-11-08 19:33:04 +00:00
// Initialize our custom order array.
2013-07-24 16:01:36 +00:00
$woocommerce_menu_order = array ();
2017-11-08 19:33:04 +00:00
// Get the index of our custom separator.
$woocommerce_separator = array_search ( 'separator-woocommerce' , $menu_order , true );
2013-07-24 16:01:36 +00:00
2017-11-08 19:33:04 +00:00
// Get index of product menu.
$woocommerce_product = array_search ( 'edit.php?post_type=product' , $menu_order , true );
2013-07-24 16:01:36 +00:00
2017-11-08 19:33:04 +00:00
// Loop through menu order and do some rearranging.
2014-09-16 02:32:34 +00:00
foreach ( $menu_order as $index => $item ) {
2013-07-24 16:01:36 +00:00
2017-11-08 19:33:04 +00:00
if ( 'woocommerce' === $item ) {
2013-07-24 16:01:36 +00:00
$woocommerce_menu_order [] = 'separator-woocommerce' ;
$woocommerce_menu_order [] = $item ;
$woocommerce_menu_order [] = 'edit.php?post_type=product' ;
2015-01-21 11:05:58 +00:00
unset ( $menu_order [ $woocommerce_separator ] );
unset ( $menu_order [ $woocommerce_product ] );
2017-11-08 19:33:04 +00:00
} elseif ( ! in_array ( $item , array ( 'separator-woocommerce' ), true ) ) {
2013-07-24 16:01:36 +00:00
$woocommerce_menu_order [] = $item ;
2014-09-16 02:32:34 +00:00
}
}
2013-07-24 16:01:36 +00:00
2017-11-08 19:33:04 +00:00
// Return order.
2013-07-24 16:01:36 +00:00
return $woocommerce_menu_order ;
}
/**
2015-11-03 12:28:01 +00:00
* Custom menu order .
2014-09-16 02:32:34 +00:00
*
2018-07-19 20:39:41 +00:00
* @ param bool $enabled Whether custom menu ordering is already enabled .
2013-07-24 16:01:36 +00:00
* @ return bool
*/
2018-07-19 20:39:41 +00:00
public function custom_menu_order ( $enabled ) {
2020-06-25 23:01:12 +00:00
return $enabled || current_user_can ( 'edit_others_shop_orders' );
2013-07-24 16:01:36 +00:00
}
2018-02-05 19:37:09 +00:00
/**
* Validate screen options on update .
*
* @ param bool | int $status Screen option value . Default false to skip .
* @ param string $option The option name .
* @ param int $value The number of rows to use .
*/
public function set_screen_option ( $status , $option , $value ) {
2018-02-23 04:18:56 +00:00
if ( in_array ( $option , array ( 'woocommerce_keys_per_page' , 'woocommerce_webhooks_per_page' ), true ) ) {
2018-02-05 19:37:09 +00:00
return $value ;
}
return $status ;
}
2013-07-24 16:01:36 +00:00
/**
2015-11-03 12:28:01 +00:00
* Init the reports page .
2013-07-24 16:01:36 +00:00
*/
public function reports_page () {
2014-03-20 11:10:25 +00:00
WC_Admin_Reports :: output ();
2013-07-24 16:01:36 +00:00
}
/**
2015-11-03 12:28:01 +00:00
* Init the settings page .
2013-07-24 16:01:36 +00:00
*/
public function settings_page () {
2013-07-26 14:36:28 +00:00
WC_Admin_Settings :: output ();
2013-07-24 16:01:36 +00:00
}
/**
2015-11-03 12:28:01 +00:00
* Init the attributes page .
2013-07-24 16:01:36 +00:00
*/
public function attributes_page () {
2014-06-04 10:16:19 +00:00
WC_Admin_Attributes :: output ();
2013-07-24 16:01:36 +00:00
}
/**
2015-11-03 12:28:01 +00:00
* Init the status page .
2013-07-24 16:01:36 +00:00
*/
public function status_page () {
2014-06-04 10:16:19 +00:00
WC_Admin_Status :: output ();
2013-07-24 16:01:36 +00:00
}
2013-08-06 13:04:24 +00:00
/**
2015-11-03 12:28:01 +00:00
* Init the addons page .
2013-08-06 13:04:24 +00:00
*/
public function addons_page () {
2014-06-04 10:16:19 +00:00
WC_Admin_Addons :: output ();
2013-08-06 13:04:24 +00:00
}
2014-09-19 07:06:28 +00:00
/**
2015-11-03 12:28:01 +00:00
* Add custom nav meta box .
2014-09-19 07:06:28 +00:00
*
2015-11-03 12:28:01 +00:00
* Adapted from http :// www . johnmorrisonline . com / how - to - add - a - fully - functional - custom - meta - box - to - wordpress - navigation - menus /.
2014-09-19 07:06:28 +00:00
*/
2014-10-17 13:42:35 +00:00
public function add_nav_menu_meta_boxes () {
2016-10-12 10:16:30 +00:00
add_meta_box ( 'woocommerce_endpoints_nav_link' , __ ( 'WooCommerce endpoints' , 'woocommerce' ), array ( $this , 'nav_menu_links' ), 'nav-menus' , 'side' , 'low' );
2014-10-17 13:42:35 +00:00
}
2014-09-19 07:06:28 +00:00
2016-01-05 15:29:16 +00:00
/**
* Output menu links .
*/
2014-10-17 13:42:35 +00:00
public function nav_menu_links () {
2017-03-28 21:33:06 +00:00
// Get items from account menu.
$endpoints = wc_get_account_menu_items ();
// Remove dashboard item.
if ( isset ( $endpoints [ 'dashboard' ] ) ) {
unset ( $endpoints [ 'dashboard' ] );
}
// Include missing lost password.
$endpoints [ 'lost-password' ] = __ ( 'Lost password' , 'woocommerce' );
$endpoints = apply_filters ( 'woocommerce_custom_nav_menu_items' , $endpoints );
2014-10-17 13:42:35 +00:00
?>
< div id = " posttype-woocommerce-endpoints " class = " posttypediv " >
2014-11-30 06:52:32 +00:00
< div id = " tabs-panel-woocommerce-endpoints " class = " tabs-panel tabs-panel-active " >
< ul id = " woocommerce-endpoints-checklist " class = " categorychecklist form-no-clear " >
< ? php
$i = - 1 ;
2017-03-28 21:33:06 +00:00
foreach ( $endpoints as $key => $value ) :
2014-11-30 06:52:32 +00:00
?>
< li >
< label class = " menu-item-title " >
2017-03-28 21:33:06 +00:00
< input type = " checkbox " class = " menu-item-checkbox " name = " menu-item[<?php echo esc_attr( $i ); ?>][menu-item-object-id] " value = " <?php echo esc_attr( $i ); ?> " /> < ? php echo esc_html ( $value ); ?>
2014-11-30 06:52:32 +00:00
</ label >
< input type = " hidden " class = " menu-item-type " name = " menu-item[<?php echo esc_attr( $i ); ?>][menu-item-type] " value = " custom " />
2019-08-22 10:51:23 +00:00
< input type = " hidden " class = " menu-item-title " name = " menu-item[<?php echo esc_attr( $i ); ?>][menu-item-title] " value = " <?php echo esc_attr( $value ); ?> " />
2017-03-28 21:33:06 +00:00
< input type = " hidden " class = " menu-item-url " name = " menu-item[<?php echo esc_attr( $i ); ?>][menu-item-url] " value = " <?php echo esc_url( wc_get_account_endpoint_url( $key ) ); ?> " />
2014-11-30 06:52:32 +00:00
< input type = " hidden " class = " menu-item-classes " name = " menu-item[<?php echo esc_attr( $i ); ?>][menu-item-classes] " />
</ li >
< ? php
2017-03-28 21:33:06 +00:00
$i -- ;
endforeach ;
2014-11-30 06:52:32 +00:00
?>
</ ul >
</ div >
< p class = " button-controls " >
< span class = " list-controls " >
2017-11-08 19:33:04 +00:00
< a href = " <?php echo esc_url( admin_url( 'nav-menus.php?page-tab=all&selectall=1#posttype-woocommerce-endpoints' ) ); ?> " class = " select-all " >< ? php esc_html_e ( 'Select all' , 'woocommerce' ); ?> </a>
2014-11-30 06:52:32 +00:00
</ span >
< span class = " add-to-menu " >
2017-11-16 14:20:22 +00:00
< button type = " submit " class = " button-secondary submit-add-to-menu right " value = " <?php esc_attr_e( 'Add to menu', 'woocommerce' ); ?> " name = " add-post-type-menu-item " id = " submit-posttype-woocommerce-endpoints " >< ? php esc_html_e ( 'Add to menu' , 'woocommerce' ); ?> </button>
2018-02-25 11:33:29 +00:00
< span class = " spinner " ></ span >
2014-11-30 06:52:32 +00:00
</ span >
</ p >
</ div >
< ? php
2014-09-19 07:06:28 +00:00
}
2015-05-27 14:55:32 +00:00
/**
2015-11-03 12:28:01 +00:00
* Add the " Visit Store " link in admin bar main menu .
2015-05-27 14:55:32 +00:00
*
* @ since 2.4 . 0
2017-11-08 19:33:04 +00:00
* @ param WP_Admin_Bar $wp_admin_bar Admin bar instance .
2015-05-27 14:55:32 +00:00
*/
public function admin_bar_menus ( $wp_admin_bar ) {
2018-06-18 11:07:56 +00:00
if ( ! is_admin () || ! is_admin_bar_showing () ) {
2015-05-27 14:55:32 +00:00
return ;
}
2015-11-03 12:28:01 +00:00
// Show only when the user is a member of this site, or they're a super admin.
2015-05-27 14:55:32 +00:00
if ( ! is_user_member_of_blog () && ! is_super_admin () ) {
return ;
}
2015-11-03 12:28:01 +00:00
// Don't display when shop page is the same of the page on front.
2017-11-08 19:33:04 +00:00
if ( intval ( get_option ( 'page_on_front' ) ) === wc_get_page_id ( 'shop' ) ) {
2015-05-27 14:55:32 +00:00
return ;
}
2015-11-03 12:28:01 +00:00
// Add an option to visit the store.
2018-03-05 18:59:17 +00:00
$wp_admin_bar -> add_node (
array (
'parent' => 'site-name' ,
'id' => 'view-store' ,
'title' => __ ( 'Visit Store' , 'woocommerce' ),
'href' => wc_get_page_permalink ( 'shop' ),
)
);
2015-05-27 14:55:32 +00:00
}
2021-07-29 13:49:12 +00:00
/**
* Highlight the My Subscriptions menu item when on that page
*
* @ param string $parent_file currently opened page .
* @ return string
*/
public function update_menu_highlight ( $parent_file ) {
global $submenu_file ;
if ( 'woocommerce' === $parent_file && isset ( $_GET [ 'section' ] ) && 'helper' === $_GET [ 'section' ] ) {
$submenu_file = 'wc-addons§ion=helper' ; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
}
return $parent_file ;
}
2021-08-06 11:26:22 +00:00
/**
* Update the My Subscriptions document title when on that page .
* We want to maintain existing page URL but add it as a separate page ,
* which requires updating it manually .
*
* @ param string $admin_title existing page title .
* @ return string
*/
public function update_my_subscriptions_title ( $admin_title ) {
if (
isset ( $_GET [ 'page' ] ) && 'wc-addons' === $_GET [ 'page' ] &&
isset ( $_GET [ 'section' ] ) && 'helper' === $_GET [ 'section' ]
) {
$admin_title = 'My WooCommerce.com Subscriptions' ;
}
return $admin_title ;
}
2013-07-24 16:01:36 +00:00
}
2014-06-27 23:08:30 +00:00
return new WC_Admin_Menus ();