我在我的主题中使用来自Easy Theme Child插件的代码,但主题检查插件失败并出现以下错误:
WARNING: fopen/fwrite was found in the file grtsth-easy-child-theme-resources.php and resources.php File operations should use the `WP_Filesystem` methods instead of direct PHP filesystem calls.
所以我尝试转换问题代码:
$create_style_css = fopen( $file_style_css, 'w+' );
$create_function_php = fopen( $file_function_php, 'w+' );
fwrite( $create_style_css, $stylesheet_data );
fwrite( $create_function_php, $function_php_data );
至:
WP_Filesystem();
global $wp_filesystem;
$create_style_css = $wp_filesystem->get_contents($file_style_css);
$create_function_php = $wp_filesystem->get_contents($file_function_php);
$wp_filesystem->put_contents($create_style_css, $stylesheet_data);
$wp_filesystem->put_contents($create_function_php, $function_php_data);
但是,它不起作用。没有错误。只是不创建子主题文件。我不是很熟悉WP_Filesystem,所以有什么想法我做错了吗?
谢谢
四季花海
慕容708150