2013-09-23 72 views
0

我面临错误/警告非法字符串偏移量Wordpress中的非法字符串偏移量警告

我检查了我的所有代码,但没有找到错误原因。 具有以下功能我的主题风格正在运行代码是在word.php中的单词按主题编写的。 (!)

尖叫:错误抑制忽略 警告(!):非法串F中偏移 '面子':\ WAMP \ WWW \ WordPress的-3.6.1-newsduke \可湿性粉剂内容\主题\ hotnews \在线功能\主题的functions.php 140

function freshthemes_theme_styles() { 

     /* Google fonts array */ 
     $google_fonts = array_keys(freshthemes_typography_get_google_fonts()); 

     /* Define all the options that possibly have a unique Google font */ 
     $body_font = ft_get_option('body_font', 'Arial, Helvetica, san-serif'); 
     $heading_font = ft_get_option('heading_font', 'Arial, Helvetica, san-serif'); 
     $menu_nav_font = ft_get_option('menu_nav_font', 'Arial, Helvetica, san-serif'); 

     /* Get the font face for each option and put it in an array */ 
     $selected_fonts = array(
      $body_font['face'], 
      $heading_font['face'], 
      $menu_nav_font['face'], 
     ); 

     /* Remove any duplicates in the list */ 
     $selected_fonts = array_unique($selected_fonts); 

     /* If it is a Google font, go ahead and call the function to enqueue it */ 
     foreach ($selected_fonts as $font) { 
      if (in_array($font, $google_fonts)) { 
       freshthemes_typography_enqueue_google_font($font); 
      } 
     } 

     // Register our styles. 
     wp_register_style('main', get_stylesheet_uri(), false, THEME_VERSION, 'all'); 
     wp_register_style('prettyPhoto', THEME_DIR . '/stylesheets/prettyPhoto.css', false, THEME_VERSION, 'all'); 
     wp_register_style('responsive', THEME_DIR . '/stylesheets/responsive.css', false, THEME_VERSION, 'all'); 
     wp_register_style('custom-style', THEME_DIR . '/functions/framework/frontend/custom-style.css', false, filemtime(THEME_PATH . '/functions/framework/frontend/custom-style.css'), 'all'); 

     // Enqueue them. 
     wp_enqueue_style('main'); 
     wp_enqueue_style('custom-style'); 
     wp_enqueue_style('prettyPhoto'); 
     wp_enqueue_style('responsive'); 
    } 
+1

我觉得很难相信'互联网和搜索engines'没有为'警告列出任何内容:非法串offset' ? – AlexP

+0

对不起,但没有找到有用的答案 –

+0

var_dump($ body_font,$ heading_font,$ menu_nav_font)显示什么? – anupam

回答

2

尝试:

$selected_fonts = array(
    $body_font, 
    $heading_font, 
    $menu_nav_font, 
); 

至于$ body_font,$ heading_font和$ menu_nav_font是字符串,使用这些作为数组会产生警告。

编辑:

更通用的:

$selected_fonts = array(
    is_array($body_font) && isset($body_font['face']) ? $body_font['face'] : $body_font, 
    is_array($heading_font) && isset($heading_font['face']) ? $heading_font['face'] : $heading_font, 
    is_array($menu_nav_font) && isset($menu_nav_font['face']) ? $menu_nav_font['face'] : $menu_nav_font, 
); 
3
$selected_fonts = array(
    $body_font['face'], 
    $heading_font['face'], 
    $menu_nav_font['face'], 
); 

一个或一个以上这些变量是一个字符串,您试图访问类似于数组,这仅适用,如果你访问它用数字键slammer比strlen-1

要确认这一点,做一个var_dump($body_font, $heading_font, $menu_nav_font)也检查哪一个实际上不是一个数组,而是一个字符串。

+0

var_dump显示“string”Arial,Helvetica,san-serif'(长度= 27)“三次。 –

+0

好吧,那么我的假设是正确的,你有一个非法的抵消,因为你试图访问一个'字符串'就好像它是一个'数组' – NDM

+0

当然给我你的电子邮件地址,以及你的任务列表,主席先生,明天中午之前,我会通过电子邮件通知您完整的项目 – NDM

相关问题