2015-10-23 80 views
1

我正在使用wordpress主題。它幾乎完成。當我在主題檢查檢查插件它給予警告當我將file_get_contents更改爲WP_Filesystem時,它不起作用

WARNING: file_get_contents was found in the file sources.php File operations 
should use the WP_Filesystem methods instead of direct PHP filesystem calls. 
Line 84: $fonts = file_get_contents(dirname(__FILE__) . '/gwf.json'); 

然後我改變file_get_contentsWP_Filesystem但沒有得到值或不工作。

這裏是線84的代碼:

function vp_get_gwf_family() 
{ 
    $fonts = file_get_contents(dirname(__FILE__) . '/gwf.json'); 
    $fonts = json_decode($fonts); 

    $fonts = array_keys(get_object_vars($fonts)); 

    foreach ($fonts as $font) 
    { 
     $result[] = array('value' => $font, 'label' => $font); 
    } 

    return $result; 
} 
+0

分享你的新代碼不工作?看着[WP_filesystem](https://codex.wordpress.org/Filesystem_API)文檔,它的一個類不是一個函數。所以它不是一個簡單的替換。該API允許基於FTP的文件更改,如果代碼正在處理的服務器設計爲不允許php更改文件。 – Practically

+0

我在一篇博客中讀到說,將file_get_contents替換爲WP_Filesystem [Here](http://www.wrock.org/resolve-wordpress-theme-check-issue/) –

回答

0

我是有wp_filesystem由於服務器上的安全設置中的問題,並最終改變:

global $wp_filesystem; 
    $file = $wp_filesystem->get_contents(get_template_directory() . '/assets/js/icomoon-selection.json'); 

到:

ob_start(); 
    include dirname(__FILE__) .'/../assets/js/icomoon-selection.json'; 
    $file = ob_get_contents(); 
    ob_end_clean(); 

也許它解決了您的警告(例如使用wp文件系統或解決方法)。

相關問題