wp-plugin-architecture — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited wp-plugin-architecture (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
How the plugin organizes itself inside includes/ (or wherever the PSR-4 root lives) once the bootstrap (see wp-plugin-bootstrap) and lifecycle (see wp-plugin-lifecycle) are in place. The bootstrap is the launcher; this skill is the engine layout.
Out of scope: bootstrap-file content, activation / deactivation / uninstall, cron specifics, REST endpoint design — covered by sibling skills.
Trigger when ANY of the following is true:
includes/ (or src/) folder of a new plugin.Schema.php, or a PHP enum.There are two reasonable organizational schemes for includes/. Pick one and stay consistent.
By-type (group classes by their WP role). Works for small-to-medium plugins (≤ 15 classes, 1-3 features):
includes/
├── Plugin.php # composition root / wiring
├── Schema.php # central constants
├── Actions/ # JFB / WC actions
├── Events/ # JFB events
├── Settings/ # admin settings
├── Rest/ # REST controllers
└── Api/ # external HTTP clientsBy-feature (group everything that belongs to a feature together). Scales better past 3-4 distinct features:
includes/
├── Plugin.php
├── Schema.php
├── Verdict/ # AI Verdict feature
│ ├── VerdictAction.php
│ ├── VerdictTrueEvent.php
│ └── VerdictFalseEvent.php
├── Enrichment/
│ ├── EnrichmentAction.php
│ └── EnrichmentDoneEvent.php
├── Settings/
│ └── SettingsTab.php
└── Updater/
└── UpdateChecker.phpThe wrong move is mixing both in the same plugin. A reader gets confused, an AI gets lost, and refactors become tedious. By-type is fine until it isn't — when a third feature ships and Actions/ has 9 classes from 3 unrelated domains, switch the whole plugin to by-feature.
Hard rule across both styles: one class per file, file name matches class name (VerdictAction.php → class VerdictAction), PSR-4 maps <RootNamespace>\Verdict\VerdictAction to includes/Verdict/VerdictAction.php. The kebab-case class-foo-bar.php filename is a holdover from PHPCS-WPCS-old; modern plugins use PascalCase that matches the class.
Schema / Constants is non-negotiableEvery string that appears more than once — meta key, option name, custom hook name, cron event name, CPT slug, capability slug, transient prefix — lives in one place. Three patterns that all work:
class UsageTracker {
public const OPTION_PREFIX = 'myplugin_usage_';
public static function current_month_key(): string {
return self::OPTION_PREFIX . gmdate( 'Y_m' );
}
}When the constant logically belongs to one feature, define it there. Cleanest scope.
Schema class for cross-feature constantsnamespace MyPlugin;
final class Schema {
public const META_FORM_SETTINGS = '_myplugin_form_settings';
public const OPTION_GLOBAL = 'myplugin_global_settings';
public const CPT_LOG = 'myplugin_log';
public const CRON_DAILY = 'myplugin_daily_cleanup';
public const HOOK_BEFORE_REQUEST = 'myplugin/before_request';
private function __construct() {} // not instantiable
}Then everywhere: Schema::META_FORM_SETTINGS instead of the literal string. Renaming becomes one-line; typos become impossible (the class autoloader catches them).
For a fixed value set (failure modes, output types, etc.), use enums only when the plugin's declared minimum PHP version is 8.1 or higher:
enum FailureMode: string {
case Halt = 'halt';
case Permissive = 'permissive';
case Restrictive = 'restrictive';
}
// Then instead of error-prone string parsing:
$mode = FailureMode::tryFrom( $raw ) ?? FailureMode::Halt;Type-safe, enumerable, documents itself.
For PHP 7.4 / 8.0-compatible plugins, use class constants plus explicit validation instead:
final class FailureMode {
public const HALT = 'halt';
public const PERMISSIVE = 'permissive';
public const RESTRICTIVE = 'restrictive';
public static function normalize( string $raw ): string {
return in_array( $raw, self::all(), true ) ? $raw : self::HALT;
}
public static function all(): array {
return array( self::HALT, self::PERMISSIVE, self::RESTRICTIVE );
}
}The hard rule: if you find yourself typing the same magic string in two files, that's the moment to centralize. The wrong direction is "I'll only have it in two places, no need yet" — git grep next year proves the lie.
The Plugin class is often the composition root: one object wires services, hooks, controllers, settings, and integrations after bootstrap. It MAY expose a small instance() helper when the surrounding plugin style already uses that pattern, but a singleton is not required. A plain new Plugin(...)->register() from the bootstrap is usually easier to test.
Beyond the composition root, don't make everything a singleton by reflex.
SettingsRepository doesn't need getInstance() — instantiate it where you need it (new SettingsRepository()); it's cheap.error_log, which is itself globally available. No state, no singleton.The price of singleton-everywhere: tests can't substitute mocks, dependencies become hidden, and you accumulate a Plugin::instance()->get_storage_manager()->get_provider_registry() getter chain that nobody can refactor.
When in doubt: write the class as a regular class. Promote to singleton only when there's a concrete reason (genuine global state, expensive lazy initialization shared across many call sites, or compatibility with an existing plugin API).
The wrong way: enqueue every script and stylesheet on every page load via wp_enqueue_scripts. The right way:
wp_enqueue_scripts (wp-includes/script-loader.php:2311)admin_enqueue_scripts (wp-admin/admin-header.php:123) — receives $hook_suffix argument identifying the current admin pageenqueue_block_editor_assetsenqueue_block_assetslogin_enqueue_scriptscustomize_preview_init add_action( 'admin_enqueue_scripts', static function ( string $hook_suffix ): void {
// Only on the plugin's own settings page
if ( $hook_suffix !== 'settings_page_myplugin' ) {
return;
}
wp_enqueue_script( /* ... */ );
} );For frontend, gate by is_singular() / has_block( 'myplugin/contact' ) / specific shortcodes.
wp-element, wp-components, wp-i18n, wp-hooks, your own scripts. Without proper deps the script may run before the dependency is defined and break.filemtime( $script_path ) — perfect during development (every save invalidates cache).VERSION constant — best for production (predictable, changes on release).defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? filemtime() : VERSION.$in_footer to an array supporting strategy ('defer' or 'async'), in_footer, and fetchpriority (since 6.9). Use 'strategy' => 'defer' instead of jQuery-era ready-handlers when feasible.wp_add_inline_script preferred over wp_localize_script for new codewp_localize_script (since 2.2) creates a JavaScript object from an associative array. It still works, but for arbitrary runtime config it is a legacy-shaped helper: it requires an array payload and creates a top-level global. Use wp_set_script_translations() for JavaScript translations.
wp_add_inline_script (since 4.5) is the modern path: any JS string, before or after the registered script. Use wp_json_encode() to serialize structured data:
wp_add_inline_script(
'myplugin-editor',
'window.MyPluginConfig = ' . wp_json_encode( array(
'restUrl' => esc_url_raw( rest_url( 'myplugin/v1/' ) ),
'nonce' => wp_create_nonce( 'wp_rest' ),
) ) . ';',
'before'
);Both functions still work; for a new plugin, default to wp_add_inline_script for configuration and wp_set_script_translations() for script translations.
Custom action / filter hooks the plugin emits (so other developers can wire into your behavior) follow ONE naming convention, picked once and never deviated from:
// Slash-separated (common in modern plugins and integrations)
do_action( 'myplugin/before_request', $payload );
apply_filters( 'myplugin/api_response', $response, $request );
// Underscore-separated (classic; common in WordPress core)
do_action( 'myplugin_before_request', $payload );Both are common in the ecosystem, but WordPress core itself mostly uses underscore-separated hook names such as pre_get_posts and rest_pre_serve_request. If the project uses WPCS rules that discourage slashes in hook names, pick underscores. The hard rule: prefix every custom hook with the plugin slug. do_action( 'before_request', ... ) is a foot-gun — collisions with other plugins are guaranteed at scale.
When you DO emit a custom hook, give it a docblock right above:
/**
* Fires before the AI request is sent.
*
* @since 1.0.0
*
* @param array $payload The request payload (mutable downstream).
*/
do_action( 'myplugin/before_request', $payload );@since lets users pin their integration; AI assistants reading the source rely on these to suggest correct hooks.
includes/ at once.Schema class, or a PHP 8.1+ enum when the plugin requires PHP 8.1+.wp_enqueue_scripts / admin_enqueue_scripts($hook_suffix) / enqueue_block_editor_assets); never enqueue unconditionally in init.wp_enqueue_script (since 6.3) — use 'strategy' => 'defer' where possible.// WRONG — magic strings scattered across files
update_post_meta( $post_id, '_myplugin_settings', $value ); // file A
get_post_meta( $post_id, '_myplugin_setings', true ); // file B (typo!)
// RIGHT — one source of truth
update_post_meta( $post_id, Schema::META_SETTINGS, $value );
// WRONG — enqueue on init unconditionally
add_action( 'init', function () {
wp_enqueue_script( 'myplugin-frontend', /* ... */ );
} );
// queues assets in broad request contexts and bypasses page-specific gates
// RIGHT — frontend hook + context gate
add_action( 'wp_enqueue_scripts', function () {
if ( ! has_block( 'myplugin/contact' ) ) return;
wp_enqueue_script( 'myplugin-frontend', /* ... */ );
} );
// WRONG — singleton by reflex
final class HttpClient {
private static ?self $instance = null;
public static function instance(): self { /* ... */ }
}
// 1 plugin = 1 client, can't test, can't swap base URL per call site
// RIGHT — regular class with explicit dependencies
$client = new HttpClient( $api_key, $base_url );
$client->post( '/things', $payload );
// WRONG — bare hook name
do_action( 'before_save', $data ); // collides with 5 other plugins
// RIGHT
do_action( 'myplugin/before_save', $data );uninstall.php.block.json, Edit / Save components) — separate skill territory.$args array enables.wp_enqueue_script: wp-includes/functions.wp-scripts.php — note the @since 6.3.0 on $args array overload.wp_add_inline_script: wp-includes/functions.wp-scripts.php — since WP 4.5.admin_enqueue_scripts action with $hook_suffix: wp-admin/admin-header.php:123.wp_enqueue_scripts action: wp-includes/script-loader.php:2311.~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.