Make WordPress Core

Opened 16 years ago

Closed 16 years ago

Last modified 2 days ago

#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)

class-wp-links-list-table.diff​ (808 bytes ) - added by latz 16 years ago.
class-wp-users-list-table.diff​ (783 bytes ) - added by latz 16 years ago.

Download all attachments as: .zip

Change History (7)

#1 @nacin
16 years ago

  • Milestone Awaiting Review → 3.1

#2 @scribu
16 years ago

  • Owner set to scribu
  • Status new → accepted

#3 @scribu
16 years ago

  • Resolution → fixed
  • Status accepted → closed

(In [16536]) Document url_shorten() and use in more places. Props latz for initial patch. Fixes #15540

#4 @scribu
16 years ago

Turns out the user url wasn't being used at all so I removed it.

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 constants ON, OFF, AUTO, AUTO_ON, AUTO_OFF, LEGACY_YES and LEGACY_NO.
  • Load it from wp-includes/functions.php, right before option.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() and wp_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.

  1. From the repository root, run:
    cp .env.example .env
    npm ci
    npm run env:start
    npm run env:install
    
  2. Run the option tests:
    npm run test:php -- --group option
    
    Expected: no failures. The count is one test more than on trunk (the new Tests_Option_wpOptionAutoload test).
  3. 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

Note: See TracTickets for help on using tickets.