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 do something like this:
$homedir = $wp_filesystem->abspath();
To get the equivalent of the ABSPATH on the other filesystem.
Related Posts:
- Creating directory in uploads – wp_mkdir_p() or WP_Filesystem?
- Convenient way to use wp_filesystem
- What dependencies should I load and to use the WP_Filesystem?
- temphangle variable missing when using wp_filesystem copy
- Should I use Filesystem API for reading files or listing directories?
- Does unzip_file() over-write by default?
- Is there a WP Way of getting a filehandle?
- Moving wp-content outside of web root?
- $wp_filesystem returns NULL. What are the dependencies?
- How do I edit the php/html for a particular post?
- Setting wp_temp_dir and permissions not working for “Missing A Temporary Folder” error
- What is the best way to move a plugin´s subdirectory+files to wp-content/uploads-directory?
- Relative file paths in CSS when linking directly (not enqueuing)
- Is fopen() forbidden in WP?
- How to check if txt file exists inside template folder?
- Can I delete `wp-config-sample.php` after installing and configuring WordPress?
- Is it bad to store many files in a single folder?
- External pages redirecting back to wordpress
- WordPress Login doesnt respond after using Filezilla to upload my files on the server
- List of files/folders writable by the web server?
- Save PDF File From Plugin to Filesystem /wp_upload
- accessing files in custom folder in wordpress
- How to replace file_get_contents() with a WordPress Filesystem call
- What files are safe to delete after a security breach in WP content folder?
- Running rmdir function on post save
- WordPress Creates Unused (Unregistered) Image Sizes
- Failed opening required
- Right way to download file from source to destination
- Correct file permissions for in-browser updates using WP-CLI
- WordPress installation on digitalocean eating the server storage
- How to prevent users to view server files using WP File Manager plugin?
- Serve contents from Nextcloud / WebDAV
- File ownership for file tree php user ID – Folder permission 775
- How to write to a text file and save it in a folder for later download?
- 403 Error on “/”
- Get names and paths from unzip_file()
- Downloadable content file structure
- saving file to external server vip
- Time limited file download upon form submit
- How do I upload my WordPress code files from previous website onto local host WordPress website?
- WordPress – tracking options
- Standard location for plugin to save/cache files?
- add/apend templates ‘transparently’ via plugin to currently active theme or child theme?
- delete uploaded file
- Copy a file from a plugin into my theme directory
- Can’t access wp_filesystem in cron function
- What exactly does $wp_filesystem->abspath() return?
- Necessary user, group and permissions for core updates
- Use WP_Filesystem to list files in directory
- Which actions can update/change .php files?
- sanitize attachment filename
- Using wp_filesystem in Plugins to store customizer settings
- Where is Featured Image code stored in WP?
- Uploading Media gives error “Missing a temporary folder.”
- Downloading File from Outside Web Root
- What are the hierarchy of filenames while initialising a WordPress plugin?
- Securing a multi-user permission structure
- Files automatically added
- WordPress HTTP Error on File upload
- Plugin writing: access file that was just uploaded
- How to implement filesystem cache in WordPress
- Image URLs stopped working due to Permalinks?
- Unable to check if image uploaded by wp_image_editor exists using file_exists function
- Is file_get_contents() the only way for plugins reading local files OR does WP_Filesystem_Direct::get_contents() even work?
- Where to write custom logs in WordPress
- How to block access to files without modifying .htaccess or ngnix config? [closed]
- wp_filesystem put_contents issue with owner/group
- Why is server preventing admin styles? (Was: Where are WordPress sessions saved?)
- How does WordPress access theme and plugin files through its editor?
- How to edit php code in WordPress Post file?
- Why does WP load so many files in the head of source code? How do I optimize it?
- Adding regular php file to site
- What functions of WP_Filesystem allow me to create a file with code-generated contents in a directory?
- Is there a name for trivial WP PHP files like functions.php, archive php entry.php, page.php and so forth?
- Removing the references to the wp-content folder
- Why WordPress not using WP_Filesystem
- Cleaning a filename after image sideloading a url that contains `%20`
- Generating and downloading files with WP API
- unzip_file not working with the remote file
- How can I create a WordPress dynamic download counter
- Admin Custom Plugin List Files in admin Table
- How can I add a method to create files when in theme-editor.php
- how to get json file in wordpress template
- Add `manifest.json` file to a Custom WordPress Theme
- Unzip_file causing Media file upload error
- Creating an .ics calendar subscription service with wordpress
- How to include all files within a folder & its sub folders to functions.php?
- How to Call Function From Separate WordPress Install on Same Server?
- Why does unzip_file always return true but nothing happens?
- FS method direct on NGINX
- Using external file with WP_USE_THEMES set to false causing 404
- how to create or rewrite files in wordpress plugin folder
- Displaying $_FILES data (simlar to $_POST)
- wp_redirect to file:// location results in blank page/cannot be displayed page
- Upgrading WordPress (File permission group owner)
- Accessing a file saved outside webroot in a wordpress post
- Hook on opening a media/document
- Media Library Issues
- Is there a way to natively return the full filesystem path when using $wp_styles?
- Is there a way to get a path to the theme directory without the server name?