@@ -36,6 +36,7 @@ class Export_Command extends WP_CLI_Command {
3636 private $ max_file_size ;
3737 private $ include_once ;
3838 private $ wxr_path ;
39+ private $ exclude = [];
3940
4041 /**
4142 * Exports WordPress content to a WXR file.
@@ -56,6 +57,12 @@ class Export_Command extends WP_CLI_Command {
5657 * [--skip_comments]
5758 * : Don't include comments in the WXR export file.
5859 *
60+ * [--skip_authors]
61+ * : Don't include authors in the WXR export file.
62+ *
63+ * [--skip_terms]
64+ * : Don't include terms (categories, tags, custom taxonomy terms and nav menu terms) in the WXR export file.
65+ *
5966 * [--max_file_size=<MB>]
6067 * : A single export file should have this many megabytes. -1 for unlimited.
6168 * ---
@@ -150,6 +157,8 @@ public function __invoke( $_, $assoc_args ) {
150157 'with_attachments ' => true , // or FALSE if user requested some post__in
151158 'start_id ' => null ,
152159 'skip_comments ' => null ,
160+ 'skip_authors ' => null ,
161+ 'skip_terms ' => null ,
153162 'max_file_size ' => 15 ,
154163 'filename_format ' => '{site}.wordpress.{date}.{n}.xml ' ,
155164 'include_once ' => null ,
@@ -174,6 +183,27 @@ public function __invoke( $_, $assoc_args ) {
174183 $ defaults ['with_attachments ' ]
175184 );
176185
186+ $ this ->export_args ['skip_authors ' ] = Utils \get_flag_value (
187+ $ assoc_args ,
188+ 'skip_authors ' ,
189+ $ defaults ['skip_authors ' ]
190+ );
191+
192+ $ this ->export_args ['skip_terms ' ] = Utils \get_flag_value (
193+ $ assoc_args ,
194+ 'skip_terms ' ,
195+ $ defaults ['skip_terms ' ]
196+ );
197+
198+ // Re-calculate exclusions after validation to ensure consistency.
199+ $ this ->exclude = [];
200+ if ( $ this ->export_args ['skip_authors ' ] ) {
201+ $ this ->exclude [] = 'authors ' ;
202+ }
203+ if ( $ this ->export_args ['skip_terms ' ] ) {
204+ $ this ->exclude = array_merge ( $ this ->exclude , array ( 'categories ' , 'tags ' , 'nav_menu_terms ' , 'custom_taxonomies_terms ' ) );
205+ }
206+
177207 if ( ! function_exists ( 'wp_export ' ) ) {
178208 self ::load_export_api ();
179209 }
@@ -209,6 +239,7 @@ static function ( $file_path ) {
209239 'destination_directory ' => $ this ->wxr_path ,
210240 'filename_template ' => self ::get_filename_template ( $ assoc_args ['filename_format ' ] ),
211241 'include_once ' => $ this ->include_once ,
242+ 'exclude ' => $ this ->exclude ,
212243 ],
213244 ]
214245 );
@@ -534,6 +565,42 @@ private function check_skip_comments( $skip ) {
534565 return true ;
535566 }
536567
568+ /**
569+ * @param string|null $skip
570+ *
571+ * @phpstan-ignore method.unused
572+ */
573+ private function check_skip_authors ( $ skip ) {
574+ if ( null === $ skip ) {
575+ return true ;
576+ }
577+
578+ if ( 0 !== (int ) $ skip && 1 !== (int ) $ skip ) {
579+ WP_CLI ::warning ( 'skip_authors needs to be 0 (no) or 1 (yes). ' );
580+ return false ;
581+ }
582+ $ this ->export_args ['skip_authors ' ] = $ skip ;
583+ return true ;
584+ }
585+
586+ /**
587+ * @param string|null $skip
588+ *
589+ * @phpstan-ignore method.unused
590+ */
591+ private function check_skip_terms ( $ skip ) {
592+ if ( null === $ skip ) {
593+ return true ;
594+ }
595+
596+ if ( 0 !== (int ) $ skip && 1 !== (int ) $ skip ) {
597+ WP_CLI ::warning ( 'skip_terms needs to be 0 (no) or 1 (yes). ' );
598+ return false ;
599+ }
600+ $ this ->export_args ['skip_terms ' ] = $ skip ;
601+ return true ;
602+ }
603+
537604 /**
538605 * @param string $size
539606 *
0 commit comments