Added condition to skip WooCommerce product 18734002369816 from the list of Woo extensions. The Woo release team uses this product to distribute the Woo AF release (pcShBQ-14K).
Restored `woocommerce_show_addons_page` filter, which is used to add or not add the Extensions menu item. Changed the method we use to hide the extra Extensions submenu item we add to WooCommerce as a temporary measure, to ensure the My Subscriptions page still works. Using the superior `hide_submenu_page` method borrowed from Jetpack.
This commit is contained in:
parent
bda564ad67
commit
db8dede036
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: fix
|
||||
|
||||
Adds condition to ensure WooCommerce is not listed as a Woo extension in the Helper list. Restores the `woocommerce_show_addons_page` filter as a means of controlling whether the addons page is added as a WooCommerce submenu item. Hides a temporary extra addons submenu item using a better method borrowed from Jetpack.
|
|
@ -1,16 +0,0 @@
|
|||
document.addEventListener( 'DOMContentLoaded', () => {
|
||||
|
||||
const addonsSubMenuLinks = document.querySelectorAll(
|
||||
'#adminmenu' +
|
||||
' #toplevel_page_woocommerce' +
|
||||
' .wp-submenu' +
|
||||
' li a[href="admin.php?page=wc-addons"]'
|
||||
);
|
||||
|
||||
addonsSubMenuLinks.forEach( ( el, index ) => {
|
||||
if ( ! el.innerHTML ) {
|
||||
el.parentNode.remove();
|
||||
}
|
||||
} );
|
||||
|
||||
} );
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
use Automattic\Jetpack\Constants;
|
||||
use Automattic\WooCommerce\Admin\Features\Features;
|
||||
use Automattic\WooCommerce\Utilities\FeaturesUtil;
|
||||
use Automattic\WooCommerce\Internal\Admin\WCAdminAssets;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -553,12 +552,6 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) :
|
|||
);
|
||||
wp_enqueue_script( 'marketplace-suggestions' );
|
||||
}
|
||||
|
||||
// Temporarily hide empty addons submenu item
|
||||
if ( FeaturesUtil::feature_is_enabled( 'marketplace' ) ) {
|
||||
wp_enqueue_script( 'wc-admin-menu', WC()->plugin_url() . '/assets/js/admin/wc-admin-menu' . $suffix . '.js', null, $version );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,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.
|
||||
*/
|
||||
|
@ -40,13 +47,15 @@ class WC_Admin_Menus {
|
|||
add_action( 'admin_menu', array( $this, 'settings_menu' ), 50 );
|
||||
add_action( 'admin_menu', array( $this, 'status_menu' ), 60 );
|
||||
|
||||
if ( FeaturesUtil::feature_is_enabled( 'marketplace' ) ) {
|
||||
$container = wc_get_container();
|
||||
$container->get( Marketplace::class );
|
||||
if ( apply_filters( 'woocommerce_show_addons_page', true ) ) {
|
||||
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_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' ) );
|
||||
|
@ -188,6 +197,8 @@ class WC_Admin_Menus {
|
|||
*/
|
||||
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' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -456,6 +467,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();
|
||||
|
|
|
@ -1199,6 +1199,11 @@ class WC_Helper {
|
|||
continue;
|
||||
}
|
||||
|
||||
// Omit the WooCommerce plugin used on Woo Express sites.
|
||||
if ( 'WooCommerce' === $data['Name'] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data['_filename'] = $filename;
|
||||
$data['_product_id'] = absint( $product_id );
|
||||
$data['_file_id'] = $file_id;
|
||||
|
|
Loading…
Reference in New Issue