woocommerce - 所见即所得不添加段落标签
问题描述
我正在使用以下几行向 WooCommerce 添加自定义文本区域:
if ( ! function_exists( 'add_custom_content_meta_box' ) ){
function add_custom_content_meta_box( $post ){
$prefix = 'Couach';
$detail = get_post_meta($post->ID, $prefix.'detail_wysiwyg', true) ? get_post_meta($post->ID, $prefix.'detail_wysiwyg', true) : '';
$args['textarea_rows'] = 8;
wp_editor( $detail, 'detail_wysiwyg', $args );
}
}
//Save the data of the Meta field
add_action( 'save_post', 'save_custom_content_meta_box', 10, 1 );
if ( ! function_exists( 'save_custom_content_meta_box' ) )
{
function save_custom_content_meta_box( $post_id ) {
$prefix = 'Couach'; // global $prefix;
if ( ! isset( $_POST[ 'custom_product_field_nonce' ] ) ) {
return $post_id;
}
$nonce = $_REQUEST[ 'custom_product_field_nonce' ];
//Verify that the nonce is valid.
if ( ! wp_verify_nonce( $nonce ) ) {
return $post_id;
}
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
// Check the user's permissions.
if ( 'product' == $_POST[ 'post_type' ] ){
if ( ! current_user_can( 'edit_product', $post_id ) )
return $post_id;
} else {
if ( ! current_user_can( 'edit_post', $post_id ) )
return $post_id;
}
update_post_meta( $post_id, $prefix.'detail_wysiwyg', wp_kses_post($_POST[ 'detail_wysiwyg' ]) );
}
}
}
但是出人意料WYSIWYG
的去掉<p>
了标签,甚至按回车后没有加p标签。我尝试删除wp_kses_post
,但它不能解决问题。
解决方案
推荐阅读
- java - JPA LOJ(左外连接):无法连接到基本类型的属性
- java - Spring Boot maven 插件:spring-boot:start 立即关闭 Web 应用(使用 jetty)
- tsql - 根据 SQL 中的范围计算拆分余额
- php - SQLSTATE [23000]:违反完整性约束:1048 列 'category_id' 不能为空
- c++ - 在 OpenGL 中正确渲染表面并进行深度测试
- php - 用 PDO 创建 php 数据库连接的正确方法是什么?
- dart - 如何解析迄今为止的 Youtube 持续时间?
- python - 如何使用 timedelta x 轴从 pandas 图中更改 xticklables?
- javascript - Display updated time each seconds in react function
- r - 来自给定范围的 R 独特组合快速且使用更少的系统资源