The scenario
I’m developing a plugin, and part of it requires lots of text content (help descriptions) that I would prefer to keep as separate text files (in a subdirectory within the plugin) for organisational and version control purposes. The obvious candidate would be file_get_contents()
, but its usage with WordPress is generally frowned upon. I’ve looked at some alternatives, such as wp_remote_get()
(not the right one as the files are in the plugin) and the WP_Filesystem
API (which seems overkill for a simple reading of text files). Is there a simple, but secure alternative? I have the nagging feeling I’m missing something very obvious.
The spec
I’m looking for a solution to:
- Read the contents of a HTML/text file into a variable
- That won’t flag as insecure when used with Theme Check or similar plugins
- Doesn’t require any writing to the files whatsoever