Add a filter hook for the theme style variations#63607
Add a filter hook for the theme style variations#63607dhananjaykuber wants to merge 1 commit intoWordPress:trunkfrom
Conversation
- Add filter to add custom variations outside styles folder - Add filter to filter the variations.
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
CC: @richtabor - What do you think of this direction? I'm in favor of the filter hooks introduced here and think this is a solid solution. Longer term, I think it'd be great to have dedicated register/unregister functions, which would certainly make the ability to unregister easier. |
|
This PR is outdated due to #63318 but there's still no way to remove a variation conditionally. I'll open a new PR with just that change. This PR could be closed. |
Fixes #63574
What?
This PR adds filter hooks to allow for custom style variations to be injected and additional directories to be scanned for JSON files. Specifically, it introduces:
Why?
Currently, only themes can register theme style variations by adding JSON files to their /styles folder. There is no API or filter hook to add custom variations outside of using the /styles folder. This PR addresses this limitation by providing the necessary hooks to extend and customize style variations more flexibly.
How?
wp_theme_json_style_variation_directoriesis added to allow custom directories to be included when scanning for style variation JSON files.wp_theme_json_variation_filesis added to enable plugins to modify the array of style variation files collected from the directories.Testing Instructions
custom-stylesin the root of your plugin and add a JSON file with style variations.Screenshots or screencast
New Stylesvariations added by newcustom-stylesfolder usingwp_theme_json_style_variation_directoriesfilterwp_theme_json_variation_filesfilter