• Resolved diweb

    (@diweb)


    Hi,

    We have identified an issue in the white-label-cms plugin related to how admin submenu items are processed, which can lead to PHP warnings and potentially break the admin menu when stored values are malformed or legacy.

    In includes/classes/AdminMenus.php, inside the block that handles $setting_admin_menus['sub'], the current code assumes that explode() will always return at least two valid elements:

    if (isset($setting_admin_menus['sub']) && is_array($setting_admin_menus['sub'])) {
    foreach ($setting_admin_menus['sub'] as $submenu_item) {
    $submenu_list = explode($this->get_submenu_placeholder(), $submenu_item);
    $main_menu = $submenu_list[0];
    $main_submenu = $submenu_list[1];
    $this->remove_submenu_page($main_menu, $main_submenu);
    }

    $this->fix_woocommerce();
    $this->fix_yoast($setting_admin_menus['sub']);
    }

    If any stored value in admin_menus['sub'] does not contain the expected placeholder, $submenu_list[1] is undefined and this results in an “Undefined array key” warning and inconsistent submenu handling in the admin area.

    We suggest adding defensive checks around the explode() result, for example:

    if (isset($setting_admin_menus['sub']) && is_array($setting_admin_menus['sub'])) {
    foreach ($setting_admin_menus['sub'] as $submenu_item) {
    /*
    $submenu_list = explode($this->get_submenu_placeholder(), $submenu_item);
    $main_menu = $submenu_list[0];
    $main_submenu = $submenu_list[1];
    $this->remove_submenu_page($main_menu, $main_submenu);
    */

    $submenu_list = explode($this->get_submenu_placeholder(), (string) $submenu_item, 2);

    if (count($submenu_list) < 2 || empty($submenu_list[0]) || empty($submenu_list[1])) {
    continue;
    }

    $main_menu = $submenu_list[0];
    $main_submenu = $submenu_list[1];
    $this->remove_submenu_page($main_menu, $main_submenu);
    }

    $this->fix_woocommerce();
    $this->fix_yoast($setting_admin_menus['sub']);
    }

    This change ensures that only well-formed submenu definitions are processed, and prevents the undefined array key warnings when invalid or legacy data is present in the stored settings.

    Please let us know if you need additional details (WordPress version, PHP version, or full warning message) to reproduce and confirm the issue.

Viewing 1 replies (of 1 total)
  • Thread Starter diweb

    (@diweb)

    Just a quick follow‑up on this report.

    After more in‑depth debugging, we’ve confirmed that the PHP warning:

    PHP Warning: Undefined array key 2 in /wp-admin/includes/plugin.php on line 2020

    was not caused by White Label CMS.

    The issue on our installation turned out to be another component adding malformed entries to the global $submenu array, specifically items that only contained something like:

    array(
    4 => 'some-css-class',
    );

    with no slug at index [2]. When WordPress core iterates over submenu and expects $item[2] to exist, this structure triggers the Undefined array key 2 warning.

    White Label CMS was initially suspected because it also manipulates admin menus, and we had added a custom MU plugin around WLCMS_Admin_Menus to harden its menu handling under PHP 8+. However, after adding a separate MU plugin that logs malformed submenu items, all the problematic entries we saw were coming from outside White Label CMS.

    So, to be precise:

    • White Label CMS is not the source of the Undefined array key 2 warning we reported earlier.
    • Our custom hardening around WLCMS is working fine, but it was not the component breaking WordPress core’s submenu iteration.

    Apologies for the earlier noise and for pointing in the wrong direction.
    You can safely disregard the previous assumption that WLCMS’ submenu handling was causing this particular PHP warning.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.