Plugin Directory

Changeset 3108797

Timestamp:
06/27/2024 02:45:01 PM (6 weeks ago)
Author:
whiteshadow
Message:

Fix WooCommerce conflict where two "Orders" menu items would appear when AME was active.

In certain configurations, WooCommerce creates two "WooCommerce -> Orders" menu items. This may be related to whether the "High-performance order storage" setting is enabled in WooCommerce. One "Orders" menu item is for the "Orders" CPT, while the other is a custom (more recent?) "wc-orders" item. WooCommerce removes the CPT item in "admin_init", which doesn't work with AME because AME processes the menu before that, in "admin_menu".

The current workaround is to check if both items exist and to remove one. Unfortunately, there doesn't seem to be a better way to do this since remove_submenu_page() is not hookable and moving menu processing to "admin_init" would interfere with some AME features, like custom menu permissions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • admin-menu-editor/trunk/includes/menu-editor-core.php

    r3106195 r3108797  
    43554355
    43564356    /**
    4357      * Compatibility fix for WooCommerce 2.2.1+.
    4358      * Summary: When AME is active, an unusable WooCommerce -> WooCommerce menu item shows up. Here we remove it.
    4359      *
    4360      * WooCommerce creates a top level "WooCommerce" menu with no callback. By default, WordPress automatically adds
    4361      * a submenu item with the same name. However, since the item doesn't have a callback, it is unusable and clicking
    4362      * it just triggers a "Cannot load woocommerce" error. So WooCommerce removes this item in an admin_head hook to
    4363      * hide it. With AME active, the item shows up anyway, and users get confused by the error.
    4364      *
    4365      * Fix it by removing the problematic menu item.
    4366      *
    4367      * Caution: If the user hides all WooCommerce submenus but not the top level menu, the WooCommerce menu will still
    4368      * show up but be inaccessible. This may be slightly counter-intuitive, but seems reasonable.
     4357     * Compatibility fixes for WooCommerce.
    43694358     */
    43704359    private function apply_woocommerce_compat_fix() {
     
    43734362        }
    43744363
     4364
     4365
     4366
     4367
     4368
     4369
     4370
     4371
     4372
     4373
     4374
     4375
     4376
     4377
     4378
     4379
    43754380        $badSubmenuExists = isset($this->default_wp_submenu['woocommerce'][0][2])
    43764381            && ($this->default_wp_submenu['woocommerce'][0][2] === 'woocommerce');
     
    43804385            $this->default_wp_submenu['woocommerce'][0] = $this->default_wp_submenu['woocommerce'][1];
    43814386            unset($this->default_wp_submenu['woocommerce'][1]);
     4387
     4388
     4389
     4390
     4391
     4392
     4393
     4394
     4395
     4396
     4397
     4398
     4399
     4400
     4401
     4402
     4403
     4404
     4405
     4406
     4407
     4408
     4409
    43824410        }
    43834411    }
Note: See TracChangeset for help on using the changeset viewer.