问题描述
在我的网站上,我有一个产品描述框,来自 dokan 插件。我有前端产品添加表单,在该表单中我有一个 WP_editor 文本区域。我需要验证它。但我做了一些研究并找到了一些代码来验证它,但它不起作用。
我做错了什么? 请帮我。 感谢您的宝贵时间。?
function dokan_can_add_product_validation_customized( $errors ) {
$post_content= absint( sanitize_textarea_field( $postdata['post_content'] ) );
if ( empty( $post_content) && ! in_array( 'Please des',$errors ) ) {
$errors[] = 'Please insert a description';
}
return $errors;
}
add_filter( 'dokan_can_add_product','dokan_can_add_product_validation_customized',35,1 );
add_filter( 'dokan_can_edit_product',1 );
function dokan_new_product_popup_validation_customized( $errors,$data ) {
if ( ! $data['post_content'] ) {
return new WP_Error( 'no-price',__( 'Please insert a description','dokan-lite' ) );
}
}
add_filter( 'dokan_new_product_popup_args','dokan_new_product_popup_validation_customized',2 );
wp_editor 代码 -
<div class="dokan-form-group">
<label for="post_content" class="control-label"><?PHP esc_html_e( 'Description','dokan-lite' ) ?>
<i class="fa fa-question-circle tips" data-title="<?PHP esc_attr_e( 'Add your product description','dokan-lite' ) ?>"
aria-hidden="true"></i></label>
<?PHP wp_editor( htmlspecialchars_decode( $post_content,ENT_QUOTES ),'post_content',array('editor_height' => 50,'quicktags' => false,'media_buttons' => false,'teeny' => true,'editor_class' => 'post_content') ); ?>
</div>
解决方法
伙计们,我找到了解决方案,
经过大量研究后,我找到了一种验证 WP_editor 的方法。
这是我在子主题/funtion.php 中的代码
function dokan_can_add_product_validation_customized( $errors ) {
if (empty($_POST['post_content'])) {
$errors[] = 'Please insert a Description ';
}
return $errors;
}
谢谢