0

I'm using code from the Easy Theme Child plugin in my theme, but it fails the Theme Check plugin with the following error:

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.

So I tried converting the problem code:

$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 );

to:

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);

However, its not working. No errors. Just not creating the child theme files. I'm not very familiar with WP_Filesystem, so any ideas what I'm doing wrong?

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.