Skip to content

Commit

Permalink
Merge pull request #43 from mullnerz/master
Browse files Browse the repository at this point in the history
Fix: Changed behaviour of esc_sql() in WordPress 4.8.3
  • Loading branch information
gitlost authored Nov 10, 2017
2 parents a823ffa + 131201e commit f593506
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
15 changes: 15 additions & 0 deletions features/search-replace-export.feature
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,18 @@ Feature: Search / replace with file export
wp_users display_name 0 PHP
"""
And STDERR should be empty

Scenario: Search / replace should remove placeholder escape on export
Given a WP install
And I run `wp post create --post_title=test-remove-placeholder-escape% --porcelain`
Then save STDOUT as {POST_ID}

When I run `wp search-replace baz bar --export | grep test-remove-placeholder-escape`
Then STDOUT should contain:
"""
'test-remove-placeholder-escape%'
"""
And STDOUT should not contain:
"""
'test-remove-placeholder-escape{'
"""
9 changes: 8 additions & 1 deletion src/Search_Replace_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,14 @@ private function write_sql_row_fields( $table, $rows ) {
if( ( $index % $export_insert_size == 0 && $index > 0 ) || $index == $count ) {
$sql .= ";\n";

$sql = $wpdb->prepare( $sql, array_values( $values ) );
if( method_exists( $wpdb, 'remove_placeholder_escape' ) ) {
// since 4.8.3
$sql = $wpdb->remove_placeholder_escape( $wpdb->prepare( $sql, array_values( $values ) ) );
} else {
// 4.8.2 or less
$sql = $wpdb->prepare( $sql, array_values( $values ) );
}

fwrite( $this->export_handle, $sql );

// If there is still rows to loop, reset $sql and $values variables.
Expand Down

0 comments on commit f593506

Please sign in to comment.