Support » Plugin: Shortcode in Menus » PHP Notices

  • Resolved dhunink

    (@dhunink)


    Hi,

    having WP Debug set to True and PHP Warnings enabled, the plugin turns out to generate a warning. Hopefully that’s one with an easy fix.

    The issue origins from line 124 on the file /includes/class-shortcode-in-menus.php.
    It looks this line is testing for a property of the $item object that’s not present.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Gagan Deep Singh

    (@gagan0123)

    @dhunink

    Thank you for reporting the issue.

    Can you provide some more detail about which theme is being used and which WordPress version are you using?

    Also, can you list other plugins that are being used on the sites for menus?

    On line 124, a function is overriding the default behaviour of menus via filter and as per documentation, the filter walker_nav_menu_start_el should be providing $item object.
    https://developer.wordpress.org/reference/hooks/walker_nav_menu_start_el/

    If some other plugin is generating menus, without adhering to WordPress’ standard, and not providing that object, then it would be causing the warning.

    In the meantime I’ll add an additional check in the plugin to see if the $item object has certain properties or not, to rectify this issue.

    Hi!
    I’ve done some more debugging and nailed it down to specific situation where there’s no menu set for a menu location. Happens a lot when the plugin is installed on a new installation where the user did not yet created menu’s and/or assigned these menu’s to a menu location.
    In that case the $item object is indeed empty, which is normal behavior. But the code always assumes the $item object consists of something.
    My suggestion:
    add a simple check in the function that checks if the $item object has the desired content. If not, the function does not need to continue.

    hbwarper

    (@hbwarper)

    Replacing :
    if ( 'gs_sim' !== $item->object ) {
    with:
    if (!isset($item->object) || $item->object !== 'gs_sim'){

    and replacing
    if ('FULL HTML OUTPUT' === $item->post_title ) {
    with
    if (isset($item->post_title) && 'FULL HTML OUTPUT' === $item->post_title ) {

    In the file: wp-content/plugins/shortcode-in-menus/includes/class-shortcode-in-menus.php
    Stops this plugin from filling the log with thousands of error lines per day.

    dhunink

    (@dhunink)

    @gagan0123 are you looking to fix this, following the suggestion made by @hbwarper?

    Plugin Author Gagan Deep Singh

    (@gagan0123)

    @dhunink

    Yes, I’ll be adding this patch and will provide an update by tomorrow.

    @hbwarper

    Thanks for the patch 🙂 , would it be okay if I use your name in the list of contributors for the plugin?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘PHP Notices’ is closed to new replies.