arraypress / wp-register-emails
Merge tags, HTML email components and named transactional emails for WordPress plugins.
Requires
- php: >=8.3
Requires (Dev)
- phpcompatibility/phpcompatibility-wp: ^2.1
- phpunit/phpunit: ^12.0
- squizlabs/php_codesniffer: ^3.13.5
- wp-coding-standards/wpcs: ^3.4
Suggests
- arraypress/wp-field-kit: Its email_editor field draws the merge-tag chooser; email_tags_for_editor() feeds it.
- arraypress/wp-money: Formats an amount in the currency an order was placed in.
Provides
None
Conflicts
None
Replaces
None
README
Named transactional emails with merge tags, and HTML that survives Outlook.
What it does
A plugin that sends a receipt needs three things nobody enjoys writing: merge tags a shop owner can put in the subject line, HTML that renders the same in Gmail and Outlook, and a way to preview the result without placing a test order.
This registers tags and emails by name, resolves the tags against whatever object the email is about, and builds the markup from components rather than from a table layout you maintain by hand.
Features
- Register a merge tag with a preview value, so the tester shows something real
- Register an email by name, with its subject and body
- Send one by name, overriding the recipient or subject at the call site
- Preview an email without sending, or triggering whatever produces it
- Build the body from components — buttons, tables, panels — not raw HTML
- Offer the available tags to an editor, so an owner can insert them
Installation
composer require arraypress/wp-register-emails
Quick start
Register what the tags mean:
register_email_tag( 'shop', 'customer_name', [ 'label' => __( 'Customer name', 'my-plugin' ), 'callback' => fn( $order ) => $order->billing_name, 'preview' => 'Jane Doe', ] );
Then the email that uses them:
register_email( 'shop', 'receipt', [ 'subject' => __( 'Your order from {site_name}', 'my-plugin' ), 'content' => __( 'Thanks, {customer_name}.', 'my-plugin' ), ] );
And sending it:
send_registered_email( 'shop', 'receipt', [ 'to' => $order->email ] );
The preview value is what makes the tester useful — without it, previewing
an email means having an order to preview it against.
Tag types
A tag's type says how what its callback returns goes in. text, the
default, goes in as text — a billing name with markup in it reads as the name.
html goes in as it is, for a callback that builds its own markup. Any
component name — button, order_items, alert — draws that component from
what the callback returns. Tags work in the subject line as well as the body.
Requirements
- PHP 8.3 or later
- WordPress 7.1 or later
License
GPL-2.0-or-later