如何解决如何在我的网站中验证 WP_editor产品描述框?
在我的网站上,我有一个产品描述框,来自 dokan 插件。我有前端产品添加表单,在该表单中我有一个 WP_editor 文本区域。我需要验证它。但我做了一些研究并找到了一些代码来验证它,但它不起作用。
如果我添加描述框的内容,它总是显示错误信息。
我做错了什么? 请帮我。 感谢您的宝贵时间。?
这是子主题/功能.php中的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;
}
谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。