0
votes

When I add items to my menus in my wordpress child theme I get this error;

Notice: Undefined index: custom_meta_box_nonce in /Users/x/Documents/Apart-1/website 3/wp-content/themes/wp-foundation/functions.php on line 546

A link to my full base theme's function file is here; (again, I did not touch/write/ that.) http://codepad.org/dAx0DlLz

This is around line 546 in my base theme;

// Save the Data  

function save_homepage_meta($post_id) {
global $custom_meta_fields;

// verify nonce  
if (!wp_verify_nonce($_POST['custom_meta_box_nonce'], basename(__FILE__)))  
    return $post_id;  
// check autosave  
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)  
    return $post_id;  
// check permissions  
if ('page' == $_POST['post_type']) {  
    if (!current_user_can('edit_page', $post_id))  
        return $post_id;  
    } elseif (!current_user_can('edit_post', $post_id)) {  
        return $post_id;  
}  

And this is exactly on line 546;

if (!wp_verify_nonce($_POST['custom_meta_box_nonce'], basename(__FILE__))) 

And this is in my child theme's function file;

    <?php
ob_start();
if ( function_exists( 'add_image_size' ) ) { add_image_size( 'orbit-custom', 920, 300 ); }

/**
 * Add a search bar to the navigation menu.
 *
 * @since Twenty Twelve 1.0
 */
function menu_search($items){
    $search = '<li class="menusearch">';
    $search .= '<form method="get" id="searchform" action="/">';
    $search .= '<input type="text" class="field" name="s" id="s" placeholder="Search" />';
    $search .= '<input type="submit" class="menusubmit" name="submit" id="searchsubmit" value="Search" />';
    $search .= '</form>';
    $search .= '</li>';

    return $items . $search;
}
add_filter('wp_nav_menu_items','menu_search');

// This adds multiple menu locations
add_action( 'init', 'register_multiple_menus' );
function register_multiple_menus() {
    register_nav_menus(
        array(
            'footer-nav-mid' =>  'Middle Footer Navigation',
            'footer-nav-left' =>  'Left Footer Navigation',
            'footer-nav-right' =>  'Right Footer Navigation'
        )
    );
}

 ?>

Why am I getting this error? I did not change anything to my base theme's function file and did not get this error before adding the multiple menu thing to my child's function file.

1
are u adding nonce to the custom meta box? show the metabox as wellB L Praveen
I added a link to the full functions file of the base theme I used, I did not edit that functions file though, it came complete with the base theme called 'wp-foundation'.Jane
error appeared in save_homepage_meta when u added to search and nav functions to child theme?code you added will not affect in anyway to the save_post... check the plugin must be overidedB L Praveen
I did not add any plugins that have anything to do with the menus or saving posts... The error appears in the screen where you can add new menus, the moment I click save or add an item to the menu.Jane
if you try to save the menu ..then it is also saving post..it should not happen.. something is hooked in some page check!..B L Praveen

1 Answers

2
votes

For undefined index notices normally the solution is using isset():

if ( 
    !isset( $_POST['custom_meta_box_nonce'] ) 
    || !wp_verify_nonce( $_POST['custom_meta_box_nonce'], basename(__FILE__) ) 
)