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_contents
到WP_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;
}
分享你的新代码不工作?看着[WP_filesystem](https://codex.wordpress.org/Filesystem_API)文档,它的一个类不是一个函数。所以它不是一个简单的替换。该API允许基于FTP的文件更改,如果代码正在处理的服务器设计为不允许php更改文件。 – Practically
我在一篇博客中读到说,将file_get_contents替换为WP_Filesystem [Here](http://www.wrock.org/resolve-wordpress-theme-check-issue/) –