You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Verify opts parameter exists and has expected structure
156
+
if ( !is_array( $opts ) ) {
157
+
throw new Exception( 'Expected $opts to be an array, got: ' . gettype( $opts ) );
158
+
}
159
+
if ( !isset( $opts['table'] ) ) {
160
+
throw new Exception( 'Expected $opts["table"] to be set' );
161
+
}
162
+
// Verify we're processing wp_posts table
163
+
if ( strpos( $opts['table'], 'posts' ) === false ) {
164
+
throw new Exception( 'Expected table to contain "posts", got: ' . $opts['table'] );
165
+
}
166
+
return str_replace( 'foo', $replacement, $data );
167
+
} elseif ( strpos( $data, 'foo' ) !== false ) {
168
+
// For other columns, just do the replacement without assertions
169
+
return str_replace( 'foo', $replacement, $data );
170
+
}
171
+
return $data;
172
+
}
173
+
"""
174
+
And I run `wp post create --post_title='foo title' --post_content='foo content here' --porcelain`
175
+
And save STDOUT as {POST_ID}
176
+
177
+
When I run `wp search-replace 'foo''verified' wp_posts --include-columns=post_content --callback='opts_callback' --precise --require=callback-opts.php`
178
+
Then STDOUT should contain:
179
+
"""
180
+
Success: Made 1 replacement.
181
+
"""
182
+
183
+
When I run `wp post get {POST_ID} --field=content`
@@ -219,7 +219,12 @@ class Search_Replace_Command extends WP_CLI_Command {
219
219
* : Prints rows to the console as they're updated.
220
220
*
221
221
* [--callback=<user-function>]
222
-
* : Runs a user-specified function on each string that contains <old>. <new> is passed as the second argument and the regex string as the third if it exists: call_user_func( 'callback', $data, $new, $search_regex ).
222
+
* : Runs a user-specified function on each string that contains <old>. The callback is called as follows:
0 commit comments