Converting fopen/fwrite operations to WP_filesystem

The get_contents function returns the contents of the file, not a file handle. Using put_contents with $f after that is incorrect. Try $wp_filesystem->put_contents( $htaccess_file, $htaccessnew, FS_CHMOD_FILE ) instead. Also, it’s not necessarily safe to use things like “get_home_path” and such with the WP_Filesystem. The remote path may not match the local path. You’ll need to … Read more

Is fopen() forbidden in WP?

File system access is tricky thing between different possible server configurations. If you need to implement it reliably in WP you should look into its API for such. See Using the WP_Filesystem.

Creating directory in uploads – wp_mkdir_p() or WP_Filesystem?

wp-content/uploads/ should be writable for the server (otherwise it would be impossible to upload a file, no?). If you are going to create something under this directory, it is safe to use wp_mkdir_p(). I would only use WP_Filesystem if there is a chance the server does not have permissions to write to the location, like … Read more