• Resolved rtpHarry

    (@rtpharry)


    When I click the “Add to menu” button within the Search Box accordion item on nav-menus.php I see the following errors:

    Notice: Undefined variable: _object in /srv/www/basetemplate/htdocs/wp-admin/includes/ajax-actions.php on line 1091
    
    Notice: Trying to get property of non-object in /srv/www/basetemplate/htdocs/wp-admin/includes/ajax-actions.php on line 1095

    Note: I have define( 'WP_DEBUG', true ); set in my wp-config.php.

    When I save and look at the site front end I see the search box in the menu and it seems to work.

    https://www.ads-software.com/plugins/bop-search-box-item-type-for-nav-menus/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter rtpHarry

    (@rtpharry)

    Looking at this some more it seems that it is a bug with WP that assumes there will only ever be three types of menu-item-type, or at least doesn’t check that the $_object exists before it tries to use it.

    Plugin Author joe_bopper

    (@joe_bopper)

    Thanks for drawing this to my attention.

    This is happening due to a bit of rubbishness in the wordpress core code. The code doesn’t declare the $_object variable and then proceeds to define $_object in a switch statement without a default choice. This leads to the notice you are seeing for strict error reporting.

    The trouble with this output is that it distracts the ajax call from the desired return. If you leave the admin menus page and return, you’ll find it has added the search box.

    I will try to find a workaround resolution to this and post up a new version soon.

    Cheers.

    Thread Starter rtpHarry

    (@rtpharry)

    Yeah I agree, I’ve been digging around and it seems like its been a known issue for two years:

    https://core.trac.www.ads-software.com/ticket/23805#comment:3

    There is a one-liner which would fix it but it needs to be done in the core.

    Unless there is a way to override the ajax call in the admin panel and use your own I think you might just have to wait for WP to fix the bug.

    Plugin Author joe_bopper

    (@joe_bopper)

    I think I’ve found a solution but am having server connection issues at the moment; will have to check tomorrow morning (UK) instead.

    Basically the fix involves checking if the core php ajax action in admin-ajax.php on line 72 and ajax-actions.php on line 1063 is registered. Then, if it isn’t registered, add my own action first; else, remove the core action, add mine and then re-add the core action. (I think this is the best way to not potentially interfere with other plugins).

    My action then checks if the menu item type is a search box and, if so, process some nice code that works before issuing wp_die(). Otherwise, do nothing and move onto the next hooked action (presumably the core one).

    Thanks again for letting me know about this and I’ll send an update tomorrow.

    Plugin Author joe_bopper

    (@joe_bopper)

    Hi,

    I’ve updated the plugin now to work around the core function.

    Cheers.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Errors when adding search box to menu’ is closed to new replies.