Skip to content

Add JSON as an alternative to PHP/CSS file headers for plugin and theme metadata#11200

Open
retlehs wants to merge 2 commits intoWordPress:trunkfrom
retlehs:trac-24152-json-metadata-for-themes-and-plugins
Open

Add JSON as an alternative to PHP/CSS file headers for plugin and theme metadata#11200
retlehs wants to merge 2 commits intoWordPress:trunkfrom
retlehs:trac-24152-json-metadata-for-themes-and-plugins

Conversation

@retlehs
Copy link

@retlehs retlehs commented Mar 8, 2026

Trac ticket: https://core.trac.wordpress.org/ticket/24152

This adds support for declaring plugin and theme metadata in JSON files as an alternative to PHP/CSS comment-based file headers.

  • Plugins can now use a plugin.json file alongside the main PHP file
  • Themes can now declare metadata in the metadata property of theme.json
  • JSON metadata takes priority when present; existing file headers work as a fallback
  • Backwards compatible fallback behavior remains: if JSON metadata is missing or invalid, existing file headers are still used

Motivation

PHP/CSS file headers are parsed via regex on the first 8KB of a file. JSON provides a structured, machine-readable, language-agnostic alternative that:

  • Eliminates regex parsing fragility
  • Aligns with modern conventions
  • Allows themes to work without style.css (block themes already don't need one for styling)

See: WordPress File Headers Have Overstayed Their Welcome

Examples

plugin.json

{
  "name": "My Plugin",
  "uri": "https://example.com/my-plugin",
  "description": "A short description of the plugin.",
  "author": "Plugin Author",
  "authorUri": "https://example.com",
  "version": "1.0.0",
  "textDomain": "my-plugin",
  "requires": {
    "wordpress": "7.0",
    "php": "8.0",
    "plugins": ["woocommerce", "jetpack"]
  },
  "network": true,
  "mainFile": "bootstrap.php"
}

theme.json (metadata property)

{
  "version": 3,
  "metadata": {
    "name": "My Theme",
    "uri": "https://example.com/my-theme",
    "description": "A short description of the theme.",
    "author": "Theme Author",
    "authorUri": "https://example.com",
    "version": "1.0.0",
    "tags": ["blog", "one-column"],
    "textDomain": "my-theme",
    "template": "parent-theme"
  },
  "settings": { ... },
  "styles": { ... }
}

Other examples from my demo repo: https://github.com/retlehs/json-metadata-theme-and-plugin

Changes

Plugin metadata (plugin.json)

  • New _get_plugin_json_data() function reads plugin.json from a plugin's directory
  • get_plugin_data() checks for JSON metadata first, then falls back to PHP file headers
  • Only applies to direct children of WP_PLUGIN_DIR (not mu-plugins or drop-ins)
  • Supports a mainFile property to designate the main entry point (defaults to {dir-name}/{dir-name}.php)
  • requires.plugins array maps to comma-separated RequiresPlugins header format
  • network field uses strict boolean checking (true only)
  • Uses silent JSON decoding (not wp_json_file_decode()) to avoid errors during enumeration
  • Files outside direct child plugin directories (including mu-plugin subdirectories and drop-ins) are ignored
  • JSON parsing honors headers registered via the existing extra_plugin_headers filter

Theme metadata (theme.jsonmetadata)

  • New read_json_metadata() private method on WP_Theme reads metadata from theme.json
  • Constructor tries JSON metadata before style.css headers
  • Themes with theme.json metadata can now work without a style.css file
  • Updated validate_current_theme() to allow active themes (including child themes) without style.css when theme.json contains valid metadata.name
  • Uses silent JSON decoding to avoid errors when enumerating themes with malformed theme.json
  • JSON metadata parsing honors headers registered via the existing extra_theme_headers filter

Schema notes

The theme.json schema (maintained in the Gutenberg repo) will need a companion PR to add the metadata property definition.

Schema publication/documentation for plugin.json will need to be done.

Testing

npm run test:php -- --filter "Tests_Admin_IncludesPluginJsonMetadata|Tests_Admin_WPPluginDependencies_Initialize|Tests_Theme_ThemeDir|Tests_Theme_wpThemeJsonMetadata"

All filtered tests passed locally in Docker

Demo

See https://github.com/retlehs/json-metadata-theme-and-plugin for an example plugin and theme, along with instructions on how to setup your local environment with this PR

Plugin Metadata Theme Metadata Theme Front End
JSON metadata plugin JSON metadata theme JSON metadata theme front end

Use of AI Tools

This PR was authored with Claude Code and Codex. Both were used for implementation, test writing, and code review. I reviewed and validated all changes, and ran tests locally in Docker.

@github-actions
Copy link

github-actions bot commented Mar 8, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @QWp6t.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

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

Props retlehs.

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

@github-actions
Copy link

github-actions bot commented Mar 8, 2026

Hi @retlehs! 👋

Thank you for your contribution to WordPress! 💖

It looks like this is your first pull request to wordpress-develop. Here are a few things to be aware of that may help you out!

No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description.

Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making.

More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook.

Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook.

If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook.

The Developer Hub also documents the various coding standards that are followed:

Thank you,
The WordPress Project

@retlehs retlehs force-pushed the trac-24152-json-metadata-for-themes-and-plugins branch from 693b1a7 to 84b82ea Compare March 8, 2026 07:15
@github-actions
Copy link

github-actions bot commented Mar 8, 2026

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.

Copy link

@QWp6t QWp6t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!


$extra_plugin_headers = (array) apply_filters( 'extra_plugin_headers', array() );
foreach ( $extra_plugin_headers as $extra_header ) {
$key_map[ $extra_header ] = $extra_header;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This odd behavior that prevents custom keys stems from https://core.trac.wordpress.org/ticket/8964 — no valid reason was given.

Can we rectify it? It would allow us to quickly deprecate and assign alternative names without changing keys.

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.

3 participants