I am utilizing composer w/ PSR-4 autoloading in a Wordpress plugin. No probs.
I went to use the WP_Filesystem_Direct
class to remove a directory in a certain circumstance, but I found that I HAD to include 3 Wordpress classes manually using require
in order to get things to work as expected.
Can anyone explain why I had to require them, and simply using
them wouldn't work?
The following is the code that worked:
namespace Cre\API;
use \WP_Filesystem_Direct;
class ThingSync extends Sync
{
public function checkPostProcessTasks()
{
// Why do I need this, and 'using' them above the class won't work?
require_once(ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php');
require_once(ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php');
require_once(ABSPATH . '/wp-includes/class-wp-error.php');
if (get_option('deleteDir') !== "on") {
$fs = new WP_Filesystem_Direct(false);
$fs->rmdir(IMAGE_PATH, true);
}
}
}