Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #32315, comment 17


Ignore:
Timestamp:
11/01/2016 12:45:47 AM (8 years ago)
Author:
procodewp
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #32315, comment 17

    initial v1  
    11I`ve been looking into this over the weekend and found the following:
    22
    3 When you call the insert() or update() routine in wpdb, it's calling process_fields().
     3When you call the `insert()` or `update()` routine in wpdb, it's calling `process_fields()`.
    44
    5 Inside of process_fields(), it calls strip_invalid_text() which removes invalid characters, and also truncates the data to the field length.
     5Inside of `process_fields()`, it calls `strip_invalid_text()` which removes invalid characters, and also truncates the data to the field length.
    66
    7 When strip_invalid_text() returns the amended $data, the following code is run:
     7When `strip_invalid_text()` returns the amended `$data`, the following code is run:
    88
    99{{{
     
    1313}}}
    1414
    15 This compares the original $data with the $converted_data returned from the strip_invalid_text() function, and if anything has been changed it returns false.
     15This compares the original `$data` with the `$converted_data` returned from the `strip_invalid_text()` function, and if anything has been changed it returns `false`.
    1616
    1717This stops the operation from occuring, without an error message. So if any invalid characters are removed, or the field is truncated, everything stops.
     
    2121>>You realize how much extra code an insert would require if you error? Every insert var would have to be checked for length prior to insert.
    2222
    23 This is already happening, each insert var string passes through process_field_lengths which gets the size of the database field. strip_invalid_text() then uses this to truncate the field if necessary.
     23This is already happening, each insert var string passes through `process_field_lengths()` which gets the size of the database field. `strip_invalid_text()` then uses this to truncate the field if necessary.
    2424
    25 I`m not not sure of the best way to handle this. It would be possible to run through the $data array and compare it to the $converted_data array returned from strip_invalid_text(), which would allow a list of any fields with data thats been changed. But what would be the best way to display this information to the user?
     25I'm not not sure of the best way to handle this. It would be possible to run through the `$data` array and compare it to the `$converted_data array` returned from `strip_invalid_text()`, which would allow a list of any fields with data that's been changed. But what would be the best way to display this information to the user?
    2626
    2727Would it be worth creating a variable to hold internal errors, for errors in functions that occur before a database operation?