#15540 closed enhancement (fixed)
Remove redundant code
| Reported by: | latz | Owned by: | scribu |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.1 |
| Component: | Administration | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
The files "class-wp-links-list-table.php" and "class-wp-users-list-table" re-implement code already present in "misc.php" to shorten URLs (function url_shorten()).
Attachments (2)
Change History (7)
This ticket was mentioned in PR #15567 on WordPress/wordpress-develop by @wesleyjrosa.
2 days ago
#5
- Keywords has-unit-tests added
The autoload column of the options table uses seven string values: 'on', 'off', 'auto', 'auto-on', 'auto-off', and the legacy 'yes' and 'no'. Core repeats them as raw literals in many places, so it is easy to use the wrong one. For example, one lock row still used the deprecated 'no' (see #15540).
This PR adds class constants for these values and uses them in wp-includes/option.php:
- Add
WP_Option_Autoload, a final class with the constantsON,OFF,AUTO,AUTO_ON,AUTO_OFF,LEGACY_YESandLEGACY_NO. - Load it from
wp-includes/functions.php, right beforeoption.php, so it is there in every path that loads the Option API, including install. - Use the constants in
wp_set_option_autoload_values(),update_option(),wp_determine_option_autoload_value()andwp_autoload_values_to_autoload(). - Fix an outdated comment that said
'yes'or'no'.
There is no change in behavior. The stored values, the function return values and the filters stay the same plain strings, so plugins see no change. Other files (lock rows, install and upgrade code) will follow in a separate PR.
Trac ticket:
Testing instructions
This is a refactor with no change in behavior, so the existing option tests are the main check.
Setup: Node 24.18 or newer, and Docker running.
- From the repository root, run:
cp .env.example .env npm ci npm run env:start npm run env:install
- Run the option tests:
npm run test:php -- --group option
Expected: no failures. The count is one test more than ontrunk(the newTests_Option_wpOptionAutoloadtest). - Run PHPStan on the changed files:
npm run typecheck:php -- src/wp-includes/class-wp-option-autoload.php src/wp-includes/option.php src/wp-includes/functions.php
Expected:[OK] No errors.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Finding the repeated values, writing the class, the changes and the test, and drafting this description. I reviewed the code and ran the tests.
---
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
🤖 Generated with Claude Code
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
(In [16536]) Document url_shorten() and use in more places. Props latz for initial patch. Fixes #15540