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