【问题标题】:Wordpress undefined index notice in child theme子主题中的 Wordpress 未定义索引通知
【发布时间】:2013-09-11 11:30:39
【问题描述】:

当我在我的 wordpress 子主题中向我的菜单添加项目时,我收到此错误;

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

我的完整基础主题函数文件的链接在这里; (同样,我没有触摸/写/那个。) http://codepad.org/dAx0DlLz

这是我基本主题中的第 546 行;

// Save the Data  

函数 save_homepage_meta($post_id) {
全局 $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;  
}  

这正好在第 546 行;

if (!wp_verify_nonce($_POST['custom_meta_box_nonce'], basename(__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'
        )
    );
}

 ?>

为什么会出现此错误?我没有对我的基本主题的功能文件进行任何更改,并且在将多个菜单内容添加到我孩子的功能文件之前没有收到此错误。

【问题讨论】:

  • 您是否在自定义元框中添加随机数?也显示元框
  • 我添加了一个指向我使用的基本主题的完整函数文件的链接,但我没有编辑该函数文件,它带有名为“wp-foundation”的基本主题。
  • 当您将搜索和导航功能添加到子主题时,save_homepage_meta 中出现错误?您添加的代码无论如何都不会影响 save_post...检查插件必须被覆盖
  • 我没有添加任何与菜单或保存帖子有关的插件...当我单击保存或添加项目时,错误出现在您可以添加新菜单的屏幕中到菜单。
  • 如果您尝试保存菜单..那么它也在保存帖子..它不应该发生..某些页面检查中钩住了一些东西!..

标签: php wordpress wordpress-theming


【解决方案1】:

对于undefined index 通知,通常解决方案是使用isset()

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

【讨论】:

  • 不幸的是,在我的网站上工作后,我再次遇到完全相同的错误,isset 的事情不再解决了..
  • 表示我昨天在主主题的函数文件中添加了isset的东西后,编辑了我的子主题和子主题的函数文件。消息说错误再次出现在主题的函数文件中,即使我没有触摸主题的函数文件,我也看不到它如何再次给出相同的错误......
  • 问题中有什么可以更新的吗?都是一样的吗?
  • 除了我的子主题的功能文件之外的所有内容,但它说问题出在主主题的功能文件中。我将再次检查我以前的主功能文件,看看我是否忘记编辑某些内容。 .. -- 我在文件顶部编辑了一条信用线,这是新版本; codepad.org/rVTqQ77I
  • 抱歉,解决方案是使用isset。仔细检查名称是否有错别字。通知并不那么重要,当然最好不要拥有它们。您可能在 wp-config.php 中启用了WP_DEBUG,在实时站点中,您应该将消息重定向到带有LOG and DISPLAY options 的文件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-16
  • 1970-01-01
  • 2020-01-06
  • 2012-09-26
  • 2022-10-13
  • 1970-01-01
相关资源
最近更新 更多