string, 'value' => string, 'tone' => 'good'|'warn'|'bad'|''], …]
* @param array $action ['label' => string, 'url' => string] or []
* @param string $footnote Optional small print under the button.
*/
public static function send($subject, $heading, $intro, array $rows = [], array $action = [], $footnote = '')
{
$to = self::recipient();
if (!is_email($to)) {
return false;
}
$headers = ['Content-Type: text/html; charset=UTF-8'];
return wp_mail($to, $subject, self::body($heading, $intro, $rows, $action, $footnote), $headers);
}
protected static function body($heading, $intro, array $rows, array $action, $footnote)
{
$siteName = get_bloginfo('name');
$siteUrl = home_url('/');
$html = '
';
$html .= '';
$html .= '';
$html .= '';
$html .= '| ';
$html .= ' Crownify ';
$html .= '' . esc_html($heading) . '';
if ('' !== $intro) {
$html .= '' . wp_kses($intro, ['strong' => [], 'em' => []]) . ' ';
}
$html .= ' | ';
if (!empty($rows)) {
$html .= '';
$html .= '';
foreach ($rows as $row) {
$tone = isset($row['tone']) ? $row['tone'] : '';
$color = 'bad' === $tone ? '#b91c1c' : ('warn' === $tone ? '#b45309' : ('good' === $tone ? '#047857' : '#111827'));
$html .= '';
$html .= '| ' . esc_html($row['label']) . ' | ';
$html .= '' . esc_html($row['value']) . ' | ';
$html .= ' ';
}
$html .= ' | ';
}
if (!empty($action['url']) && !empty($action['label'])) {
$html .= '| ';
$html .= '' . esc_html($action['label']) . '';
$html .= ' | ';
}
if ('' !== $footnote) {
$html .= '| ' . wp_kses($footnote, ['strong' => [], 'em' => []]) . ' | ';
}
$html .= '| ';
$html .= sprintf(
/* translators: 1: site name, 2: link to the notification settings screen. */
esc_html__('Sent by Crownify for %1$s. Change what gets sent, or stop these emails, in %2$s.', 'crownify'),
'' . esc_html($siteName) . '',
'' . esc_html__('Crownify → Settings → Notifications', 'crownify') . '',
);
$html .= ' | ';
$html .= ' |
';
return $html;
}
}