Skip to content

Filesystem

The FileSystem utility class provides a set of methods to interact with the WordPress filesystem.

Retrieving the filesystem

To retrieve the filesystem, use the get_wp_filesystem() method:

php
use Sematico\Metapress\Utils\FileSystem;

$filesystem = FileSystem::get_wp_filesystem();

This will return an instance of the WP_Filesystem_Base class, which provides a set of methods to interact with the WordPress filesystem.

NOTE

Refer to the WordPress Codex for more information about the WP_Filesystem_Base class.

Setting up the logs directory

Metapress comes with a built-in logger that logs messages to one or more log files. These log files are stored in the wp-content/slug-logs directory. Where slug is the slug of your plugin.

To set up the logs directory, use the initialize_logs_directory() static method. This method will create the directory if it doesn't exist, and will set the appropriate permissions. The method requires the Plugin instance as a parameter.

php
use Sematico\Metapress\Utils\FileSystem;

FileSystem::initialize_logs_directory( $plugin );

It is recommended to call this method via the plugin activation class. For more information about the logger, refer to the logger documentation.