Skip to content

Options: Prevent All Settings screen from wiping options with unsafe POST field names - #16319

Open
robelsust wants to merge 1 commit into
WordPress:trunkfrom
robelsust:fix/66864-options-php-dot-space-names
Open

robelsust wants to merge 1 commit into
WordPress:trunkfrom
robelsust:fix/66864-options-php-dot-space-names

Conversation

@robelsust

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/66864
See also: https://core.trac.wordpress.org/ticket/66863

Description

On Settings → All Settings (wp-admin/options.php), PHP converts dots (.), spaces, and open square brackets ([) in submitted form field names to underscores (or parses brackets as arrays), and page_options is comma-delimited. Because options containing these characters were still listed in page_options, clicking Save Changes looked up an absent key in $_POST and called update_option( $option, null ), wiping their stored values (such as dotted plugin options like litespeed.conf.*).

Additionally, home and siteurl were marked $disabled = true when WP_HOME / WP_SITEURL were defined, yet were still appended to $options_to_update, causing spurious "did not appear to be a valid URL" errors on every save (#66863).

Changes

  • Extract option row display/editability logic into a private helper _wp_prepare_all_options_field() in src/wp-admin/includes/options.php.
  • Mark options whose names match /[\s.\[,]/ as disabled while preserving their display value.
  • Initialize $options_to_update = array() and only append non-disabled options (if ( ! $disabled )) to page_options, which also resolves #66863.
  • Apply disabled( $disabled, true ) to <textarea> elements in src/wp-admin/options.php (previously only <input> had it).
  • Add unit tests in tests/phpunit/tests/admin/wpPrepareAllOptionsField.php.

Testing

  • Ran vendor/bin/phpcs on all modified and new files.
  • Ran single-site and multisite PHPUnit suites on tests/phpunit/tests/admin/wpPrepareAllOptionsField.php (16 tests, 32 assertions).

…POST field names.

On Settings -> All Settings (`wp-admin/options.php`), PHP converts dots,
spaces, and open square brackets in submitted form field names to underscores
(or parses brackets as arrays), and `page_options` is comma-delimited. Because
those option names were still added to `page_options`, saving the form looked up
an absent key in `$_POST` and called `update_option( $option, null )`, wiping
existing values (such as dotted plugin options like `litespeed.conf.*`).

In addition, `home` and `siteurl` were marked disabled when `WP_HOME` or
`WP_SITEURL` were defined, yet were still added to `page_options`, causing
spurious invalid URL errors on save.

Extract field preparation into `_wp_prepare_all_options_field()`, mark options
whose names contain characters rewritten by PHP or the `page_options` comma
delimiter as disabled, only append non-disabled options to `$options_to_update`,
and apply `disabled()` to `<textarea>` fields as well as `<input>` fields.

Trac ticket: https://core.trac.wordpress.org/ticket/66864
See also: https://core.trac.wordpress.org/ticket/66863
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props therssoftware.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

❌ PHPStan Static Analysis

PHPStan reported 1 error when analyzing 8ca783f (workflow run). This comment is updated as new commits are pushed.

Important

The PHPStan baselines are out of date, so the PHPStan check fails.

An error recorded in a baseline no longer occurs, or occurs a different number of times. If this pull request fixed it, that is expected: nothing needs to change in the code, but each baseline entry records an exact count for a specific file, and the baselines need to catch up. Remove the stale entries, and commit the result:

npm run typecheck:php:fix

or, outside the Docker environment:

composer phpstan:fix

This also deletes any baseline left with no entries, and removes any @phpstan-ignore comment in the code that no longer ignores anything.

See Removing stale entries with --fix for details, and for regenerating the baselines instead.

Errors that fail the check

Location Error Identifier First reported
src/wp-admin/options.php Ignored error pattern #^Variable \$options_to_update might not be defined\.$# (variable.undefined) in path /home/runner/work/wordpress-develop/wordpress-develop/src/wp-admin/options.php was not matched in reported errors. ignore.unmatched 8ca783f

Running PHPStan locally

To run the analysis on your own machine, use npm run typecheck:php, or composer phpstan outside the Docker environment.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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