Usage of file_get_contents and file_put_contents in a WP plugin

wordpress
tips-and-tricks
#1

Hi

In a new WordPress plugin I am developing, I need to read/write a file inside this plugin directory (so internally, no external urls or files).

I do not want to use the global $wp_filesystem ( the WP_Filesystem class) to read and write my file, because there is no need to ask for FTP credentials, or user id and password from the user.

I just need to read/write the file internally.

The plugin Plugin Check reports a warning for usage of file_get_contents…so my question is:

are file_get_contents and file_put_contents allowed by Envato reviewers in a WordPress plugin?

#2

I used file_get_contents and file_put_contents in one of my WordPress plugins here about 2 years ago, and it was approved.

Officially, WordPress does provide their own methods for this, but if it will hassle your users then definitely use PHP’s native file functions.