In a WordPress plugin, this does NOT work
<?php
/**
* Plugin Name: test
* Plugin URI: _
* Description: _
* Version: 0.0.1
* Author: _
* Author URI: _
* License: GPL-2.0+
* License URI: _
* Text Domain: _
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
But this DOES work
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
Where inside class-wp-filesystem-direct
you can see that it extends from class-wp-filesystem-base
Why do I need to require the two libraries?
The error was
Fatal error: Uncaught Error: Class 'WP_Filesystem_Base' not found in /home/..../domains/..../public_html/wp-admin/includes/class-wp-filesystem-direct.php:16
The require statement works exactly as it's supposed to, the problem is what you're loading in. It has dependencies that are unmet, and depends on other things that aren't loaded.
Loading class-wp-filesystem-direct.php
will load the things in that file, but it won't go searching for other things it needs. WordPress doesn't use PHP autoloading
So some notes:
Your problem is that you can't just include random files in WP Admin, they have dependencies that need to be included beforehand.
So your require statement works fine,