As of yesterday, when I changed two of the submenu items in my site’s main navigation menu, I have been getting the following error in the Wordpress debug log. I have not edited the plugin file that the error refers to. Please let me know what can be done to resolve this error.
PHP Notice: Undefined index: menu-item in /wp-content/plugins/shapely-companion/inc/shapely-navmenu.php on line 81
Thanks
Note: For issue replication/debugging purposes, I will post a private reply with the login credentials for a temporary user.
I hope you are well today and thank you for your question.
I logged in but I’m not seeing any PHP error, also you’ll need to set the user to admin so I can assist you.
Kindly update the created user to admin, and let us know if you still need our assistance.
I’ve updated the temporary user to the role of administrator.
I’ve also included screenshots of the error as it appears in the admin area (also being logged in the debug log). The issue can be replicated when saving or updating any menu. Changes to the menu do not have to be made - just clicking the “Save” button alone will cause the error to display. When the error appears in the admin backend, the beginning of it will be covered by the admin toolbar, but I’ve unveiled the full error using the browser inspector and included it in the second screenshot I’ve attached.
Please note that the website is in development and any content you view is strictly confidential at this point and property of the International Matrix Management Institute, Inc. You do not have permission to make any alterations to the site.
Can you please try to set the debugger to “false” in wp-config.php:
define( ‘WP_DEBUG’, false ); and try again, more information can be found here: WP DEBUG « WordPress Codex
The debugger is purposely turned on while the site is in development so that I can identify any errors before the site launches. Turning off the debugger would essentially be the same as sweeping the issue under the carpet - the error would still be there, just not visible. The codex even highly recommends that WP_Debug is turned on while in development (Debugging in WordPress « WordPress Codex). My point of posting here was to determine what in the plugin’s code is causing the error and what can be done to resolve it.
It appears that the issue is with the function, “shapely_update_menu_item” inside the plugin file, “shapely-navemenu.php” (/wp-content/plugins/shapely-companion/inc/shapely-navmenu.php). I actually resolved this today on my own by testing whether the table’s fields were set before being indexed using isset(). The new and old code are included below.
NEW CODE (starting on line 79 of shapely-navemenu.php):
function shapely_update_menu_item( $menu_id, $menu_item_db_id, $args ) {
// Before using $_POST['value']
if (isset($_POST['menu-item'])) {
// Instructions if $_POST['value'] exist
if ( count( $_POST['menu-item'] ) == 1 ) {
if ( isset( $_POST['menu-item']['-1'] ) ) {
$menu_item = $_POST['menu-item']['-1'];
if ( isset( $menu_item['menu-item-extra'] ) && 'shapely-section' == $menu_item['menu-item-extra'] ) {
update_post_meta( $menu_item_db_id, '_menu_item_extra', 'shapely-section' );
}
if ( isset( $menu_item['menu-item-widget'] ) ) {
update_post_meta( $menu_item_db_id, '_menu_item_widget', sanitize_text_field( $menu_item['menu-item-widget'] ) );
}
}
}
}
}
OLD CODE (error causing, starting on line 79 of shapely-navemenu.php):