author | ymh <ymh.work@gmail.com> |
Tue, 15 Dec 2020 13:49:49 +0100 | |
changeset 16 | a86126ab1dd4 |
parent 9 | 177826044cd9 |
child 18 | be944660c56a |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Export Administration API |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* Version number for the export format. |
|
11 |
* |
|
12 |
* Bump this when something changes that might affect compatibility. |
|
13 |
* |
|
14 |
* @since 2.5.0 |
|
15 |
*/ |
|
16 |
define( 'WXR_VERSION', '1.2' ); |
|
17 |
||
18 |
/** |
|
5 | 19 |
* Generates the WXR export file for download. |
0 | 20 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
* Default behavior is to export all content, however, note that post content will only |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
* be exported for post types with the `can_export` argument enabled. Any posts with the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
* 'auto-draft' status will be skipped. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
* |
0 | 25 |
* @since 2.1.0 |
26 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
* @global wpdb $wpdb WordPress database abstraction object. |
16 | 28 |
* @global WP_Post $post Global post object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
* Optional. Arguments for generating the WXR export file for download. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
* @type string $content Type of content to export. If set, only the post content of this post type |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
* will be exported. Accepts 'all', 'post', 'page', 'attachment', or a defined |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
* custom post. If an invalid custom post type is supplied, every post type for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
* which `can_export` is enabled will be exported instead. If a valid custom post |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
* type is supplied but `can_export` is disabled, then 'posts' will be exported |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
* instead. When 'all' is supplied, only post types with `can_export` enabled will |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
* be exported. Default 'all'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
* @type string $author Author to export content for. Only used when `$content` is 'post', 'page', or |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
* 'attachment'. Accepts false (all) or a specific author ID. Default false (all). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
* @type string $category Category (slug) to export content for. Used only when `$content` is 'post'. If |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
* set, only post content assigned to `$category` will be exported. Accepts false |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
44 |
* or a specific category slug. Default is false (all categories). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
* @type string $start_date Start date to export content from. Expected date format is 'Y-m-d'. Used only |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
* when `$content` is 'post', 'page' or 'attachment'. Default false (since the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
* beginning of time). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
* @type string $end_date End date to export content to. Expected date format is 'Y-m-d'. Used only when |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
* `$content` is 'post', 'page' or 'attachment'. Default false (latest publish date). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
* @type string $status Post status to export posts for. Used only when `$content` is 'post' or 'page'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
* Accepts false (all statuses except 'auto-draft'), or a specific status, i.e. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
* 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', or |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
* 'trash'. Default false (all statuses except 'auto-draft'). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
* } |
0 | 55 |
*/ |
56 |
function export_wp( $args = array() ) { |
|
57 |
global $wpdb, $post; |
|
58 |
||
9 | 59 |
$defaults = array( |
60 |
'content' => 'all', |
|
61 |
'author' => false, |
|
62 |
'category' => false, |
|
63 |
'start_date' => false, |
|
64 |
'end_date' => false, |
|
65 |
'status' => false, |
|
0 | 66 |
); |
9 | 67 |
$args = wp_parse_args( $args, $defaults ); |
0 | 68 |
|
5 | 69 |
/** |
70 |
* Fires at the beginning of an export, before any headers are sent. |
|
71 |
* |
|
72 |
* @since 2.3.0 |
|
73 |
* |
|
74 |
* @param array $args An array of export arguments. |
|
75 |
*/ |
|
76 |
do_action( 'export_wp', $args ); |
|
0 | 77 |
|
78 |
$sitename = sanitize_key( get_bloginfo( 'name' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
if ( ! empty( $sitename ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
$sitename .= '.'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
} |
16 | 82 |
$date = gmdate( 'Y-m-d' ); |
9 | 83 |
$wp_filename = $sitename . 'WordPress.' . $date . '.xml'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
* Filters the export filename. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
* @param string $wp_filename The name of the file for download. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
* @param string $sitename The site name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
* @param string $date Today's date, formatted. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
$filename = apply_filters( 'export_wp_filename', $wp_filename, $sitename, $date ); |
0 | 94 |
|
95 |
header( 'Content-Description: File Transfer' ); |
|
96 |
header( 'Content-Disposition: attachment; filename=' . $filename ); |
|
97 |
header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); |
|
98 |
||
16 | 99 |
if ( 'all' !== $args['content'] && post_type_exists( $args['content'] ) ) { |
0 | 100 |
$ptype = get_post_type_object( $args['content'] ); |
9 | 101 |
if ( ! $ptype->can_export ) { |
0 | 102 |
$args['content'] = 'post'; |
9 | 103 |
} |
0 | 104 |
|
105 |
$where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] ); |
|
106 |
} else { |
|
107 |
$post_types = get_post_types( array( 'can_export' => true ) ); |
|
9 | 108 |
$esses = array_fill( 0, count( $post_types ), '%s' ); |
16 | 109 |
|
110 |
// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare |
|
111 |
$where = $wpdb->prepare( "{$wpdb->posts}.post_type IN (" . implode( ',', $esses ) . ')', $post_types ); |
|
0 | 112 |
} |
113 |
||
16 | 114 |
if ( $args['status'] && ( 'post' === $args['content'] || 'page' === $args['content'] ) ) { |
0 | 115 |
$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_status = %s", $args['status'] ); |
9 | 116 |
} else { |
0 | 117 |
$where .= " AND {$wpdb->posts}.post_status != 'auto-draft'"; |
9 | 118 |
} |
0 | 119 |
|
120 |
$join = ''; |
|
16 | 121 |
if ( $args['category'] && 'post' === $args['content'] ) { |
122 |
$term = term_exists( $args['category'], 'category' ); |
|
123 |
if ( $term ) { |
|
9 | 124 |
$join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; |
0 | 125 |
$where .= $wpdb->prepare( " AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id'] ); |
126 |
} |
|
127 |
} |
|
128 |
||
16 | 129 |
if ( in_array( $args['content'], array( 'post', 'page', 'attachment' ), true ) ) { |
9 | 130 |
if ( $args['author'] ) { |
0 | 131 |
$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] ); |
9 | 132 |
} |
0 | 133 |
|
9 | 134 |
if ( $args['start_date'] ) { |
16 | 135 |
$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", gmdate( 'Y-m-d', strtotime( $args['start_date'] ) ) ); |
9 | 136 |
} |
0 | 137 |
|
9 | 138 |
if ( $args['end_date'] ) { |
16 | 139 |
$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", gmdate( 'Y-m-d', strtotime( '+1 month', strtotime( $args['end_date'] ) ) ) ); |
9 | 140 |
} |
0 | 141 |
} |
142 |
||
5 | 143 |
// Grab a snapshot of post IDs, just in case it changes during the export. |
0 | 144 |
$post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where" ); |
145 |
||
5 | 146 |
/* |
147 |
* Get the requested terms ready, empty unless posts filtered by category |
|
148 |
* or all content. |
|
149 |
*/ |
|
16 | 150 |
$cats = array(); |
151 |
$tags = array(); |
|
152 |
$terms = array(); |
|
0 | 153 |
if ( isset( $term ) && $term ) { |
9 | 154 |
$cat = get_term( $term['term_id'], 'category' ); |
0 | 155 |
$cats = array( $cat->term_id => $cat ); |
156 |
unset( $term, $cat ); |
|
16 | 157 |
} elseif ( 'all' === $args['content'] ) { |
0 | 158 |
$categories = (array) get_categories( array( 'get' => 'all' ) ); |
9 | 159 |
$tags = (array) get_tags( array( 'get' => 'all' ) ); |
0 | 160 |
|
161 |
$custom_taxonomies = get_taxonomies( array( '_builtin' => false ) ); |
|
16 | 162 |
$custom_terms = (array) get_terms( |
163 |
array( |
|
164 |
'taxonomy' => $custom_taxonomies, |
|
165 |
'get' => 'all', |
|
166 |
) |
|
167 |
); |
|
0 | 168 |
|
5 | 169 |
// Put categories in order with no child going before its parent. |
0 | 170 |
while ( $cat = array_shift( $categories ) ) { |
16 | 171 |
if ( 0 == $cat->parent || isset( $cats[ $cat->parent ] ) ) { |
9 | 172 |
$cats[ $cat->term_id ] = $cat; |
173 |
} else { |
|
0 | 174 |
$categories[] = $cat; |
9 | 175 |
} |
0 | 176 |
} |
177 |
||
5 | 178 |
// Put terms in order with no child going before its parent. |
0 | 179 |
while ( $t = array_shift( $custom_terms ) ) { |
16 | 180 |
if ( 0 == $t->parent || isset( $terms[ $t->parent ] ) ) { |
9 | 181 |
$terms[ $t->term_id ] = $t; |
182 |
} else { |
|
0 | 183 |
$custom_terms[] = $t; |
9 | 184 |
} |
0 | 185 |
} |
186 |
||
187 |
unset( $categories, $custom_taxonomies, $custom_terms ); |
|
188 |
} |
|
189 |
||
190 |
/** |
|
191 |
* Wrap given string in XML CDATA tag. |
|
192 |
* |
|
193 |
* @since 2.1.0 |
|
194 |
* |
|
195 |
* @param string $str String to wrap in XML CDATA tag. |
|
196 |
* @return string |
|
197 |
*/ |
|
198 |
function wxr_cdata( $str ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
if ( ! seems_utf8( $str ) ) { |
0 | 200 |
$str = utf8_encode( $str ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
201 |
} |
0 | 202 |
// $str = ent2ncr(esc_html($str)); |
203 |
$str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>'; |
|
204 |
||
205 |
return $str; |
|
206 |
} |
|
207 |
||
208 |
/** |
|
209 |
* Return the URL of the site |
|
210 |
* |
|
211 |
* @since 2.5.0 |
|
212 |
* |
|
213 |
* @return string Site URL. |
|
214 |
*/ |
|
215 |
function wxr_site_url() { |
|
9 | 216 |
if ( is_multisite() ) { |
217 |
// Multisite: the base URL. |
|
0 | 218 |
return network_home_url(); |
9 | 219 |
} else { |
220 |
// WordPress (single site): the blog URL. |
|
0 | 221 |
return get_bloginfo_rss( 'url' ); |
9 | 222 |
} |
0 | 223 |
} |
224 |
||
225 |
/** |
|
226 |
* Output a cat_name XML tag from a given category object |
|
227 |
* |
|
228 |
* @since 2.1.0 |
|
229 |
* |
|
230 |
* @param object $category Category Object |
|
231 |
*/ |
|
232 |
function wxr_cat_name( $category ) { |
|
9 | 233 |
if ( empty( $category->name ) ) { |
0 | 234 |
return; |
9 | 235 |
} |
0 | 236 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
echo '<wp:cat_name>' . wxr_cdata( $category->name ) . "</wp:cat_name>\n"; |
0 | 238 |
} |
239 |
||
240 |
/** |
|
241 |
* Output a category_description XML tag from a given category object |
|
242 |
* |
|
243 |
* @since 2.1.0 |
|
244 |
* |
|
245 |
* @param object $category Category Object |
|
246 |
*/ |
|
247 |
function wxr_category_description( $category ) { |
|
9 | 248 |
if ( empty( $category->description ) ) { |
0 | 249 |
return; |
9 | 250 |
} |
0 | 251 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
252 |
echo '<wp:category_description>' . wxr_cdata( $category->description ) . "</wp:category_description>\n"; |
0 | 253 |
} |
254 |
||
255 |
/** |
|
256 |
* Output a tag_name XML tag from a given tag object |
|
257 |
* |
|
258 |
* @since 2.3.0 |
|
259 |
* |
|
260 |
* @param object $tag Tag Object |
|
261 |
*/ |
|
262 |
function wxr_tag_name( $tag ) { |
|
9 | 263 |
if ( empty( $tag->name ) ) { |
0 | 264 |
return; |
9 | 265 |
} |
0 | 266 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
echo '<wp:tag_name>' . wxr_cdata( $tag->name ) . "</wp:tag_name>\n"; |
0 | 268 |
} |
269 |
||
270 |
/** |
|
271 |
* Output a tag_description XML tag from a given tag object |
|
272 |
* |
|
273 |
* @since 2.3.0 |
|
274 |
* |
|
275 |
* @param object $tag Tag Object |
|
276 |
*/ |
|
277 |
function wxr_tag_description( $tag ) { |
|
9 | 278 |
if ( empty( $tag->description ) ) { |
0 | 279 |
return; |
9 | 280 |
} |
0 | 281 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
echo '<wp:tag_description>' . wxr_cdata( $tag->description ) . "</wp:tag_description>\n"; |
0 | 283 |
} |
284 |
||
285 |
/** |
|
286 |
* Output a term_name XML tag from a given term object |
|
287 |
* |
|
288 |
* @since 2.9.0 |
|
289 |
* |
|
290 |
* @param object $term Term Object |
|
291 |
*/ |
|
292 |
function wxr_term_name( $term ) { |
|
9 | 293 |
if ( empty( $term->name ) ) { |
0 | 294 |
return; |
9 | 295 |
} |
0 | 296 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
297 |
echo '<wp:term_name>' . wxr_cdata( $term->name ) . "</wp:term_name>\n"; |
0 | 298 |
} |
299 |
||
300 |
/** |
|
301 |
* Output a term_description XML tag from a given term object |
|
302 |
* |
|
303 |
* @since 2.9.0 |
|
304 |
* |
|
305 |
* @param object $term Term Object |
|
306 |
*/ |
|
307 |
function wxr_term_description( $term ) { |
|
9 | 308 |
if ( empty( $term->description ) ) { |
0 | 309 |
return; |
9 | 310 |
} |
0 | 311 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
312 |
echo "\t\t<wp:term_description>" . wxr_cdata( $term->description ) . "</wp:term_description>\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
314 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
315 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
* Output term meta XML tags for a given term object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
317 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
318 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
319 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
320 |
* @param WP_Term $term Term object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
function wxr_term_meta( $term ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
323 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
324 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
$termmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->termmeta WHERE term_id = %d", $term->term_id ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
326 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
327 |
foreach ( $termmeta as $meta ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
328 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
329 |
* Filters whether to selectively skip term meta used for WXR exports. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
330 |
* |
16 | 331 |
* Returning a truthy value from the filter will skip the current meta |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
332 |
* object from being exported. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
333 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
334 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
* @param bool $skip Whether to skip the current piece of term meta. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
337 |
* @param string $meta_key Current meta key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
* @param object $meta Current meta object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
340 |
if ( ! apply_filters( 'wxr_export_skip_termmeta', false, $meta->meta_key, $meta ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
printf( "\t\t<wp:termmeta>\n\t\t\t<wp:meta_key>%s</wp:meta_key>\n\t\t\t<wp:meta_value>%s</wp:meta_value>\n\t\t</wp:termmeta>\n", wxr_cdata( $meta->meta_key ), wxr_cdata( $meta->meta_value ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
342 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
343 |
} |
0 | 344 |
} |
345 |
||
346 |
/** |
|
347 |
* Output list of authors with posts |
|
348 |
* |
|
349 |
* @since 3.1.0 |
|
5 | 350 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
351 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
352 |
* |
9 | 353 |
* @param int[] $post_ids Optional. Array of post IDs to filter the query by. |
0 | 354 |
*/ |
5 | 355 |
function wxr_authors_list( array $post_ids = null ) { |
0 | 356 |
global $wpdb; |
357 |
||
9 | 358 |
if ( ! empty( $post_ids ) ) { |
5 | 359 |
$post_ids = array_map( 'absint', $post_ids ); |
9 | 360 |
$and = 'AND ID IN ( ' . implode( ', ', $post_ids ) . ')'; |
5 | 361 |
} else { |
362 |
$and = ''; |
|
363 |
} |
|
364 |
||
0 | 365 |
$authors = array(); |
5 | 366 |
$results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft' $and" ); |
9 | 367 |
foreach ( (array) $results as $result ) { |
0 | 368 |
$authors[] = get_userdata( $result->post_author ); |
9 | 369 |
} |
0 | 370 |
|
371 |
$authors = array_filter( $authors ); |
|
372 |
||
373 |
foreach ( $authors as $author ) { |
|
374 |
echo "\t<wp:author>"; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
echo '<wp:author_id>' . intval( $author->ID ) . '</wp:author_id>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
echo '<wp:author_login>' . wxr_cdata( $author->user_login ) . '</wp:author_login>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
377 |
echo '<wp:author_email>' . wxr_cdata( $author->user_email ) . '</wp:author_email>'; |
0 | 378 |
echo '<wp:author_display_name>' . wxr_cdata( $author->display_name ) . '</wp:author_display_name>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
379 |
echo '<wp:author_first_name>' . wxr_cdata( $author->first_name ) . '</wp:author_first_name>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
echo '<wp:author_last_name>' . wxr_cdata( $author->last_name ) . '</wp:author_last_name>'; |
0 | 381 |
echo "</wp:author>\n"; |
382 |
} |
|
383 |
} |
|
384 |
||
385 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
* Output all navigation menu terms |
0 | 387 |
* |
388 |
* @since 3.1.0 |
|
389 |
*/ |
|
390 |
function wxr_nav_menu_terms() { |
|
391 |
$nav_menus = wp_get_nav_menus(); |
|
9 | 392 |
if ( empty( $nav_menus ) || ! is_array( $nav_menus ) ) { |
0 | 393 |
return; |
9 | 394 |
} |
0 | 395 |
|
396 |
foreach ( $nav_menus as $menu ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
397 |
echo "\t<wp:term>"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
398 |
echo '<wp:term_id>' . intval( $menu->term_id ) . '</wp:term_id>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
399 |
echo '<wp:term_taxonomy>nav_menu</wp:term_taxonomy>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
400 |
echo '<wp:term_slug>' . wxr_cdata( $menu->slug ) . '</wp:term_slug>'; |
0 | 401 |
wxr_term_name( $menu ); |
402 |
echo "</wp:term>\n"; |
|
403 |
} |
|
404 |
} |
|
405 |
||
406 |
/** |
|
407 |
* Output list of taxonomy terms, in XML tag format, associated with a post |
|
408 |
* |
|
409 |
* @since 2.3.0 |
|
410 |
*/ |
|
411 |
function wxr_post_taxonomy() { |
|
412 |
$post = get_post(); |
|
413 |
||
414 |
$taxonomies = get_object_taxonomies( $post->post_type ); |
|
9 | 415 |
if ( empty( $taxonomies ) ) { |
0 | 416 |
return; |
9 | 417 |
} |
0 | 418 |
$terms = wp_get_object_terms( $post->ID, $taxonomies ); |
419 |
||
420 |
foreach ( (array) $terms as $term ) { |
|
421 |
echo "\t\t<category domain=\"{$term->taxonomy}\" nicename=\"{$term->slug}\">" . wxr_cdata( $term->name ) . "</category>\n"; |
|
422 |
} |
|
423 |
} |
|
424 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
* @param bool $return_me |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
* @param string $meta_key |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
* @return bool |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
*/ |
0 | 430 |
function wxr_filter_postmeta( $return_me, $meta_key ) { |
16 | 431 |
if ( '_edit_lock' === $meta_key ) { |
0 | 432 |
$return_me = true; |
9 | 433 |
} |
0 | 434 |
return $return_me; |
435 |
} |
|
436 |
add_filter( 'wxr_export_skip_postmeta', 'wxr_filter_postmeta', 10, 2 ); |
|
437 |
||
9 | 438 |
echo '<?xml version="1.0" encoding="' . get_bloginfo( 'charset' ) . "\" ?>\n"; |
0 | 439 |
|
440 |
?> |
|
441 |
<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. --> |
|
442 |
<!-- It contains information about your site's posts, pages, comments, categories, and other content. --> |
|
443 |
<!-- You may use this file to transfer that content from one site to another. --> |
|
444 |
<!-- This file is not intended to serve as a complete backup of your site. --> |
|
445 |
||
446 |
<!-- To import this information into a WordPress site follow these steps: --> |
|
447 |
<!-- 1. Log in to that site as an administrator. --> |
|
448 |
<!-- 2. Go to Tools: Import in the WordPress admin panel. --> |
|
449 |
<!-- 3. Install the "WordPress" importer from the list. --> |
|
450 |
<!-- 4. Activate & Run Importer. --> |
|
451 |
<!-- 5. Upload this file using the form provided on that page. --> |
|
452 |
<!-- 6. You will first be asked to map the authors in this export file to users --> |
|
453 |
<!-- on the site. For each author, you may choose to map to an --> |
|
454 |
<!-- existing user on the site or to create a new user. --> |
|
455 |
<!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. --> |
|
456 |
<!-- contained in this file into your site. --> |
|
457 |
||
9 | 458 |
<?php the_generator( 'export' ); ?> |
0 | 459 |
<rss version="2.0" |
460 |
xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/" |
|
461 |
xmlns:content="http://purl.org/rss/1.0/modules/content/" |
|
462 |
xmlns:wfw="http://wellformedweb.org/CommentAPI/" |
|
463 |
xmlns:dc="http://purl.org/dc/elements/1.1/" |
|
464 |
xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/" |
|
465 |
> |
|
466 |
||
467 |
<channel> |
|
468 |
<title><?php bloginfo_rss( 'name' ); ?></title> |
|
469 |
<link><?php bloginfo_rss( 'url' ); ?></link> |
|
470 |
<description><?php bloginfo_rss( 'description' ); ?></description> |
|
16 | 471 |
<pubDate><?php echo gmdate( 'D, d M Y H:i:s +0000' ); ?></pubDate> |
0 | 472 |
<language><?php bloginfo_rss( 'language' ); ?></language> |
473 |
<wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version> |
|
474 |
<wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url> |
|
475 |
<wp:base_blog_url><?php bloginfo_rss( 'url' ); ?></wp:base_blog_url> |
|
476 |
||
9 | 477 |
<?php wxr_authors_list( $post_ids ); ?> |
0 | 478 |
|
9 | 479 |
<?php foreach ( $cats as $c ) : ?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
<wp:category> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
481 |
<wp:term_id><?php echo intval( $c->term_id ); ?></wp:term_id> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
482 |
<wp:category_nicename><?php echo wxr_cdata( $c->slug ); ?></wp:category_nicename> |
9 | 483 |
<wp:category_parent><?php echo wxr_cdata( $c->parent ? $cats[ $c->parent ]->slug : '' ); ?></wp:category_parent> |
484 |
<?php |
|
485 |
wxr_cat_name( $c ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
486 |
wxr_category_description( $c ); |
9 | 487 |
wxr_term_meta( $c ); |
488 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
489 |
</wp:category> |
9 | 490 |
<?php endforeach; ?> |
491 |
<?php foreach ( $tags as $t ) : ?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
492 |
<wp:tag> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
493 |
<wp:term_id><?php echo intval( $t->term_id ); ?></wp:term_id> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
494 |
<wp:tag_slug><?php echo wxr_cdata( $t->slug ); ?></wp:tag_slug> |
9 | 495 |
<?php |
496 |
wxr_tag_name( $t ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
wxr_tag_description( $t ); |
9 | 498 |
wxr_term_meta( $t ); |
499 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
</wp:tag> |
9 | 501 |
<?php endforeach; ?> |
502 |
<?php foreach ( $terms as $t ) : ?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
503 |
<wp:term> |
16 | 504 |
<wp:term_id><?php echo intval( $t->term_id ); ?></wp:term_id> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
505 |
<wp:term_taxonomy><?php echo wxr_cdata( $t->taxonomy ); ?></wp:term_taxonomy> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
506 |
<wp:term_slug><?php echo wxr_cdata( $t->slug ); ?></wp:term_slug> |
9 | 507 |
<wp:term_parent><?php echo wxr_cdata( $t->parent ? $terms[ $t->parent ]->slug : '' ); ?></wp:term_parent> |
508 |
<?php |
|
509 |
wxr_term_name( $t ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
510 |
wxr_term_description( $t ); |
9 | 511 |
wxr_term_meta( $t ); |
512 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
513 |
</wp:term> |
9 | 514 |
<?php endforeach; ?> |
515 |
<?php |
|
16 | 516 |
if ( 'all' === $args['content'] ) { |
9 | 517 |
wxr_nav_menu_terms();} |
518 |
?> |
|
0 | 519 |
|
5 | 520 |
<?php |
521 |
/** This action is documented in wp-includes/feed-rss2.php */ |
|
522 |
do_action( 'rss2_head' ); |
|
523 |
?> |
|
0 | 524 |
|
9 | 525 |
<?php |
526 |
if ( $post_ids ) { |
|
527 |
/** |
|
16 | 528 |
* @global WP_Query $wp_query WordPress Query object. |
9 | 529 |
*/ |
530 |
global $wp_query; |
|
531 |
||
532 |
// Fake being in the loop. |
|
533 |
$wp_query->in_the_loop = true; |
|
0 | 534 |
|
9 | 535 |
// Fetch 20 posts at a time rather than loading the entire table into memory. |
536 |
while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) { |
|
537 |
$where = 'WHERE ID IN (' . join( ',', $next_posts ) . ')'; |
|
538 |
$posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" ); |
|
539 |
||
540 |
// Begin Loop. |
|
541 |
foreach ( $posts as $post ) { |
|
542 |
setup_postdata( $post ); |
|
543 |
||
544 |
/** This filter is documented in wp-includes/feed.php */ |
|
545 |
$title = apply_filters( 'the_title_rss', $post->post_title ); |
|
5 | 546 |
|
9 | 547 |
/** |
548 |
* Filters the post content used for WXR exports. |
|
549 |
* |
|
550 |
* @since 2.5.0 |
|
551 |
* |
|
552 |
* @param string $post_content Content of the current post. |
|
553 |
*/ |
|
554 |
$content = wxr_cdata( apply_filters( 'the_content_export', $post->post_content ) ); |
|
0 | 555 |
|
9 | 556 |
/** |
557 |
* Filters the post excerpt used for WXR exports. |
|
558 |
* |
|
559 |
* @since 2.6.0 |
|
560 |
* |
|
561 |
* @param string $post_excerpt Excerpt for the current post. |
|
562 |
*/ |
|
563 |
$excerpt = wxr_cdata( apply_filters( 'the_excerpt_export', $post->post_excerpt ) ); |
|
564 |
||
565 |
$is_sticky = is_sticky( $post->ID ) ? 1 : 0; |
|
566 |
?> |
|
0 | 567 |
<item> |
9 | 568 |
<title><?php echo $title; ?></title> |
569 |
<link><?php the_permalink_rss(); ?></link> |
|
0 | 570 |
<pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate> |
571 |
<dc:creator><?php echo wxr_cdata( get_the_author_meta( 'login' ) ); ?></dc:creator> |
|
572 |
<guid isPermaLink="false"><?php the_guid(); ?></guid> |
|
573 |
<description></description> |
|
9 | 574 |
<content:encoded><?php echo $content; ?></content:encoded> |
575 |
<excerpt:encoded><?php echo $excerpt; ?></excerpt:encoded> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
576 |
<wp:post_id><?php echo intval( $post->ID ); ?></wp:post_id> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
577 |
<wp:post_date><?php echo wxr_cdata( $post->post_date ); ?></wp:post_date> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
578 |
<wp:post_date_gmt><?php echo wxr_cdata( $post->post_date_gmt ); ?></wp:post_date_gmt> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
579 |
<wp:comment_status><?php echo wxr_cdata( $post->comment_status ); ?></wp:comment_status> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
580 |
<wp:ping_status><?php echo wxr_cdata( $post->ping_status ); ?></wp:ping_status> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
581 |
<wp:post_name><?php echo wxr_cdata( $post->post_name ); ?></wp:post_name> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
582 |
<wp:status><?php echo wxr_cdata( $post->post_status ); ?></wp:status> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
583 |
<wp:post_parent><?php echo intval( $post->post_parent ); ?></wp:post_parent> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
584 |
<wp:menu_order><?php echo intval( $post->menu_order ); ?></wp:menu_order> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
585 |
<wp:post_type><?php echo wxr_cdata( $post->post_type ); ?></wp:post_type> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
586 |
<wp:post_password><?php echo wxr_cdata( $post->post_password ); ?></wp:post_password> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
587 |
<wp:is_sticky><?php echo intval( $is_sticky ); ?></wp:is_sticky> |
16 | 588 |
<?php if ( 'attachment' === $post->post_type ) : ?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
589 |
<wp:attachment_url><?php echo wxr_cdata( wp_get_attachment_url( $post->ID ) ); ?></wp:attachment_url> |
9 | 590 |
<?php endif; ?> |
591 |
<?php wxr_post_taxonomy(); ?> |
|
592 |
<?php |
|
593 |
$postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) ); |
|
594 |
foreach ( $postmeta as $meta ) : |
|
595 |
/** |
|
596 |
* Filters whether to selectively skip post meta used for WXR exports. |
|
597 |
* |
|
16 | 598 |
* Returning a truthy value from the filter will skip the current meta |
9 | 599 |
* object from being exported. |
600 |
* |
|
601 |
* @since 3.3.0 |
|
602 |
* |
|
603 |
* @param bool $skip Whether to skip the current post meta. Default false. |
|
604 |
* @param string $meta_key Current meta key. |
|
605 |
* @param object $meta Current meta object. |
|
606 |
*/ |
|
607 |
if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) ) { |
|
608 |
continue; |
|
609 |
} |
|
610 |
?> |
|
0 | 611 |
<wp:postmeta> |
9 | 612 |
<wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key> |
613 |
<wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value> |
|
0 | 614 |
</wp:postmeta> |
9 | 615 |
<?php |
616 |
endforeach; |
|
5 | 617 |
|
9 | 618 |
$_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) ); |
619 |
$comments = array_map( 'get_comment', $_comments ); |
|
620 |
foreach ( $comments as $c ) : |
|
621 |
?> |
|
0 | 622 |
<wp:comment> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
<wp:comment_id><?php echo intval( $c->comment_ID ); ?></wp:comment_id> |
0 | 624 |
<wp:comment_author><?php echo wxr_cdata( $c->comment_author ); ?></wp:comment_author> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
<wp:comment_author_email><?php echo wxr_cdata( $c->comment_author_email ); ?></wp:comment_author_email> |
0 | 626 |
<wp:comment_author_url><?php echo esc_url_raw( $c->comment_author_url ); ?></wp:comment_author_url> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
<wp:comment_author_IP><?php echo wxr_cdata( $c->comment_author_IP ); ?></wp:comment_author_IP> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
<wp:comment_date><?php echo wxr_cdata( $c->comment_date ); ?></wp:comment_date> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
629 |
<wp:comment_date_gmt><?php echo wxr_cdata( $c->comment_date_gmt ); ?></wp:comment_date_gmt> |
9 | 630 |
<wp:comment_content><?php echo wxr_cdata( $c->comment_content ); ?></wp:comment_content> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
631 |
<wp:comment_approved><?php echo wxr_cdata( $c->comment_approved ); ?></wp:comment_approved> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
632 |
<wp:comment_type><?php echo wxr_cdata( $c->comment_type ); ?></wp:comment_type> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
633 |
<wp:comment_parent><?php echo intval( $c->comment_parent ); ?></wp:comment_parent> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
634 |
<wp:comment_user_id><?php echo intval( $c->user_id ); ?></wp:comment_user_id> |
9 | 635 |
<?php |
636 |
$c_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) ); |
|
637 |
foreach ( $c_meta as $meta ) : |
|
638 |
/** |
|
639 |
* Filters whether to selectively skip comment meta used for WXR exports. |
|
640 |
* |
|
16 | 641 |
* Returning a truthy value from the filter will skip the current meta |
9 | 642 |
* object from being exported. |
643 |
* |
|
644 |
* @since 4.0.0 |
|
645 |
* |
|
646 |
* @param bool $skip Whether to skip the current comment meta. Default false. |
|
647 |
* @param string $meta_key Current meta key. |
|
648 |
* @param object $meta Current meta object. |
|
649 |
*/ |
|
650 |
if ( apply_filters( 'wxr_export_skip_commentmeta', false, $meta->meta_key, $meta ) ) { |
|
651 |
continue; |
|
652 |
} |
|
653 |
?> |
|
654 |
<wp:commentmeta> |
|
655 |
<wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key> |
|
656 |
<wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value> |
|
0 | 657 |
</wp:commentmeta> |
9 | 658 |
<?php endforeach; ?> |
0 | 659 |
</wp:comment> |
9 | 660 |
<?php endforeach; ?> |
661 |
</item> |
|
662 |
<?php |
|
663 |
} |
|
664 |
} |
|
0 | 665 |
} |
9 | 666 |
?> |
0 | 667 |
</channel> |
668 |
</rss> |
|
9 | 669 |
<?php |
0 | 670 |
} |