• Hi,

    On one of our sites we are repeatedly seeing the following warning in the server error log when accessing the WordPress admin:

    PHP Warning: Undefined array key 2 in
    /wp-content/plugins/white-label-cms/includes/classes/Admin_Menus.php on line 368

    Environment:

    • WordPress: 6.9.4
    • PHP: 8.3.30
    • White Label CMS: 2.7.8
    • Theme: JNews 12.0.4
    • Other relevant plugins: WooCommerce / Yoast / etc. (if applicable)

    Looking at the code of WLCMS_Admin_Menus::compile_menus(), it seems the plugin is accessing $menu_item[2] without checking that this index actually exists:

    foreach ( $menu as $menu_item ) {
    // some menu items are seperators, skip them
    if ( $menu_item[0] == '' ) {
    continue;
    }

    if ( $menu_item[2] == $sidebar_url ) {
    continue;
    }

    $menu_name = preg_replace('#(<span.*?>).*?(</span>)#', '', $menu_item[0]);
    $menu_key = $menu_item[2];
    ...
    }


    On PHP 8, whenever a $menu entry does not define index 2, this results in the exact warning mentioned above.

    Suggested fix:

    foreach ( $menu as $menu_item ) {
    if ( ! isset( $menu_item[0], $menu_item[2] ) ) {
    continue;
    }

    if ( $menu_item[0] === '' ) {
    continue;
    }

    if ( $menu_item[2] === $sidebar_url ) {
    continue;
    }

    $menu_name = preg_replace('#(<span.*?>).*?(</span>)#', '', $menu_item[0]);
    $menu_key = $menu_item[2];
    ...
    }

    Adding a simple isset() guard prevents the warning without changing the business logic, and only skips malformed menu entries.

    Could you please confirm whether this approach looks correct to you and if you plan to include a similar fix in an upcoming version of the plugin?

    Thanks in advance.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Support VUM Support – Jhay

    (@jhayvum)

    Hi,

    Thanks so much for sending this over, and thank you for continuing to support the plugin!

    Good news—we’ve already applied this fix in the latest version of the plugin. Go ahead and update, and that warning should be gone.

    Let us know if you still see it popping up after the update!

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.