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/) –