94 |
94 |
95 header( 'Content-Description: File Transfer' ); |
95 header( 'Content-Description: File Transfer' ); |
96 header( 'Content-Disposition: attachment; filename=' . $filename ); |
96 header( 'Content-Disposition: attachment; filename=' . $filename ); |
97 header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); |
97 header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); |
98 |
98 |
99 if ( 'all' != $args['content'] && post_type_exists( $args['content'] ) ) { |
99 if ( 'all' !== $args['content'] && post_type_exists( $args['content'] ) ) { |
100 $ptype = get_post_type_object( $args['content'] ); |
100 $ptype = get_post_type_object( $args['content'] ); |
101 if ( ! $ptype->can_export ) { |
101 if ( ! $ptype->can_export ) { |
102 $args['content'] = 'post'; |
102 $args['content'] = 'post'; |
103 } |
103 } |
104 |
104 |
105 $where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] ); |
105 $where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] ); |
106 } else { |
106 } else { |
107 $post_types = get_post_types( array( 'can_export' => true ) ); |
107 $post_types = get_post_types( array( 'can_export' => true ) ); |
108 $esses = array_fill( 0, count( $post_types ), '%s' ); |
108 $esses = array_fill( 0, count( $post_types ), '%s' ); |
109 $where = $wpdb->prepare( "{$wpdb->posts}.post_type IN (" . implode( ',', $esses ) . ')', $post_types ); |
109 |
110 } |
110 // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare |
111 |
111 $where = $wpdb->prepare( "{$wpdb->posts}.post_type IN (" . implode( ',', $esses ) . ')', $post_types ); |
112 if ( $args['status'] && ( 'post' == $args['content'] || 'page' == $args['content'] ) ) { |
112 } |
|
113 |
|
114 if ( $args['status'] && ( 'post' === $args['content'] || 'page' === $args['content'] ) ) { |
113 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_status = %s", $args['status'] ); |
115 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_status = %s", $args['status'] ); |
114 } else { |
116 } else { |
115 $where .= " AND {$wpdb->posts}.post_status != 'auto-draft'"; |
117 $where .= " AND {$wpdb->posts}.post_status != 'auto-draft'"; |
116 } |
118 } |
117 |
119 |
118 $join = ''; |
120 $join = ''; |
119 if ( $args['category'] && 'post' == $args['content'] ) { |
121 if ( $args['category'] && 'post' === $args['content'] ) { |
120 if ( $term = term_exists( $args['category'], 'category' ) ) { |
122 $term = term_exists( $args['category'], 'category' ); |
|
123 if ( $term ) { |
121 $join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; |
124 $join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; |
122 $where .= $wpdb->prepare( " AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id'] ); |
125 $where .= $wpdb->prepare( " AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id'] ); |
123 } |
126 } |
124 } |
127 } |
125 |
128 |
126 if ( 'post' == $args['content'] || 'page' == $args['content'] || 'attachment' == $args['content'] ) { |
129 if ( in_array( $args['content'], array( 'post', 'page', 'attachment' ), true ) ) { |
127 if ( $args['author'] ) { |
130 if ( $args['author'] ) { |
128 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] ); |
131 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] ); |
129 } |
132 } |
130 |
133 |
131 if ( $args['start_date'] ) { |
134 if ( $args['start_date'] ) { |
132 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", date( 'Y-m-d', strtotime( $args['start_date'] ) ) ); |
135 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", gmdate( 'Y-m-d', strtotime( $args['start_date'] ) ) ); |
133 } |
136 } |
134 |
137 |
135 if ( $args['end_date'] ) { |
138 if ( $args['end_date'] ) { |
136 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", date( 'Y-m-d', strtotime( '+1 month', strtotime( $args['end_date'] ) ) ) ); |
139 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", gmdate( 'Y-m-d', strtotime( '+1 month', strtotime( $args['end_date'] ) ) ) ); |
137 } |
140 } |
138 } |
141 } |
139 |
142 |
140 // Grab a snapshot of post IDs, just in case it changes during the export. |
143 // Grab a snapshot of post IDs, just in case it changes during the export. |
141 $post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where" ); |
144 $post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where" ); |
142 |
145 |
143 /* |
146 /* |
144 * Get the requested terms ready, empty unless posts filtered by category |
147 * Get the requested terms ready, empty unless posts filtered by category |
145 * or all content. |
148 * or all content. |
146 */ |
149 */ |
147 $cats = $tags = $terms = array(); |
150 $cats = array(); |
|
151 $tags = array(); |
|
152 $terms = array(); |
148 if ( isset( $term ) && $term ) { |
153 if ( isset( $term ) && $term ) { |
149 $cat = get_term( $term['term_id'], 'category' ); |
154 $cat = get_term( $term['term_id'], 'category' ); |
150 $cats = array( $cat->term_id => $cat ); |
155 $cats = array( $cat->term_id => $cat ); |
151 unset( $term, $cat ); |
156 unset( $term, $cat ); |
152 } elseif ( 'all' == $args['content'] ) { |
157 } elseif ( 'all' === $args['content'] ) { |
153 $categories = (array) get_categories( array( 'get' => 'all' ) ); |
158 $categories = (array) get_categories( array( 'get' => 'all' ) ); |
154 $tags = (array) get_tags( array( 'get' => 'all' ) ); |
159 $tags = (array) get_tags( array( 'get' => 'all' ) ); |
155 |
160 |
156 $custom_taxonomies = get_taxonomies( array( '_builtin' => false ) ); |
161 $custom_taxonomies = get_taxonomies( array( '_builtin' => false ) ); |
157 $custom_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) ); |
162 $custom_terms = (array) get_terms( |
|
163 array( |
|
164 'taxonomy' => $custom_taxonomies, |
|
165 'get' => 'all', |
|
166 ) |
|
167 ); |
158 |
168 |
159 // Put categories in order with no child going before its parent. |
169 // Put categories in order with no child going before its parent. |
160 while ( $cat = array_shift( $categories ) ) { |
170 while ( $cat = array_shift( $categories ) ) { |
161 if ( $cat->parent == 0 || isset( $cats[ $cat->parent ] ) ) { |
171 if ( 0 == $cat->parent || isset( $cats[ $cat->parent ] ) ) { |
162 $cats[ $cat->term_id ] = $cat; |
172 $cats[ $cat->term_id ] = $cat; |
163 } else { |
173 } else { |
164 $categories[] = $cat; |
174 $categories[] = $cat; |
165 } |
175 } |
166 } |
176 } |
167 |
177 |
168 // Put terms in order with no child going before its parent. |
178 // Put terms in order with no child going before its parent. |
169 while ( $t = array_shift( $custom_terms ) ) { |
179 while ( $t = array_shift( $custom_terms ) ) { |
170 if ( $t->parent == 0 || isset( $terms[ $t->parent ] ) ) { |
180 if ( 0 == $t->parent || isset( $terms[ $t->parent ] ) ) { |
171 $terms[ $t->term_id ] = $t; |
181 $terms[ $t->term_id ] = $t; |
172 } else { |
182 } else { |
173 $custom_terms[] = $t; |
183 $custom_terms[] = $t; |
174 } |
184 } |
175 } |
185 } |
573 <wp:post_parent><?php echo intval( $post->post_parent ); ?></wp:post_parent> |
583 <wp:post_parent><?php echo intval( $post->post_parent ); ?></wp:post_parent> |
574 <wp:menu_order><?php echo intval( $post->menu_order ); ?></wp:menu_order> |
584 <wp:menu_order><?php echo intval( $post->menu_order ); ?></wp:menu_order> |
575 <wp:post_type><?php echo wxr_cdata( $post->post_type ); ?></wp:post_type> |
585 <wp:post_type><?php echo wxr_cdata( $post->post_type ); ?></wp:post_type> |
576 <wp:post_password><?php echo wxr_cdata( $post->post_password ); ?></wp:post_password> |
586 <wp:post_password><?php echo wxr_cdata( $post->post_password ); ?></wp:post_password> |
577 <wp:is_sticky><?php echo intval( $is_sticky ); ?></wp:is_sticky> |
587 <wp:is_sticky><?php echo intval( $is_sticky ); ?></wp:is_sticky> |
578 <?php if ( $post->post_type == 'attachment' ) : ?> |
588 <?php if ( 'attachment' === $post->post_type ) : ?> |
579 <wp:attachment_url><?php echo wxr_cdata( wp_get_attachment_url( $post->ID ) ); ?></wp:attachment_url> |
589 <wp:attachment_url><?php echo wxr_cdata( wp_get_attachment_url( $post->ID ) ); ?></wp:attachment_url> |
580 <?php endif; ?> |
590 <?php endif; ?> |
581 <?php wxr_post_taxonomy(); ?> |
591 <?php wxr_post_taxonomy(); ?> |
582 <?php |
592 <?php |
583 $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) ); |
593 $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) ); |
584 foreach ( $postmeta as $meta ) : |
594 foreach ( $postmeta as $meta ) : |
585 /** |
595 /** |
586 * Filters whether to selectively skip post meta used for WXR exports. |
596 * Filters whether to selectively skip post meta used for WXR exports. |
587 * |
597 * |
588 * Returning a truthy value to the filter will skip the current meta |
598 * Returning a truthy value from the filter will skip the current meta |
589 * object from being exported. |
599 * object from being exported. |
590 * |
600 * |
591 * @since 3.3.0 |
601 * @since 3.3.0 |
592 * |
602 * |
593 * @param bool $skip Whether to skip the current post meta. Default false. |
603 * @param bool $skip Whether to skip the current post meta. Default false. |