In my website i have a product description box, is coming from dokan plugin. I have front end product add form, In that form i have a WP_editor text area. I need to validate it. but i did some research and find some code to validate it but its not working.
If I add the content of the description box its always show the error message.
What I'm doing wrong? please help me. Thanks for your valuable time.😊
Here is the WP_editor Validate code in child theme/funtion.php
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', 'dokan_can_add_product_validation_customized', 35, 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', 35, 2 );
code of 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>
Guys i found a solutions,
after doing big research i found a method to validate WP_editor.
Here is my code in child theme/funtion.php
function dokan_can_add_product_validation_customized( $errors ) {
if (empty($_POST['post_content'])) {
$errors[] = 'Please insert a Description ';
}
return $errors;
}
Thank you