【发布时间】:2019-04-15 05:58:36
【问题描述】:
我目前正在尝试使用 html 内容内联 css,该内容完美但只有一次。当我多次尝试时,我收到此错误:
PHP 致命错误:无法声明类 Emogrifier,因为名称为 已经在使用中
在我的 Wordpress 子主题 functions.php 文件中包含的 email-functions.php 中引发了错误:
/**
* Include email functions for ultimate member
*/
require 'ultimate-member/functions/email-functions.php';
这是导致问题的 email-functions.php 文件中的函数:
/**
* Apply css to UM email message from template
*/
add_filter( 'um_email_send_message_content', 'apply_style_to_email', 10, 99);
function apply_style_to_email($message, $slug, $args ) {
//Get Emogrifier class
include_once get_home_path() . 'wp-content/themes/DiviChild/ultimate-member/libraries/class-emogrifier.php';
ob_start();
include_once get_home_path() . 'wp-content/themes/DiviChild/woocommerce/emails/email-styles.php';
$css = apply_filters( 'woocommerce_email_styles', ob_get_clean() );
// apply CSS styles inline for picky email clients.
try {
$emogrifier = new Emogrifier( $message, $css );
$message = $emogrifier->emogrify();
} catch ( Exception $e ) {
$logger = wc_get_logger();
$logger->error( $e->getMessage(), array( 'source' => 'emogrifier' ) );
}
return $message;
}
如您所见,我正在使用 include_once 来获取 Emogrifier 类。我真的不知道我在这里做错了什么。
这是 Emogrifier 类:https://codeshare.io/50B0ml
【问题讨论】:
标签: php wordpress woocommerce