Ashlar WP-CLI Tools
Two custom WP-CLI tools that simplify working with Figma design tokens and ACF block templates in the Ashlar WordPress starter.
- Status
- In daily use
- Stack
Overview
I built two custom WP-CLI tools for the Ashlar WordPress starter theme. Both live in wp-content/mu-plugins/ and are designed to handle parts of the development workflow that were previously done by hand.
The first takes design variables exported from Figma and turns them into Tailwind CSS v4 theme files. The second checks and fixes ACF block field definitions and generates the corresponding render.php templates.
They’re both must-use plugins, so there’s no activation step or admin interface to maintain. Everything runs directly through WP-CLI.
The problem
There were two areas of the workflow that could be improved.
- Design tokens: Figma variables had to be manually translated into Tailwind CSS. Whenever the design changed, keeping the code in sync meant repeating the same work.
- ACF block development: Field definitions and their corresponding render templates were maintained separately. This made it easy for the two to get out of sync. Invalid field files could also cause problems when ACF loaded them during initialization.
I wanted to make both processes easier to maintain and less prone to human error.
What I built
Figma Tokens to Tailwind
The wp tailwind-tokens convert <file>... command takes Figma’s exported variables in W3C design-token format and generates Tailwind CSS v4 theme files.
It generates separate CSS files for each token type found in the exported variables, such as colors, spacing, radius, width, typography, and container values. The output filenames are configurable, and there’s also an option to combine everything into a single stylesheet without affecting the surrounding SCSS.
Some of the features I implemented:
- Light and dark modes: Light values are written into
@theme, while dark mode values use a separate unlayered CSS block. This allows dark values to take precedence without relying on!important. - Responsive typography: Generates mobile-first styles with tablet and desktop overrides. Breakpoints can be configured through command options.
- Container utility: Generates a custom
containerclass using the padding and maximum-width values defined in Figma. - Token references: Resolves nested Figma references such as
{colors.background.bg-secondary}into their actual values. There’s also a--link-primitivesoption to generate CSS variable references instead of repeating values. - Filtering: Supports
--include,--exclude, and--onlyto control which tokens are generated, including filtering by token type. - Consistent output: Normalizes file and token ordering so the same inputs always produce identical CSS, regardless of the order in which files are passed.
ACF Field Validator and Generator (acf-gen)
The second tool handles ACF block field definitions and their corresponding render templates.
It provides two commands:
wp acf-gen check validates and repairs existing fields.php files, while wp acf-gen convert reads a StoutLogic FieldsBuilder definition and generates a matching render.php template.
A few things I focused on when building it:
- Safe file changes: Before writing anything, the tool checks modified PHP using
token_get_all(..., TOKEN_PARSE). If the generated code doesn’t parse, the changes are discarded. - Automatic rollback: If a repaired file fails to load and the original worked, the original file is restored. The rollback is also reported in the command output.
- Existing file protection: If a
render.phpalready exists, generated output goes intotemp-render.phprather than overwriting the existing template. - Repeatable checks: Once a file has been fixed, running the command again reports
0 fix(es)without unnecessarily modifying the file. A--dry-runoption is also available to preview changes. - Clear exit codes: Returns
0when everything is clean and1when errors remain. Warnings alone don’t cause a failure. - Flexible paths: Resolves relative paths against the active theme, so commands can be run from different working directories.
A few implementation details
Both tools follow WordPress’s must-use plugin loading requirements. Since WordPress only automatically loads PHP files directly inside mu-plugins/, each tool has a small entry-point file at the root, with the rest of its implementation kept in its own subfolder.
They also have different compatibility requirements. The Figma token converter uses PHP 7.4-compatible syntax and avoids database operations and unnecessary WordPress API dependencies. The ACF tool requires PHP 8.0+ and uses the StoutLogic ACF Builder autoloader.
Tech stack
WP-CLI, PHP 7.4/8.0+, Tailwind CSS v4, ACF Pro, StoutLogic ACF Builder, Composer, Node.js, Tailwind CLI, Figma, WordPress.
Outcome
Both tools are running on the Ashlar site and were verified in 2026 using WP-CLI 2.12.0, PHP 8.2.0, and Tailwind CSS 4.1.14.
The token converter successfully generates all six CSS files, and wp acf-gen check --dry-run completes cleanly across all five existing ACF blocks.
I haven’t measured time savings across a full development cycle, so I won’t attach an estimated productivity figure to the results.
What I learned
A lot of the work went into handling the details that are easy to overlook.
With Tailwind v4, for example, the order and naming of CSS variables matter. I ran into a case where --spacing-* took precedence over --container-*, causing a named spacing value to be picked up where a container width was expected.
The ACF tool presented a different challenge. Automatically fixing PHP files is useful, but only if the changes are safe. Validating the generated code before writing it and having a rollback mechanism made that possible.
I also found that deterministic output makes a big difference when working with generated code. Being able to run the same conversion with differently ordered inputs and get exactly the same result makes the output much easier to review and maintain.