Plugin Directory

Changeset 3111859

Timestamp:
07/03/2024 04:11:39 PM (5 weeks ago)
Author:
whiteshadow
Message:

Fix duplicate "WooCommerce -> Subscriptions" menu items.

Reported by a user, but wasn't tested because WooCommerce Subscriptions is a paid extension. Implementation based on URLs reported by the user.

File:
1 edited

Legend:

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

    r3108803 r3111859  
    43944394         * is active because it happens in the admin_init hook.
    43954395         *
    4396          * Let's check if there are two "Orders" items and remove the one that uses custom post types.
     4396         * According to user reports, when the WooCommerce Subscriptions extension is active, the same
     4397         * problem happens with the "WooCommerce -> Subscriptions" item.
     4398         *
     4399         * Let's check if there are duplicate items and remove the ones that use custom post types.
    43974400         */
    4398         $goodOrdersItemIndex = null;
    4399         $redundantOrdersItemIndex = null;
    4400         foreach($this->default_wp_submenu['woocommerce'] as $index => $menu) {
    4401             //Skip menu items without a slug/URL in case someone adds a custom separator or something.
    4402             if ( !isset($menu[2]) ) {
    4403                 continue;
    4404             }
    4405             if ( $menu[2] === 'edit.php?post_type=shop_order' ) {
    4406                 $redundantOrdersItemIndex = $index;
    4407             } elseif ( $menu[2] === 'wc-orders' ) {
    4408                 $goodOrdersItemIndex = $index;
    4409             }
    4410         }
    4411 
    4412         if ( ($goodOrdersItemIndex !== null) && ($redundantOrdersItemIndex !== null) ) {
    4413             unset($this->default_wp_submenu['woocommerce'][$redundantOrdersItemIndex]);
     4401        $potentialDuplicateItems = [
     4402            'edit.php?post_type=shop_order'        => 'wc-orders',
     4403            'edit.php?post_type=shop_subscription' => 'wc-orders--shop_subscription',
     4404        ];
     4405        foreach ($potentialDuplicateItems as $redundantSlug => $goodSlug) {
     4406            $redundantItemIndex = null;
     4407            $goodItemIndex = null;
     4408            foreach ($this->default_wp_submenu['woocommerce'] as $index => $menu) {
     4409                //Skip menu items without a slug/URL in case someone adds a custom separator or something.
     4410                if ( !isset($menu[2]) ) {
     4411                    continue;
     4412                }
     4413                if ( $menu[2] === $redundantSlug ) {
     4414                    $redundantItemIndex = $index;
     4415                } elseif ( $menu[2] === $goodSlug ) {
     4416                    $goodItemIndex = $index;
     4417                }
     4418            }
     4419            if ( ($goodItemIndex !== null) && ($redundantItemIndex !== null) ) {
     4420                unset($this->default_wp_submenu['woocommerce'][$redundantItemIndex]);
     4421            }
    44144422        }
    44154423    }
Note: See TracChangeset for help on using the changeset viewer.