Skip to content

Add a filter to protect more options - #102

Open
jdevalk wants to merge 1 commit into
developfrom
claude/protected-options-filter
Open

jdevalk wants to merge 1 commit into
developfrom
claude/protected-options-filter

Conversation

@jdevalk

@jdevalk jdevalk commented Nov 18, 2026

Copy link
Copy Markdown
Member

Ports the one piece of #79's protected-options work that develop did not get from #93: the aaa_option_optimizer_protected_options filter.

What it does

Other code (an MU plugin, for example) can add option names to the protected list. Those options then can't be deleted, created with a false value, or have their autoload state changed through this plugin, and the list routes flag them so the admin screen hides the actions. Names match case-insensitively, like the built-in ones.

add_filter( 'aaa_option_optimizer_protected_options', function ( $names ) {
	$names[] = 'my_plugin_license';
	return $names;
} );

Difference from #79

In #79 the filter received the full list and its return value replaced it, so a callback could remove siteurl from protection. Here the filter is add-only: removing a built-in name has no effect, and a return value that is not an array of non-empty strings is ignored. A broken callback can't switch the built-in protection off.

The filter runs on each lookup rather than being cached, matching how the roles and theme-mods names are already added per call, so a filter added later in the request still applies.

Tests

Two new PHPUnit tests: a filtered name is refused by single delete, bulk delete and autoload change and is flagged in all-options; and __return_empty_array, __return_false and a list of non-strings all leave siteurl protected.

Run locally: 59 tests pass on PHP 8.4 with WP 7.1.4 (single and multisite) and on PHP 7.4 with WP 6.7. tests/hardening.php, composer check-cs, composer phpstan and composer lint pass.

🤖 Generated with Claude Code

Ported from #79: the aaa_option_optimizer_protected_options filter lets other code
add option names that can't be deleted, created with a false value, or have their
autoload state changed through the plugin.

Unlike the #79 version, the filter can only add names. Removing a built-in name
has no effect, and a return value that is not an array of strings is ignored, so
a broken callback can't switch off the built-in protection.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Plugin readme preview

Open preview · Commit 7b36f7e

29 passed · 1 warning · 0 notes

Warnings

  • “Tested up to” is 7.2; the latest WordPress major release is 7.1. Test with 7.1 and update the header.
Passed checks (29)
  • 76 / 150 characters in the short description.
  • Plugin name header recognized.
  • License header recognized: GPL-3.0-or-later.
  • 5 tags accepted within the five-tag limit.
  • Description is within the parser’s word limit.
  • Installation is within the parser’s word limit.
  • Faq is within the parser’s word limit.
  • Changelog is within the parser’s word limit.
  • Stable tag is declared: 1.7.1.
  • The PHP Version header is declared: 1.7.1.
  • Stable tag matches the PHP Version header: 1.7.1.
  • The readme “Requires at least” value is valid: 6.7.
  • The PHP “Requires at least” header is a numeric version: 6.7.
  • “Requires at least” matches between the readme and PHP header: 6.7.
  • The readme “Requires PHP” value is valid: 7.4.
  • The PHP “Requires PHP” header is a numeric version: 7.4.
  • “Requires PHP” matches between the readme and PHP header: 7.4.
  • “Tested up to” 7.2 meets the minimum WordPress version 6.7.
  • Installation content is present.
  • FAQ content is present.
  • Changelog content is present.
  • Screenshot captions are present.
  • The first changelog release matches Stable tag: 1.7.1.
  • The first changelog release matches PHP Version: 1.7.1.
  • Banner image loaded.
  • Plugin icon loaded.
  • Screenshot 1 has a matching image and caption.
  • Screenshot 2 has a matching image and caption.
  • Plugin PHP header loaded.

Readme and PHP-header checks only; this does not test plugin runtime compatibility.

@github-actions

Copy link
Copy Markdown

Test on Playground
Test this pull request on the Playground
or download the zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant