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