Installation

Install the Package#Copied!

 1composer require millipress/acorn-millirules

The service provider is registered automatically via the extra.acorn.providers key in the package's composer.json — no manual registration needed.

Publish Config and Stubs#Copied!

Publish the configuration file and stub templates:

 1wp acorn vendor:publish --tag=millirules

This publishes:

File Location
Configuration config/millirules.php
Rule stub stubs/millirules/rule.stub
Action stub stubs/millirules/action.stub
Condition stub stubs/millirules/condition.stub
Tip: Publishing is optional. The package works out of the box with sensible defaults. Publish only if you need to customize the middleware configuration or scaffold templates.

Verify the Installation#Copied!

Run these commands to confirm everything is registered:

 1# List registered packages (should show PHP, Acorn, and optionally WP)
 2wp acorn rules:packages
 3
 4# List available action types
 5wp acorn rules:actions
 6
 7# List available condition types
 8wp acorn rules:conditions

You should see the Acorn package listed with its redirect, set_header actions and route_name, route_parameter, route_controller conditions.

Your First Rule#Copied!

Let's create a rule that adds security headers to all documentation pages.

1. Scaffold the Rule#Copied!

 1wp acorn rules:make:rule SecurityHeaders

This creates app/Rules/SecurityHeaders.php:

 1<?php
 2
 3namespace AppRules;
 4
 5use MilliRulesRules;
 6
 7class SecurityHeaders
 8{
 9    /**
10     * Register this rule with MilliRules.
11     *
12     * Called automatically by the ServiceProvider.
13     */
14    public function register(): void
15    {
16        Rules::create('security-headers')
17            ->when()
18                // ->routeName('example.route')
19                // ->requestUrl('/example/*', 'LIKE')
20            ->then()
21                // ->setHeader('X-Custom', 'value')
22            ->register();
23    }
24}

2. Fill in the Rule#Copied!

Replace the placeholders with real conditions and actions:

 1<?php
 2
 3namespace AppRules;
 4
 5use MilliRulesRules;
 6
 7class SecurityHeaders
 8{
 9    public function register(): void
10    {
11        Rules::create('security-headers')
12            ->when()
13                ->routeName('docs.*', 'LIKE')
14            ->then()
15                ->setHeader('X-Content-Type-Options', 'nosniff')
16                ->setHeader('X-Frame-Options', 'DENY')
17            ->register();
18    }
19}

This rule matches any route whose name starts with docs. and adds two security headers to the response.

3. Verify the Rule#Copied!

 1# List all rules — you should see security-headers
 2wp acorn rules:list
 3
 4# Show details for this specific rule
 5wp acorn rules:show security-headers

The rules:show command displays the rule's conditions, actions, and metadata:

Rule ID ................................... security-headers
Package ............................................. Acorn
Order .................................................. 10
Enabled ............................................... Yes
Match Type ............................................ all

Conditions (1)
  route_name LIKE docs.*

Actions (2)
  set_header {"name":"X-Content-Type-Options","value":"nosniff"}
  set_header {"name":"X-Frame-Options","value":"DENY"}
Important: Rules are auto-discovered from app/Rules/*.php. There is no registration step beyond creating the file — the service provider finds and calls register() automatically.

Next Steps#Copied!