• Resolved spinips

    (@spinips)


    I just installed your plugin and entered a snippet with this function:

    function my_custom_menu_item( $items, $args ) {
        if ( function_exists ( 'the_msls' ) && 'Primary Navigation' == $args->theme_location ) {
            $obj = new MslsOutput;
            $arr = $obj->get( 2 );
            if ( !empty( $arr ) ) {
                $items .= '<li>' . implode( '</li><li>', $arr ) . '</li>';
            }
        }
    
        return $items;
    }
    add_filter( 'wp_nav_menu_items', 'my_custom_menu_item', 10, 2 );

    but wordpress collapsed with this message:

    Fatal error: Cannot redeclare my_custom_menu_item() (previously declared in /web/htdocs/www.spinips.com/home/wp-content/plugins/functions.php:13) in /web/htdocs/www.spinips.com/home/wp-content/plugins/code-snippets/code-snippets.php(1103) : eval()’d code on line 11

    I found then your instruction for safe mode, but I still don’t understand why it crashed, since I used that function for my previous theme (without multisite). Any suggestion?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter spinips

    (@spinips)

    And maybe this is a stupid question, but how can I be sure to have fixed the function and that this function is working good if I’m in safe mode?

    Plugin Author Shea Bunge

    (@bungeshea)

    The error occurs because you have the exact same code in a snippet as in your functions.php. PHP requires function names to be unique, so you cannot have the same one twice.

    You can fix the error by renaming the function:

    function my_custom_menu_item_unique( $items, $args ) {
        if ( function_exists ( 'the_msls' ) && 'Primary Navigation' == $args->theme_location ) {
            $obj = new MslsOutput;
            $arr = $obj->get( 2 );
            if ( !empty( $arr ) ) {
                $items .= '<li>' . implode( '</li><li>', $arr ) . '</li>';
            }
        }
    
        return $items;
    }
    add_filter( 'wp_nav_menu_items', 'my_custom_menu_item_unique', 10, 2 );

    After you have updated the code, simply disable safe mode and activate the snippet to check if it works.

    Thread Starter spinips

    (@spinips)

    Thank you, fixed! Although the function hasn’t got the wished effect…

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘not working – multisite’ is closed to new replies.