Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 1, 2026

Scaffold commands previously required WordPress to be fully loaded, preventing scaffolding in arbitrary directories or environments where WordPress files exist but database connections don't.

Changes

  • Added Scaffold_Filesystem_Fallback class - Drop-in replacement for WP_Filesystem using native PHP file operations when WordPress unavailable

  • Modified init_wp_filesystem() - Detects WordPress availability and returns appropriate filesystem handler

  • Added fallback helpers for WordPress dependencies:

    • get_plugin_dir() / get_content_dir() - Return WP constants or fallback to getcwd()
    • parse_args() - Wraps wp_parse_args() with array_merge() fallback
    • get_wp_version() - Returns bloginfo or fallback constant (6.4)
    • maybe_load_plugin_functions() - Conditionally loads wp-admin/includes/plugin.php
  • Added @when before_wp_load annotations to plugin() and plugin_tests() commands

Example

# Works without WordPress installation
$ mkdir /tmp/my-plugin && cd /tmp/my-plugin
$ wp scaffold plugin-tests my-plugin --dir=. --path=/tmp/my-plugin
Success: Created test files.

When WordPress is detected, behavior remains unchanged - WP_Filesystem is used for proper permissions and security. Fallback uses equivalent permissions (0755 for directories, matching WordPress defaults).

Original prompt

This section details on the original issue you should resolve

<issue_title>Allow scaffolding without WordPress being present</issue_title>
<issue_description>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.</issue_description>

Comments on the Issue (you are @copilot in this section)

@schlessera 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 Some context: https://wordpress.slack.com/archives/C02RP4T41/p1529483149000520 @BrianHenryIE `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 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.</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@codecov
Copy link

codecov bot commented Feb 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI and others added 4 commits February 1, 2026 16:11
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Allow scaffolding without WordPress being present Allow scaffold commands to run without WordPress loaded Feb 1, 2026
Copilot AI requested a review from swissspidy February 1, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow scaffolding without WordPress being present

2 participants