Repository navigation
Add an Autoloaded Options tab with evidence, a safety check, and WP-CLI - #187
Conversation
A new tab on the Site Optimizer settings page lists the options WordPress
loads on every page, largest first, and stops loading the ones selected.
Only the autoload flag changes, never a value. Each change is logged with
the flag it replaced, so switching back on restores the exact flag
('on', 'auto', 'auto-on', or 'yes'). Options WordPress and the plugin need
are locked.
WordPress records no owner for an option, so the tab gathers evidence: a
guess from plugin and theme folder names and text domains; on request, a
search of the installed PHP code, which marks names found nowhere as left
behind; and an optional, time-limited recording of which options pages
read, and which plugin or theme read each one.
After a switch-off the plugin loads the home page and the dashboard and
undoes the change if either answers with a server error. WP-CLI commands
list and restore the changes; the command file also loads on its own, so
a restore works with every plugin and theme skipped.
Uninstall restores every switched-off option on every site before it
deletes anything; if one cannot be restored, nothing on that site is
deleted. The tab, the Plugins screen, and the FAQ say so beforehand.
Adds php-stubs/wp-cli-stubs as a development dependency, so that PHPStan
and Psalm know WP-CLI's API.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for contributing to EngineScript Site Optimizer! Before we review:
Security Reminder
We'll review your PR soon. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 510 |
| Duplication | 0 |
🟢 Coverage 95.66% diff coverage · -0.66% coverage variation
Metric Results Coverage variation ✅ -0.66% coverage variation (-1.00%) Diff coverage ✅ 95.66% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (d9e3fbd) 971 941 96.91% Head commit (c09694f) 1998 (+1027) 1923 (+982) 96.25% (-0.66%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#187) 1036 991 95.66% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
…tests Plugin Check did not recognise the WP-CLI command file's direct-access guard. The guard now reads `defined( 'WP_CLI' ) || defined( 'ABSPATH' ) || exit;`, which keeps the WP-CLI exception that --require needs, and Rector skips the two rules that would rewrite it for this file. New unit tests cover the WP-CLI commands, through a WP-CLI double, the list of switched-off options, and the page links, which brings line coverage back above the minimum. The code search check moves out of the view reader, and reviewed false positives carry nosemgrep markers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Covers malformed stored usage and code search results, the minimum name length of the code search, and each check result and recording notice, which keeps total coverage within Codacy's allowed drop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
This adds an Autoloaded Options tab to Settings › Site Optimizer. It lists the options WordPress loads on every page, largest first, and stops loading the ones you select.
es_optimizer_autoload_changes, never autoloaded itself). Switching back on restores that exact flag (on,auto,auto-onoryes), and only while the stored flag is stilloff; if other code has changed it since, its change wins.widget_*,theme_mods_*, the roles row,alloptionsandnotoptions, and the plugin's own options. There is no override.Who owns an option. WordPress records no owner, so the tab gathers evidence:
Safety:
wp site-optimizer autoload listandwp site-optimizer autoload restore [<option>...] [--all]. The command file has no other plugin dependency, so the restore also works on a site a plugin breaks:wp --skip-plugins --skip-themes --require=wp-content/plugins/enginescript-site-optimizer/includes/class-es-optimizer-autoload-command.php site-optimizer autoload restore --allEvery request needs
manage_optionsand a nonce. Queries are prepared, LIKE wildcards in the search are escaped, and every option name, plugin name and message is escaped on output.This adds
php-stubs/wp-cli-stubsas a development dependency, and adds it tophpstan.neonandpsalm.xml, so static analysis knows WP-CLI's API.Testing
composer check-allpasses: PHPCS, PHPMD, Psalm (level 1) and its taint analysis, PHPStan (max), Rector, and PHPUnit with 213 tests and 1032 assertions. There are two new test files, AutoloadTest and AutoloadInsightTest, plus new uninstall tests.%,_, quotes, Unicode, 191 bytes) and locked options;pre_optionfilter.optimizer-autoloadsuite) passes all 46 checks, on Nginx with the FastCGI cache, PHP-FPM, MariaDB, the Redis object cache, and 28 active plugins. It verified that:alloptionsentry shrinks from 416 KB to 56 KB;astra-settingsto the Astra theme;wp plugin uninstallrestores every flag.p/php,p/security-audit), trivy, gitleaks and Plugin Check's PHPCS rulesets are clean.The changelog entries are under "Unreleased", the README and
readme.txt(including new FAQ entries) are updated, and the translation template is regenerated (217 strings).🤖 Generated with Claude Code