WordPress Filesystem class and connect
Initialize the WordPress Filesystem class and connect to the file system:
The heart of the WordPress Filesystem API is the WP_Filesystem function. It loads and initializes the appropriate transportation class, stores an obtained instance in the global $wp_filesystem object for further usage, and tries to connect to the filesystem with the provided credentials:
WP_Filesystem($args, $context);
Use the WordPress Filesystem methods to perform read/write operations:
A properly initialized $wp_filesystem object has a set of methods to communicate with the local file system that could be used without any further anxiety about connection type. In particular, there are following commonly used methods:
get_contents – reads the file into a string
put_contents – writes a string to a file
mkdir – creates a directory
mdir – removes a directory
wp_content_dir – returns the path on the local file system to the wp-content folder
wp_plugins_dir – returns the path on the local file system to the plugins folder
wp_themes_dir – returns the path on the local file system to the themes folder