2013-09-23 69 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

相關問題