php - PHP 致命错误:无法声明类 Emogrifier,因为该名称已在使用中
问题描述
我目前正在尝试使用 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
解决方案
该错误很好地描述了您的问题。看起来您的项目中有 2 个同名的类。在这里,NameSpace 可以帮助您。
最好在你的项目文件中搜索关键字“emogrifier”,也许你在项目中有 2 次类。或者该类通过 Composer 来自供应商目录之一,但 Composer Packages NameSpaces 不应该发生这种情况。
推荐阅读
- jenkins - Jenkins 声明性管道 @tmp 文件夹
- javascript - 按 json 键值对列表进行分组并创建一个新列表 javascript
- ruby-on-rails - Rails 6.0 最佳实践中的 secret_key_base
- python - 为什么 venv 包含旧版本的 pip (9.0.3)?
- azure - 使用 Azure CLI 为应用程序见解设置数据保留
- c# - DynamoDB 查询包含一个列表参数
- reactjs - 无法使用 @testing-library/user-event 用新值更新文本区域
- xamarin - Xamarin Forms 不能两次安装相同的应用程序(使用不同的包名称)
- excel - 下载一个特定股票的历史股票价格时 VBA 宏出错:MDB
- angular - 使用 Angular 9 Reactive Forms 为一个输入使用多种模式的方法