Tagged: user, validation, warnings
- This topic has 7 replies, 2 voices, and was last updated 6 years, 4 months ago by
Steve.
-
AuthorPosts
-
-
September 28, 2015 at 1:03 pm #4402
justinMemberWhen I save one of the pages I have created in my profile flow I consitently get these warnings. After I save it I get a blank white page with these warnings:
Warning: mysqli_real_escape_string() expects parameter 2 to be string, array given in /home/micdri10/EXTREMESOUTHAMERICA.COM/wp-includes/wp-db.php on line 1092 Warning: mysqli_real_escape_string() expects parameter 2 to be string, array given in /home/micdri10/EXTREMESOUTHAMERICA.COM/wp-includes/wp-db.php on line 1092 Warning: mysqli_real_escape_string() expects parameter 2 to be string, array given in /home/micdri10/EXTREMESOUTHAMERICA.COM/wp-includes/wp-db.php on line 1092 Warning: mysqli_real_escape_string() expects parameter 2 to be string, array given in /home/micdri10/EXTREMESOUTHAMERICA.COM/wp-includes/wp-db.php on line 1092 Warning: mysqli_real_escape_string() expects parameter 2 to be string, array given in /home/micdri10/EXTREMESOUTHAMERICA.COM/wp-includes/wp-db.php on line 1092 Warning: Cannot modify header information - headers already sent by (output started at /home/micdri10/EXTREMESOUTHAMERICA.COM/wp-includes/wp-db.php:1092) in /home/micdri10/EXTREMESOUTHAMERICA.COM/wp-includes/pluggable.php on line 1207It does successfully save the information, but it is pretty annoying.
I have narrowed it down to validation rule I have created.
This is the validation rule that is on my functions page
//Validation RULES add_filter('piklist_validation_rules', 'check_if_unique', 11); function check_if_unique($validation_rules) { $validation_rules['custom_unique'] = array( 'callback' => 'my_validate_unique' ); return $validation_rules; } function my_validate_unique($file, $field, $arguments) { global $user_id; $user_profile_id = $user_id; $user_query = new WP_User_Query( array( 'meta_key' => 'user_custom_url' ,'meta_value' => $field ,'exclude' =>$user_profile_id ) ); $userscount = $user_query->get_total(); if($userscount != 1 ) { return true; }else{ return __('is not unique and or used unsupported characters. ONLY letters and numbers.', 'Extreme'); } }This is the field that calls that validation. If I remove the validate parameter I do not receive the errors anymore.
piklist('field', array( 'type' => 'text' ,'field' => 'user_custom_url' ,'label' => 'URL of your profile' ,'validate' => array( array( 'type' => 'custom_unique' ) ) )); -
September 29, 2015 at 2:32 pm #4404
SteveKeymaster@justin– I suggest you open the file:
/home/micdri10/EXTREMESOUTHAMERICA.COM/wp-includes/wp-db.php on line 1092. You should see thisreturn mysqli_real_escape_string( $this->dbh, $string );Right before it, add this:
print_r($string);That will tell you what you’re passing and might help you fix your rule.
-
September 29, 2015 at 3:28 pm #4406
justinMemberSo I figured it out. It had to do with $field. It returns an array and you have to
$field['value'][0];to get the value of that field.If anyone wants the fixed code for an example of a validation rule here is the fixed code:
add_filter('piklist_validation_rules', 'check_if_unique', 11); function check_if_unique($validation_rules) { $validation_rules['custom_unique'] = array( 'type' => 'safe_text', 'callback' => 'my_validate_unique' ); return $validation_rules; } function my_validate_unique($file, $field, $arguments) { if (! empty($_GET['user_id']) && is_numeric($_GET['user_id']) ) { $user_profile_id = $_GET['user_id']; // Otherwise something is wrong. } else { $current_user = wp_get_current_user(); $user_profile_id = $current_user->ID; } $thereturned_field = $field['value'][0]; $duplicate_url = new WP_User_Query( array( 'meta_key' => 'user_custom_url', 'meta_value' => $thereturned_field, 'exclude' =>$user_profile_id ) ); $userscount = $duplicate_url->get_total(); if($userscount != 1 ) { return true; }else{ return __('is not unique and or used unsupported characters. ONLY letters and numbers.', 'Extreme'); } } -
October 1, 2015 at 2:54 pm #4407
-
October 1, 2015 at 3:08 pm #4408
justinMember$field is being brought down by your function I am just passing it into my function. $field ends up being a large array. Here is the array that it prints out:
Array ( [field] => user_custom_url [type] => text [label] => URL of your profile [description] => [prefix] => 1 [scope] => user_meta [value] => Array ( [0] => Adams ) [capability] => [role] => [logged_in] => [add_more] => [sortable] => [choices] => [list] => 1 [position] => [template] => user_meta [wrapper] => [field_wrapper][/field_wrapper][field_label] [field][field_description_wrapper][field_description][/field_description_wrapper] [columns] => [embed] => [editable] => 1 [child_field] => [label_position] => before [conditions] => [options] => [on_post_status] => [on_comment_status] => [display] => [group_field] => [required] => [index] => [multiple] => [errors] => [attributes] => Array ( [class] => Array ( [0] => _user_meta_user_custom_url ) [title] => [alt] => [tabindex] => [columns] => [value] => ) [tax_query] => Array ( [include_children] => 1 [field] => term_id [operator] => IN ) [meta_query] => Array ( [compare] => = [type] => CHAR ) [validate] => Array ( [0] => Array ( [type] => custom_unique ) ) [name] => _user_meta[user_custom_url][] [id] => [request_value] => Array ( [0] => Adams ) [valid] => 1 )So I have to go into the first portion of the array value in order to get what was actually put into the text field. so $field[‘value’][0] is set when the user types into the text box and enters in this case “Adams”.
-
October 1, 2015 at 4:11 pm #4409
-
October 1, 2015 at 4:21 pm #4410
justinMember@Steve,
I think there is some miscommunication. Your first post pointed me in the right direction to fix the problem. I just posted back on this, in case anyone else was using the $field variable in the function how to properly use it and pull the value from it. I don’t see a problem with how the array is.
Thanks,
-
October 1, 2015 at 4:23 pm #4411
SteveKeymasterGreat! Closing ticket. Thanks
-
-
AuthorPosts
- The topic ‘Warnings when savings a user’ is closed to new replies.