Skip to content

Readme: Add header properties that the readme does not have yet - #919

Open
manishsongirkar wants to merge 1 commit into
WordPress:trunkfrom
manishsongirkar:fix/readme-add-missing-header-props
Open

manishsongirkar wants to merge 1 commit into
WordPress:trunkfrom
manishsongirkar:fix/readme-add-missing-header-props

Conversation

@manishsongirkar

Copy link
Copy Markdown

Summary

CBT_Theme_Readme::add_or_update_prop() reads the first match of a property in the readme without checking that there is one:

preg_match_all( $pattern, $readme_content, $matches );
$current_uri = $matches[0][0]; // Undefined array key 0 when there is no match.

When the readme has no Requires at least or Tested up to line, PHP logs Undefined array key 0 and the property is never written. The save still reports Theme Updated., and readme.txt ends up out of step with style.css. add_or_update_section() in the same class adds a missing section, but the property function did not add a missing property.

Now, when the property is not in the readme, it is added at the end of the header, before the first == Section == line. A property that is already there is updated in place, as before.

Fixes #918

Related to #916 and #917, the line-ending bug in the same file. The two changes are independent and touch different functions.

Changes

  • includes/create-theme/theme-readme.php: add_or_update_prop() adds the property to the header when preg_match() finds no match. The header is the text before the first line that starts with == . If the readme has no header text, the property starts the file.
  • tests/CbtThemeReadme/missingProps.php (new): three tests through the public update() method:
    • Missing properties are added at the end of the header, in order, and the property that is there is updated.
    • A readme with only a title and sections gets its properties between the title and the first section.
    • Properties that are there are updated in place and are not duplicated. This one passes on trunk too, as a guard.

Test plan

  • The two tests for missing properties fail on trunk with Undefined array key 0 and pass with this change: npm run test:unit:php:base -- --filter CBT_ThemeReadme_MissingProps.
  • --group readme passes (16 tests).
  • The full PHPUnit suite passes (276 tests, 3 multisite tests skipped in a single-site run).
  • vendor/bin/phpcs --standard=phpcs.xml.dist on the changed files is clean.
  • Manual test in the Site Editor with Ipsum:
    1. Remove the Requires at least: and Tested up to: lines from the theme's readme.txt.
    2. Open Create Block Theme → Edit Theme Metadata and click Update.
    3. On trunk, the response says SUCCESS, readme.txt still has neither line, and PHP logs two Undefined array key 0 warnings.
    4. With this change, readme.txt gets Requires at least: 7.2 and Tested up to: 7.3-alpha-65850 at the end of the header, and PHP logs no warnings.

Out of scope

  • The pattern that finds a property is not anchored to the start of a line, so a property name that appears in other text can match there. I did not change how existing properties are found.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code (Claude Sonnet 5.5)
Used for: Investigating the issue, implementing the fix, writing the tests, and drafting this description. I reproduced the bug in the editor, ran the tests, and reviewed and tested the change myself.

CBT_Theme_Readme::add_or_update_prop() read the first match of the
property in the readme without checking that there was one. When the
readme had no "Requires at least" or "Tested up to" line, PHP logged
"Undefined array key 0" and the property was never written, while the
save still reported success. readme.txt then disagreed with style.css.

When the property is not in the readme, add it at the end of the
header, before the first section. A property that is there is updated
in place, as before.

Add tests for missing properties, for a readme with no header
properties, and for properties that must not be duplicated.

Fixes WordPress#918
Related to WordPress#916 and WordPress#917
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.

Readme: Saving theme metadata silently skips header properties that readme.txt does not already have

1 participant