您需要一个“换行符”将它们分开!您可以使用html 标签,例如:
仅举几例!
但是您正在使用 esc_html__ 翻译和转义 html。为什么需要使用esc_html__ 从数据库中检索博客名称?为什么?
话虽如此,您可以同时对translate 和escape unwanted html 使用一种白名单技术。
使用wp_kses,您将能够为允许的html 标签定义一个“白名单”并转义其余标签。
您可以阅读更多相关信息:
wp_ksesDocs
和
This post on whitelisting html tags
所以你的代码应该是这样的:
使用<br>标签:
protected function send_account_email( $user_data, $user_id ) {
$whitelist_tags = array(
'br' => array(),
);
$to = $user_data['user_email'];
$subject = sprintf(wp_kses(__('Welcome to %s <br>', 'my-plugin'), $whitelist_tags), get_option( 'blogname' ));
$body = sprintf( esc_html__( 'Thanks for creating account on %1$s. Your username is: %2$s ',
'my-plugin' ), get_option( 'blogname' ), $user_data['user_login'] );
}
或者使用<p>标签:
protected function send_account_email( $user_data, $user_id ) {
$whitelist_tags = array(
'p' => array()
);
$to = $user_data['user_email'];
$subject = sprintf(wp_kses(__('<p>Welcome to %s </p>', 'my-plugin'), $whitelist_tags), get_option( 'blogname' ));
$body = sprintf( esc_html__( 'Thanks for creating account on %1$s. Your username is: %2$s ',
'my-plugin' ), get_option( 'blogname' ), $user_data['user_login'] );
}
或者使用<h1>标签:
protected function send_account_email( $user_data, $user_id ) {
$whitelist_tags = array(
'h1' => array(),
);
$to = $user_data['user_email'];
$subject = sprintf(wp_kses(__('<h1>Welcome to %s </h1>', 'my-plugin'), $whitelist_tags), get_option( 'blogname' ));
$body = sprintf( esc_html__( 'Thanks for creating account on %1$s. Your username is: %2$s ',
'my-plugin' ), get_option( 'blogname' ), $user_data['user_login'] );
}
注意:
-
$whitelist_tags 是一个数组,可以添加多个标签!
- 另外,我只在您的
$subject 变量中使用了这些标签,如果您需要,您也可以在您的$body 变量中使用确切的技术!
- 我还使用了
__() 和wp_kses 的组合而不是esc_html__,以便translate 和escape unwanted html!