What is the proper way to validate and sanitize JSON response from REST API?

Thanks to @GTsvetanov from Stackoverflow.com. Missing part of my code is $request->get_json_params(); for getting json request then compare it with schema using rest_validate_value_from_schema() then using rest_sanitize_value_from_schema() for saving proper data to database. $schema = $this->user_playtime_meta_schema(); $val = $request->get_json_params();//<– my mistake $result = rest_validate_value_from_schema( $values, $schema ); if ( ! is_wp_error( rest_validate_value_from_schema( $val, $schema ) ) … Read more

ACF Custom validation message not showing up

Add this snippet and check according to your needed. add_action(‘acf/validate_save_post’, ‘my_acf_validate_save_post’); function my_acf_validate_save_post() { $start = $_POST[‘acf’][‘field_5fb0e816ea4fc’]; //$start = new DateTime($start); $start = strtotime($start); $end = $_POST[‘acf’][‘field_5fb0e83aea4fd’]; //$end = new DateTime($end); $end = strtotime($end); if( current_user_can(‘manage_options’) ) { acf_reset_validation_errors(); } // check custom $_POST data if ($start > $end ) { acf_add_validation_error($_POST[‘acf’][‘field-600e609de8ab8’], ‘End Date should … Read more

Add Div to Comment Form

If you want to add some custom HTML between the </h3> and the <form> tags, you can try the following: /** * Add custom HTML between the `</h3>` and the `<form>` tags in the comment_form() output. */ add_action( ‘comment_form_before’, function(){ add_filter( ‘pre_option_comment_registration’, ‘wpse_156112’ ); }); function wpse_156112( $comment_registration ) { // Adjust this to your … Read more

Validate form in functions.php, send errors back to template

You need a filter not an action. Something like this (notes are commented into the code. You have a few PHP errors that you need to correct): function signup_validate_insert($post){ $errors = false; if (isset($post[‘submit_msg’])) { // validate , insert into database } return $errors; } add_filter(‘signup_insert’, ‘signup_validate_insert’); $errors = apply_filters(‘signup_insert’, $_POST); if((!empty($errors))){ // $errors is … Read more

Best Practice for Validating and Sanitizing Data

Inputs need to be validated/sanitized before making any execution flow decision based on it. Actually a +100 to the reviewer that caught it (or whoever wrote the automated tool) as I would have missed it. Sanitization is something that needs context. Just because function A does a sanitization in the context of storing an displaying … Read more

Settings API – sanitize_callback is not called and it leads to an incorrect behavior

If I take the value sanitize_callback out of the argument array completely, everything works as desired, so error-free. Yes, and that’s because you used the wrong callable syntax which then causes PHP to use a global function named sanitize_options instead of the method/function of the same name in your class (i.e. Faqdesk_Settings::sanitize_options()). So to solve … Read more

How do i validate data entered in a meta box so that only floats can be entered in a field?

Not shure if this isn´t a general php question… Use the WP_Error Class. // http://php.net/manual/de/function.is-float.php // http://php.net/manual/de/function.is-int.php // inside your save_post/update_post hooks callback function, // just type cast to float. You could also do a check if it contains non numeric chars // and then simply return; $check = ! is_float( $value ) OR ! … Read more

Validate Uploaded Image using WordPress’ Built-in Functions?

All of the code in your question can be replaced with: require_once( ABSPATH . ‘wp-admin/includes/image.php’ ); require_once( ABSPATH . ‘wp-admin/includes/file.php’ ); require_once( ABSPATH . ‘wp-admin/includes/media.php’ ); if ( $_FILES ) { foreach ($_FILES as $file => $array) { $image_post_id = media_handler_upload( $file ); if ( is_wp_error( $image_post_id ) ) { $error .= $image_post_id->get_error_message(); } else … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)