Open swissspidy opened 6 years ago
The reason why commands like this use WP_Filesystem
is because we want to adhere to all permissions/security settings on the server that were configured for WordPress. Otherwise, we might create files with too lax permissions that are directly accessible from the web.
wp scaffold plugin
works if you add this to the beginning of the function.
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' );
define( 'WPINC', 'wp-includes' );
require_once ABSPATH . 'wp-includes/functions.php';
require_once ABSPATH . 'wp-includes/load.php';
require_once ABSPATH . 'wp-includes/formatting.php';
require_once ABSPATH . 'wp-includes/plugin.php';
require_once ABSPATH . 'wp-includes/l10n.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
In my case, I do have the WordPress files present, but I don't have a database connection.
A blast from the past 😄
So my original issue was that I wanted to scaffold a plugin in an arbitrary location, without having a WordPress install. But if WP is detected, using the filesystem functions make sense. Right now that's not possible though.
I don't see why a command like
wp scaffold plugin-tests
should require WordPress to be loaded. UsingWP_Fileystem
to copy/create a bunch of files seems unnecessary in this case IMO.