Skip to content

Commit

Permalink
Switch email notifications to new emogrifier class
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeyarce committed Apr 20, 2024
1 parent 3a94a31 commit c78d26b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions includes/class-wp-job-manager-email-notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
exit;
}

use Pelago\Emogrifier\CssInliner;
use Pelago\Emogrifier\HtmlProcessor\CssToAttributeConverter;
/**
* Base class for WP Job Manager's email notification system.
*
Expand Down Expand Up @@ -164,9 +166,8 @@ public static function lazy_init() {
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/emails/class-wp-job-manager-email-employer-expiring-job.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/emails/class-wp-job-manager-email-admin-expiring-job.php';

if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) && version_compare( PHP_VERSION, '5.5', '>=' ) ) {
include_once JOB_MANAGER_PLUGIN_DIR . '/lib/emogrifier/class-emogrifier.php';
}
// Load Vendor Autoload for Emogrifier.
require_once JOB_MANAGER_PLUGIN_DIR . '/vendor/autoload.php';
}

/**
Expand Down Expand Up @@ -933,10 +934,12 @@ private static function get_email_content( $email_notification_key, $args, $is_p
* @return string
*/
private static function inject_styles( $content ) {
if ( class_exists( 'Emogrifier' ) ) {
$css_inliner_class = CssInliner::class;
if ( class_exists( $css_inliner_class ) ) {
try {
$emogrifier = new Emogrifier( $content, self::get_styles() );
$content = $emogrifier->emogrify();
$dom_document = CssInliner::fromHtml( $content )->inlineCss( self::get_styles() )->getDomDocument();
$content = CssToAttributeConverter::fromDomDocument( $dom_document )->convertCssToVisualAttributes()->render();

} catch ( Exception $e ) {
trigger_error( 'Unable to inject styles into email notification: ' . $e->getMessage() ); // @codingStandardsIgnoreLine
}
Expand Down

0 comments on commit c78d26b

Please sign in to comment.