首页 > 解决方案 > 所见即所得不添加段落标签

问题描述

我正在使用以下几行向 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,但它不能解决问题。

标签: woocommerce

解决方案


推荐阅读