Your plugin can add its own email templates to Settings > Email templates. The admin can edit them there and add other languages, just like the RISE templates. Don't build your own email template page.
Add a template
Call this from your plugin's index.php file:
register_email_template("my_plugin_document_approved", array(
"category" => "my_plugin_documents",
"subject" => "Document approved: {DOCUMENT_TITLE}",
"message" => "{EVENT_TITLE}
{DOCUMENT_TITLE}
{EVENT_DETAILS}{SIGNATURE}",
"variables" => array("DOCUMENT_TITLE")
));
| Option | Required | What it does |
| category | Yes | Language key of the group name on the email templates page. |
| subject | Yes | The default subject. |
| message | Yes | The default message in HTML. Use inline styles, because most email apps ignore CSS. |
| variables | No | The variables shown under the editor, without the { } brackets. |
- The template name is shown from the language key with the same name.
- Template names use only small letters, numbers and underscores, start with a letter, and have 50 characters or less. You can't reuse a template name of RISE.
- RISE adds the template by itself the first time it is used, or when the admin opens the email templates page.
- When the template is used by a notification (the email_template option of register_notification_event()), these variables are also available: EVENT_TITLE, EVENT_DETAILS, NOTIFICATION_URL, TO_USER_NAME, APP_TITLE, COMPANY_NAME, LOGO_URL, SIGNATURE, RECIPIENTS_EMAIL_ADDRESS.
Send an email without a notification
send_email_template("my_plugin_document_approved", $email, array("DOCUMENT_TITLE" => $title), $user_language);
- Parameters: send_email_template($template_name, $to_email, $parser_data = array(), $language = "", $email_options = array()). It returns the result of send_app_mail().
- It uses the template in the given language if there is one. If not, it uses the default template.
- It adds SIGNATURE, LOGO_URL, APP_TITLE, COMPANY_NAME and RECIPIENTS_EMAIL_ADDRESS by itself.
- It works with the RISE templates too.
- The same values are used in the subject and the message, and they are added as they are. So escape what users typed when the value goes in the message. Don't escape values for the subject, because the subject is plain text and would show codes like &.