Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • FYI, same problem happened on my website.

    The php file uploaded in wp-content/uploads was using the script https://pastebin.com/raw/jmxnY3Rk that includes a JS script in all posts via a MySQL query.

    There is a small bug in your code, you forgot to do an array_shift in your block “$data[$field]===null”.

    Here is a the correct insert function. Do the same for the update function.

    function insert($table, $data, $format = null) {
    $formats = $format = (array) $format;
    $fields = array_keys($data);
    $formatted_fields = array();
    $real_data = array();
    foreach ( $fields as $field ) {
    if ( !empty($format) )
    $form = ( $form = array_shift($formats) ) ? $form : $format[0];
    elseif ( isset($this->field_types[$field]) )
    $form = $this->field_types[$field];
    else
    $form = ‘%s’;

    if ($data[$field]===null) {
    $formatted_fields[] = ‘NULL’;
    }
    else {
    $formatted_fields[] = “‘”.$form.”‘”;
    $real_data[] = $data[$field];
    }
    }
    $sql = “INSERT INTO $table (" . implode( ',', $fields ) . ") VALUES (” . implode( “,”, $formatted_fields ) . “)”;
    return $this->query( $this->prepare( $sql, $real_data) );
    }

    Thanks for sharing. Very useful.

    Should be included in core.

Viewing 3 replies - 1 through 3 (of 3 total)