Skip to content

Commit 894ee48

Browse files
swissspidyclaude
andcommitted
Apply --callback to a value of '0' in an export
The export skipped every falsy value, so a callback never saw the string '0' there, while the live run passes it on. Only skip NULL and empty values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5pwpi2xQfDA6mUYkkx
1 parent 42c9851 commit 894ee48

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎features/search-replace-callback.feature‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,30 @@ Feature: Test search-replace --callback option
269269
foo bar
270270
"""
271271

272+
@require-mysql
273+
Scenario: Callback is applied to a value of 0 in an export
274+
Given a WP install
275+
And a callback-zero.php file:
276+
"""
277+
<?php
278+
function zero_callback( $data, $replacement ) {
279+
return '0' === $data ? 'ZERO' : $data;
280+
}
281+
"""
282+
And I run `wp option add zero_test_option 0`
283+
284+
When I run `wp search-replace '0' 'ignored' wp_options --include-columns=option_value --callback='zero_callback' --require=callback-zero.php --export`
285+
Then STDOUT should contain:
286+
"""
287+
'zero_test_option', 'ZERO'
288+
"""
289+
290+
When I run `wp option get zero_test_option`
291+
Then STDOUT should be:
292+
"""
293+
0
294+
"""
295+
272296
@require-mysql
273297
Scenario: Log shows the value the callback returned
274298
Given a WP install

‎src/Search_Replace_Command.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ private function php_export_table( $table, $old, $new ) {
781781
$row_fields = array();
782782
foreach ( $all_columns as $col ) {
783783
$value = $row->$col;
784-
if ( $value
784+
if ( null !== $value && '' !== $value
785785
&& ! in_array( $col, $primary_keys, true )
786786
&& ! in_array( $col, $this->skip_columns, true )
787787
&& ! in_array( $table . '.' . $col, $this->skip_columns, true )

0 commit comments

Comments
 (0)