@@ -37,6 +37,11 @@ class Search_Replace_Command extends WP_CLI_Command {
3737 */
3838 private $ recurse_objects ;
3939
40+ /**
41+ * @var bool
42+ */
43+ private $ replace_keys ;
44+
4045 /**
4146 * @var bool
4247 */
@@ -214,6 +219,9 @@ class Search_Replace_Command extends WP_CLI_Command {
214219 * : Enable recursing into objects to replace strings. Defaults to true;
215220 * pass --no-recurse-objects to disable.
216221 *
222+ * [--replace-keys]
223+ * : Enable replacing string keys in serialized arrays.
224+ *
217225 * [--verbose]
218226 * : Prints rows to the console as they're updated.
219227 *
@@ -287,7 +295,7 @@ class Search_Replace_Command extends WP_CLI_Command {
287295 * fi
288296 *
289297 * @param array<string> $args Positional arguments.
290- * @param array{'old'?: string, 'new'?: string, 'dry-run'?: bool, 'network'?: bool, 'all-tables-with-prefix'?: bool, 'all-tables'?: bool, 'export'?: string, 'export_insert_size'?: string, 'skip-tables'?: string, 'skip-columns'?: string, 'include-columns'?: string, 'precise'?: bool, 'recurse-objects'?: bool, 'verbose'?: bool, 'regex'?: bool, 'regex-flags'?: string, 'regex-delimiter'?: string, 'regex-limit'?: string, 'format': string, 'report'?: bool, 'report-changed-only'?: bool, 'log'?: string, 'before_context'?: string, 'after_context'?: string} $assoc_args Associative arguments.
298+ * @param array{'old'?: string, 'new'?: string, 'dry-run'?: bool, 'network'?: bool, 'all-tables-with-prefix'?: bool, 'all-tables'?: bool, 'export'?: string, 'export_insert_size'?: string, 'skip-tables'?: string, 'skip-columns'?: string, 'include-columns'?: string, 'precise'?: bool, 'recurse-objects'?: bool, 'replace-keys'?: bool, ' verbose'?: bool, 'regex'?: bool, 'regex-flags'?: string, 'regex-delimiter'?: string, 'regex-limit'?: string, 'format': string, 'report'?: bool, 'report-changed-only'?: bool, 'log'?: string, 'before_context'?: string, 'after_context'?: string} $assoc_args Associative arguments.
291299 */
292300 public function __invoke ( $ args , $ assoc_args ) {
293301 global $ wpdb ;
@@ -333,6 +341,7 @@ public function __invoke( $args, $assoc_args ) {
333341 $ this ->dry_run = Utils \get_flag_value ( $ assoc_args , 'dry-run ' , false );
334342 $ php_only = Utils \get_flag_value ( $ assoc_args , 'precise ' , false );
335343 $ this ->recurse_objects = Utils \get_flag_value ( $ assoc_args , 'recurse-objects ' , true );
344+ $ this ->replace_keys = Utils \get_flag_value ( $ assoc_args , 'replace-keys ' , false );
336345 $ this ->verbose = Utils \get_flag_value ( $ assoc_args , 'verbose ' , false );
337346 $ this ->format = Utils \get_flag_value ( $ assoc_args , 'format ' );
338347 $ this ->regex = Utils \get_flag_value ( $ assoc_args , 'regex ' , false );
@@ -638,7 +647,7 @@ private function php_export_table( $table, $old, $new ) {
638647 'chunk_size ' => $ chunk_size ,
639648 );
640649
641- $ replacer = new SearchReplacer ( $ old , $ new , $ this ->recurse_objects , $ this ->regex , $ this ->regex_flags , $ this ->regex_delimiter , false , $ this ->regex_limit );
650+ $ replacer = new SearchReplacer ( $ old , $ new , $ this ->recurse_objects , $ this ->replace_keys , $ this -> regex , $ this ->regex_flags , $ this ->regex_delimiter , false , $ this ->regex_limit );
642651 $ col_counts = array_fill_keys ( $ all_columns , 0 );
643652 if ( $ this ->verbose && 'table ' === $ this ->format ) {
644653 $ this ->start_time = microtime ( true );
@@ -743,7 +752,7 @@ private function php_handle_col( $col, $primary_keys, $table, $old, $new ) {
743752 global $ wpdb ;
744753
745754 $ count = 0 ;
746- $ replacer = new SearchReplacer ( $ old , $ new , $ this ->recurse_objects , $ this ->regex , $ this ->regex_flags , $ this ->regex_delimiter , null !== $ this ->log_handle , $ this ->regex_limit );
755+ $ replacer = new SearchReplacer ( $ old , $ new , $ this ->recurse_objects , $ this ->replace_keys , $ this -> regex , $ this ->regex_flags , $ this ->regex_delimiter , null !== $ this ->log_handle , $ this ->regex_limit );
747756
748757 $ table_sql = self ::esc_sql_ident ( $ table );
749758 $ col_sql = self ::esc_sql_ident ( $ col );
0 commit comments