Skip to content

Commit 471c42b

Browse files
swissspidyclaude
andcommitted
Apply --callback to --export
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5pwpi2xQfDA6mUYkkx
1 parent 9369699 commit 471c42b

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎features/search-replace-callback.feature‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,32 @@ Feature: Test search-replace --callback option
239239
"""
240240
FOO bar
241241
"""
242+
243+
@require-mysql
244+
Scenario: Callback is applied to an export
245+
Given a WP install
246+
And a callback-function.php file:
247+
"""
248+
<?php
249+
function test_callback( $data, $replacement ) {
250+
return str_replace( 'foo', strtoupper( $replacement ), $data );
251+
}
252+
"""
253+
And I run `wp post create --post_title='foo bar' --porcelain`
254+
And save STDOUT as {POST_ID}
255+
256+
When I run `wp search-replace 'foo' 'baz' wp_posts --include-columns=post_title --callback='test_callback' --require=callback-function.php --export`
257+
Then STDOUT should contain:
258+
"""
259+
'BAZ bar'
260+
"""
261+
And STDOUT should not contain:
262+
"""
263+
'baz bar'
264+
"""
265+
266+
When I run `wp post get {POST_ID} --field=title`
267+
Then STDOUT should be:
268+
"""
269+
foo bar
270+
"""

‎src/Search_Replace_Command.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ private function php_export_table( $table, $old, $new ) {
769769
'chunk_size' => $chunk_size,
770770
);
771771

772-
$replacer = new SearchReplacer( $old, $new, $this->recurse_objects, $this->regex, $this->regex_flags, $this->regex_delimiter, false, $this->regex_limit );
772+
$replacer = new SearchReplacer( $old, $new, $this->recurse_objects, $this->regex, $this->regex_flags, $this->regex_delimiter, false, $this->regex_limit, $this->callback );
773773
$col_counts = array_fill_keys( $all_columns, 0 );
774774
if ( $this->verbose && 'table' === $this->format ) {
775775
$this->start_time = microtime( true );

0 commit comments

Comments
 (0)