wp-cli / scaffold-command

Generates code for post types, taxonomies, blocks, plugins, child themes, etc.
MIT License
165 stars 87 forks source link

Allow scaffolding without WordPress being present #157

Open swissspidy opened 6 years ago

swissspidy commented 6 years ago

I don't see why a command like wp scaffold plugin-tests should require WordPress to be loaded. Using WP_Fileystem to copy/create a bunch of files seems unnecessary in this case IMO.

schlessera commented 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.

swissspidy commented 6 years ago

Some context: https://wordpress.slack.com/archives/C02RP4T41/p1529483149000520

BrianHenryIE commented 4 months ago

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.

swissspidy commented 4 months ago

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.