Viewing 7 reply threads
  • Author
    Posts
    • #4402
      justin
      Member

      When 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 1207
      

      It 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'
        )
      )
       ));
      
    • #4404
      Steve
      Keymaster

      @justin– I suggest you open the file: /home/micdri10/EXTREMESOUTHAMERICA.COM/wp-includes/wp-db.php on line 1092. You should see this return 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.

    • #4406
      justin
      Member

      So 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');
        }
       
      }
      
    • #4407
      Steve
      Keymaster

      @justin– where do we have$field['value'][0] set?

    • #4408
      justin
      Member

      $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”.

    • #4409
      Steve
      Keymaster

      @justin– Do you see this as an issue with Piklist, or your code?

    • #4410
      justin
      Member

      @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,

    • #4411
      Steve
      Keymaster

      Great! Closing ticket. Thanks

Viewing 7 reply threads
  • The topic ‘Warnings when savings a user’ is closed to new replies.