How to append_contents using WP_Filesystem?

I have scenario that appends the contents into the files, I was using normal file system function of PHP
Now I have decided to use WordPress WP_Filesystem but I cannot see any methods of it which do append the contents into the files.
It has only the put_contents(), Is there any way to append the file content using WordPress’s FS?

1 Answer
1

WP_Filesystem abstraction is primarily meant for performing plugin/theme/core updates, especially in environments with restricted writes.

As such it doesn’t really implement full range of possible file operations, as you noted there is no ability to write to the end of file in declared API. More so some possible implementations (depending on file system) might not even be capable of writing to the end of file.

In a nutshell you’ll have to take care of this logic yourself and it would depend a lot on it being private/public code and how widely compatible you want it to be. If you stick with uploads destination in WP context it has the maximum chances of being writable with direct filesystem access (which WP core itself still uses for many operations).

Leave a Comment