Automattic / sensei

Sensei LMS - Online Courses, Quizzes, & Learning
https://senseilms.com
GNU General Public License v2.0
539 stars 198 forks source link

PHP Notice when using Nav Menu Roles plugin #2329

Open lkraav opened 5 years ago

lkraav commented 5 years ago

In menu editor, Sensei is passing weird objects into wp_setup_nav_menu_item filter.

https://developer.wordpress.org/reference/functions/wp_setup_nav_menu_item/ clearly states: "object_id: The DB ID of the original object this menu item represents, e.g. ID for posts and term_id for categories."

Instead, this is what Sensei sends:

stdClass Object
(
    [object_id] => #senseicourses
    [title] => Courses
    [url] => #senseicourses
    [description] => description
    [db_id] => 0
    [object] => sensei
    [menu_item_parent] => 0
    [type] => custom
    [target] => 
    [attr_title] => 
    [classes] => Array
        (
        )

    [xfn] => 
)

Then PHP Notices occur when filter callbacks are expecting a real ID property to exist https://github.com/helgatheviking/Nav-Menu-Roles/blob/1.9.2/nav-menu-roles.php#L422

Steps to Reproduce

  1. Install, activate plugin: Nav Menu Roles
  2. Edit any menu at /wp-admin/nav-menus.php
  3. See PHP Notice [20-Nov-2018 12:42:38 UTC] PHP Notice: Undefined property: stdClass::$ID in wp-content/plugins/nav-menu-roles/nav-menu-roles.php on line 422

What I Expected

No weirdness

What Happened Instead

Weird objects transmitted

PHP / WordPress / Sensei version

7.2 / 4.9.8 / 1.12.2

Screenshot / Video

Context / Source

Full stack:

nav-menu-roles.php:422, Nav_Menu_Roles->setup_nav_item()
class-wp-hook.php:286, WP_Hook->apply_filters()
plugin.php:203, apply_filters()
nav-menu.php:906, wp_setup_nav_menu_item()
class-sensei-admin.php:1638, array_map()
class-sensei-admin.php:1638, Sensei_Admin->wp_nav_menu_item_sensei_links_meta_box()
template.php:1193, do_accordion_sections()
nav-menus.php:735, {main}()

Must investigate https://github.com/Automattic/sensei/blob/version/1.12.2-beta.1/includes/class-sensei-admin.php#L1638

lkraav commented 5 years ago

Original commit is https://github.com/Automattic/sensei/commit/6d9d7cdb5f8be9b7912e1538b3cf5764b741fb1b from 5 years ago. @danjjohnson do you happen to remember anything about it?

jimyaghi commented 5 years ago

i'm having a similar issue, but i do not use Nav Menu Roles plugin. The warning occurs when all plugins are disabled except for Sensei LMS and Orbitfox Companion and on the Menu Editor page. In the menu editor page, Orbitfox Companion attempts to show the menu and triggers the filter which subsequently gets some weird menu object that has no ID value and throws these warnings.

donnapep commented 5 years ago

I wasn't able to reproduce this with the Nav Menu Roles plugin, but was able to with the OrbitFox plugin.