2015-10-23 58 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文件系统或解决方法)。

相关问题