1010class WP_Export_Query {
1111 const QUERY_CHUNK = 100 ;
1212
13- private static $ defaults = array (
13+ private static $ defaults = [
1414 'post_ids ' => null ,
1515 'post_type ' => null ,
1616 'status ' => null ,
@@ -20,21 +20,20 @@ class WP_Export_Query {
2020 'start_id ' => null ,
2121 'max_num_posts ' => null ,
2222 'category ' => null ,
23- ) ;
23+ ] ;
2424
2525 private $ post_ids ;
2626 private $ filters ;
27- private $ xml_gen ;
2827
29- private $ wheres = array () ;
30- private $ joins = array () ;
28+ private $ wheres = [] ;
29+ private $ joins = [] ;
3130
3231 private $ author ;
3332 private $ category ;
3433
3534 public $ missing_parents = false ;
3635
37- public function __construct ( $ filters = array () ) {
36+ public function __construct ( $ filters = [] ) {
3837 $ this ->filters = wp_parse_args ( $ filters , self ::$ defaults );
3938 $ this ->post_ids = $ this ->calculate_post_ids ();
4039 }
@@ -48,15 +47,15 @@ public function charset() {
4847 }
4948
5049 public function site_metadata () {
51- $ metadata = array (
50+ $ metadata = [
5251 'name ' => $ this ->bloginfo_rss ( 'name ' ),
5352 'url ' => $ this ->bloginfo_rss ( 'url ' ),
5453 'language ' => $ this ->bloginfo_rss ( 'language ' ),
5554 'description ' => $ this ->bloginfo_rss ( 'description ' ),
5655 'pubDate ' => date ( 'D, d M Y H:i:s +0000 ' ), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
5756 'site_url ' => is_multisite () ? network_home_url () : $ this ->bloginfo_rss ( 'url ' ),
5857 'blog_url ' => $ this ->bloginfo_rss ( 'url ' ),
59- ) ;
58+ ] ;
6059 return $ metadata ;
6160 }
6261
@@ -67,9 +66,9 @@ public function wp_generator_tag() {
6766
6867 public function authors () {
6968 global $ wpdb ;
70- $ authors = array () ;
71- $ author_ids = $ wpdb ->get_col ( "SELECT DISTINCT post_author FROM $ wpdb ->posts WHERE post_status != 'auto-draft' " );
72- foreach ( ( array ) $ author_ids as $ author_id ) {
69+ $ authors = [] ;
70+ $ author_ids = ( array ) $ wpdb ->get_col ( "SELECT DISTINCT post_author FROM $ wpdb ->posts WHERE post_status != 'auto-draft' " );
71+ foreach ( $ author_ids as $ author_id ) {
7372 $ authors [] = get_userdata ( $ author_id );
7473 }
7574 $ authors = array_filter ( $ authors );
@@ -78,12 +77,12 @@ public function authors() {
7877
7978 public function categories () {
8079 if ( $ this ->category ) {
81- return array ( $ this ->category ) ;
80+ return [ $ this ->category ] ;
8281 }
8382 if ( $ this ->filters ['post_type ' ] ) {
84- return array () ;
83+ return [] ;
8584 }
86- $ categories = (array ) get_categories ( array ( 'get ' => 'all ' ) );
85+ $ categories = (array ) get_categories ( [ 'get ' => 'all ' ] );
8786
8887 $ this ->check_for_orphaned_terms ( $ categories );
8988
@@ -94,9 +93,9 @@ public function categories() {
9493
9594 public function tags () {
9695 if ( $ this ->filters ['post_type ' ] ) {
97- return array () ;
96+ return [] ;
9897 }
99- $ tags = (array ) get_tags ( array ( 'get ' => 'all ' ) );
98+ $ tags = (array ) get_tags ( [ 'get ' => 'all ' ] );
10099
101100 $ this ->check_for_orphaned_terms ( $ tags );
102101
@@ -105,18 +104,18 @@ public function tags() {
105104
106105 public function custom_taxonomies_terms () {
107106 if ( $ this ->filters ['post_type ' ] ) {
108- return array () ;
107+ return [] ;
109108 }
110- $ custom_taxonomies = get_taxonomies ( array ( '_builtin ' => false ) );
111- $ custom_terms = (array ) get_terms ( $ custom_taxonomies , array ( 'get ' => 'all ' ) );
109+ $ custom_taxonomies = get_taxonomies ( [ '_builtin ' => false ] );
110+ $ custom_terms = (array ) get_terms ( $ custom_taxonomies , [ 'get ' => 'all ' ] );
112111 $ this ->check_for_orphaned_terms ( $ custom_terms );
113112 $ custom_terms = self ::topologically_sort_terms ( $ custom_terms );
114113 return $ custom_terms ;
115114 }
116115
117116 public function nav_menu_terms () {
118117 $ nav_menus = wp_get_nav_menus ();
119- foreach ( $ nav_menus as & $ term ) {
118+ foreach ( $ nav_menus as $ term ) {
120119 $ term ->description = '' ;
121120 }
122121 return $ nav_menus ;
@@ -143,7 +142,7 @@ public function exportify_post( $post ) {
143142
144143 public function posts () {
145144 $ posts_iterator = new WP_Post_IDs_Iterator ( $ this ->post_ids , self ::QUERY_CHUNK );
146- return new WP_Map_Iterator ( $ posts_iterator , array ( $ this , 'exportify_post ' ) );
145+ return new WP_Map_Iterator ( $ posts_iterator , [ $ this , 'exportify_post ' ] );
147146 }
148147
149148 private function calculate_post_ids () {
@@ -170,29 +169,28 @@ private function calculate_post_ids() {
170169 $ join = implode ( ' ' , array_filter ( $ this ->joins ) );
171170
172171 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Individual where clauses run through $wpdb->prepare().
173- $ post_ids = $ wpdb ->get_col ( "SELECT ID FROM {$ wpdb ->posts } AS p $ join $ where {$ this ->max_num_posts ()}" );
172+ $ post_ids = $ wpdb ->get_col ( "SELECT ID FROM {$ wpdb ->posts } AS p { $ join} { $ where} {$ this ->max_num_posts ()}" );
174173 if ( $ this ->filters ['post_type ' ] ) {
175174 $ post_ids = array_merge ( $ post_ids , $ this ->include_attachment_ids ( $ post_ids ) );
176175 }
177176 return $ post_ids ;
178177 }
179178
180179 private function post_type_where () {
181- global $ wpdb ;
182- $ post_types_filters = array ( 'can_export ' => true );
180+ $ post_types_filters = [ 'can_export ' => true ];
183181 if ( $ this ->filters ['post_type ' ] ) {
184182 $ post_types = $ this ->filters ['post_type ' ];
185183
186184 // Flatten single post types
187185 if ( is_array ( $ post_types ) && 1 === count ( $ post_types ) ) {
188186 $ post_types = array_shift ( $ post_types );
189187 }
190- $ post_types_filters = array_merge ( $ post_types_filters , array ( 'name ' => $ post_types ) );
188+ $ post_types_filters = array_merge ( $ post_types_filters , [ 'name ' => $ post_types ] );
191189 }
192190
193191 // Multiple post types
194192 if ( isset ( $ post_types_filters ['name ' ] ) && is_array ( $ post_types_filters ['name ' ] ) ) {
195- $ post_types = array () ;
193+ $ post_types = [] ;
196194 foreach ( $ post_types_filters ['name ' ] as $ post_type ) {
197195 if ( post_type_exists ( $ post_type ) ) {
198196 $ post_types [] = $ post_type ;
@@ -294,7 +292,7 @@ private function max_num_posts() {
294292 private function include_attachment_ids ( $ post_ids ) {
295293 global $ wpdb ;
296294 if ( ! $ post_ids ) {
297- return array () ;
295+ return [] ;
298296 }
299297 $ attachment_ids = [];
300298 // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition -- Assigment is part of the break condition.
@@ -348,8 +346,8 @@ private static function topologically_sort_terms( $terms ) {
348346 }
349347
350348 private function check_for_orphaned_terms ( $ terms ) {
351- $ term_ids = array () ;
352- $ have_parent = array () ;
349+ $ term_ids = [] ;
350+ $ have_parent = [] ;
353351
354352 foreach ( $ terms as $ term ) {
355353 $ term_ids [ $ term ->term_id ] = true ;
@@ -369,16 +367,14 @@ private function check_for_orphaned_terms( $terms ) {
369367 private static function get_terms_for_post ( $ post ) {
370368 $ taxonomies = get_object_taxonomies ( $ post ->post_type );
371369 if ( empty ( $ taxonomies ) ) {
372- return array () ;
370+ return [] ;
373371 }
374- $ terms = wp_get_object_terms ( $ post ->ID , $ taxonomies );
375- $ terms = $ terms ? $ terms : array ();
376- return $ terms ;
372+ return wp_get_object_terms ( $ post ->ID , $ taxonomies ) ?: [];
377373 }
378374
379375 private static function get_meta_for_post ( $ post ) {
380376 global $ wpdb ;
381- $ meta_for_export = array () ;
377+ $ meta_for_export = [] ;
382378 $ meta_from_db = $ wpdb ->get_results ( $ wpdb ->prepare ( "SELECT * FROM $ wpdb ->postmeta WHERE post_id = %d " , $ post ->ID ) );
383379 foreach ( $ meta_from_db as $ meta ) {
384380 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Calling native WordPress hook.
@@ -397,14 +393,12 @@ private function get_comments_for_post( $post ) {
397393 global $ wpdb ;
398394
399395 if ( isset ( $ this ->filters ['skip_comments ' ] ) ) {
400- return array () ;
396+ return [] ;
401397 }
402398
403399 $ comments = $ wpdb ->get_results ( $ wpdb ->prepare ( "SELECT * FROM $ wpdb ->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam' " , $ post ->ID ) );
404400 foreach ( $ comments as $ comment ) {
405- $ meta = $ wpdb ->get_results ( $ wpdb ->prepare ( "SELECT * FROM $ wpdb ->commentmeta WHERE comment_id = %d " , $ comment ->comment_ID ) );
406- $ meta = $ meta ? $ meta : array ();
407- $ comment ->meta = $ meta ;
401+ $ comment ->meta = $ wpdb ->get_results ( $ wpdb ->prepare ( "SELECT * FROM $ wpdb ->commentmeta WHERE comment_id = %d " , $ comment ->comment_ID ) ) ?: [];
408402 }
409403 return $ comments ;
410404 }
0 commit comments