Merged in feature/MAW-855-import-code-into-aws (pull request #2)

code import from pantheon

* code import from pantheon
This commit is contained in:
Tony Volpe
2023-12-04 23:08:14 +00:00
parent 8c9b1312bc
commit 8f4b5efda6
4766 changed files with 185592 additions and 239967 deletions

View File

@@ -6,10 +6,14 @@
* @version 2.5.0
*/
use Automattic\WooCommerce\Admin\Features\Features;
use Automattic\WooCommerce\Admin\PageController;
use Automattic\WooCommerce\Internal\Admin\Marketplace;
use Automattic\WooCommerce\Internal\Admin\Orders\COTRedirectionController;
use Automattic\WooCommerce\Internal\Admin\Orders\PageController as Custom_Orders_PageController;
use Automattic\WooCommerce\Internal\Admin\WCAdminAssets;
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
use Automattic\WooCommerce\Admin\Features\Features;
use Automattic\WooCommerce\Utilities\FeaturesUtil;
defined( 'ABSPATH' ) || exit;
@@ -22,6 +26,13 @@ if ( class_exists( 'WC_Admin_Menus', false ) ) {
*/
class WC_Admin_Menus {
/**
* The CSS classes used to hide the submenu items in navigation.
*
* @var string
*/
const HIDE_CSS_CLASS = 'hide-if-js';
/**
* Hook in tabs.
*/
@@ -36,8 +47,23 @@ class WC_Admin_Menus {
add_action( 'admin_menu', array( $this, 'settings_menu' ), 50 );
add_action( 'admin_menu', array( $this, 'status_menu' ), 60 );
/**
* Controls whether we add a submenu item for the WooCommerce Addons page.
* Woo Express uses this filter.
*
* @since 8.2.1
*
* @param bool $show_addons_page If the addons page should be included.
*/
if ( apply_filters( 'woocommerce_show_addons_page', true ) ) {
add_action( 'admin_menu', array( $this, 'addons_menu' ), 70 );
if ( FeaturesUtil::feature_is_enabled( 'marketplace' ) ) {
$container = wc_get_container();
$container->get( Marketplace::class );
add_action( 'admin_menu', array( $this, 'addons_my_subscriptions' ), 70 );
} else {
add_action( 'admin_menu', array( $this, 'addons_menu' ), 70 );
}
}
add_filter( 'menu_order', array( $this, 'menu_order' ) );
@@ -171,6 +197,18 @@ class WC_Admin_Menus {
add_submenu_page( 'woocommerce', __( 'WooCommerce extensions', 'woocommerce' ), $menu_title, 'manage_woocommerce', 'wc-addons', array( $this, 'addons_page' ) );
}
/**
* Registers the wc-addons page within the WooCommerce menu.
* Temporary measure till we convert the whole page to React.
*
* @return void
*/
public function addons_my_subscriptions() {
add_submenu_page( 'woocommerce', __( 'WooCommerce extensions', 'woocommerce' ), null, 'manage_woocommerce', 'wc-addons', array( $this, 'addons_page' ) );
// Temporarily hide the submenu item we've just added.
$this->hide_submenu_page( 'woocommerce', 'wc-addons' );
}
/**
* Highlights the correct top level admin menu item for post type add screens.
*/
@@ -426,7 +464,7 @@ class WC_Admin_Menus {
* Maybe add new management product experience.
*/
public function maybe_add_new_product_management_experience() {
if ( Features::is_enabled( 'new-product-management-experience' ) || \Automattic\WooCommerce\Utilities\FeaturesUtil::feature_is_enabled( 'product_block_editor' ) ) {
if ( Features::is_enabled( 'new-product-management-experience' ) || FeaturesUtil::feature_is_enabled( 'product_block_editor' ) ) {
global $submenu;
if ( isset( $submenu['edit.php?post_type=product'][10] ) ) {
// Disable phpcs since we need to override submenu classes.
@@ -437,6 +475,58 @@ class WC_Admin_Menus {
}
}
}
/**
* Hide the submenu page based on slug and return the item that was hidden.
*
* Borrowed from Jetpack's Base_Admin_Menu class.
*
* Instead of actually removing the submenu item, a safer approach is to hide it and filter it in the API response.
* In this manner we'll avoid breaking third-party plugins depending on items that no longer exist.
*
* A false|array value is returned to be consistent with remove_submenu_page() function
*
* @param string $menu_slug The parent menu slug.
* @param string $submenu_slug The submenu slug that should be hidden.
* @return false|array
*/
public function hide_submenu_page( $menu_slug, $submenu_slug ) {
global $submenu;
if ( ! isset( $submenu[ $menu_slug ] ) ) {
return false;
}
foreach ( $submenu[ $menu_slug ] as $i => $item ) {
if ( $submenu_slug !== $item[2] ) {
continue;
}
$this->hide_submenu_element( $i, $menu_slug, $item );
return $item;
}
return false;
}
/**
* Apply the hide-if-js CSS class to a submenu item.
*
* Borrowed from Jetpack's Base_Admin_Menu class.
*
* @param int $index The position of a submenu item in the submenu array.
* @param string $parent_slug The parent slug.
* @param array $item The submenu item.
*/
public function hide_submenu_element( $index, $parent_slug, $item ) {
global $submenu;
$css_classes = empty( $item[4] ) ? self::HIDE_CSS_CLASS : $item[4] . ' ' . self::HIDE_CSS_CLASS;
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$submenu [ $parent_slug ][ $index ][4] = $css_classes;
}
}
return new WC_Admin_Menus();