Title: PHP 8 warning – Undefined array key 2 in Admin_Menus.php
Last modified: April 1, 2026

---

# PHP 8 warning – Undefined array key 2 in Admin_Menus.php

 *  [diweb](https://wordpress.org/support/users/diweb/)
 * (@diweb)
 * [2 months ago](https://wordpress.org/support/topic/php-8-warning-undefined-array-key-2-in-admin_menus-php/)
 * 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[](https://wordpress.org/plugins/white-label-cms/)
    - 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:
 *     ```wp-block-code
       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.[](https://wordpress.org/support/topic/undefined-array-key-2-in-menu-php/)
 * Suggested fix:
 *     ```wp-block-code
       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](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fphp-8-warning-undefined-array-key-2-in-admin_menus-php%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Support [VUM Support – Jhay](https://wordpress.org/support/users/jhayvum/)
 * (@jhayvum)
 * [1 month, 2 weeks ago](https://wordpress.org/support/topic/php-8-warning-undefined-array-key-2-in-admin_menus-php/#post-18878357)
 * 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](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fphp-8-warning-undefined-array-key-2-in-admin_menus-php%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/white-label-cms/assets/icon-256x256.png?rev=1977768)
 * [White Label CMS](https://wordpress.org/plugins/white-label-cms/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/white-label-cms/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/white-label-cms/)
 * [Active Topics](https://wordpress.org/support/plugin/white-label-cms/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/white-label-cms/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/white-label-cms/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [VUM Support – Jhay](https://wordpress.org/support/users/jhayvum/)
 * Last activity: [1 month, 2 weeks ago](https://wordpress.org/support/topic/php-8-warning-undefined-array-key-2-in-admin_menus-php/#post-18878357)
 * Status: not resolved