PluginProbe
Advanced Custom Fields (ACF®) / 3.3.1
Advanced Custom Fields (ACF®) v3.3.1
6.8.9 6.8.8 6.8.7 6.8.6 6.8.5 6.8.4 6.8.3 6.8.2 6.8.1 5.8.5 5.8.6 5.8.7 5.8.8 5.8.9 5.9.0 5.9.1 5.9.2 5.9.3 5.9.4 5.9.5 5.9.6 5.9.7 5.9.8 5.9.9 6.0.0 All 230 releases
advanced-custom-fields / core / actions / export.php
export.php
221 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*--------------------------------------------------------------------------------------
3 *
4 * ACF Export
5 *
6 * @author Elliot Condon
7 * @since 3.0.2
8 *
9 *-------------------------------------------------------------------------------------*/
10
11 // includes
12 require_once('../../../../../wp-load.php');
13 require_once('../../../../../wp-admin/admin.php');
14
15
16 // check for posts
17 if(!isset($_POST['acf_posts']))
18 {
19 wp_die(__("No ACF groups selected",'acf'));
20 }
21
22
23 /**
24 * Version number for the export format.
25 *
26 * Bump this when something changes that might affect compatibility.
27 *
28 * @since 2.5.0
29 */
30 define( 'WXR_VERSION', '1.1' );
31
32
33 /**
34 * Wrap given string in XML CDATA tag.
35 *
36 * @since 2.1.0
37 *
38 * @param string $str String to wrap in XML CDATA tag.
39 */
40 function wxr_cdata( $str ) {
41 if ( seems_utf8( $str ) == false )
42 $str = utf8_encode( $str );
43
44 // $str = ent2ncr(esc_html($str));
45 $str = "<![CDATA[$str" . ( ( substr( $str, -1 ) == ']' ) ? ' ' : '' ) . ']]>';
46
47 return $str;
48 }
49
50 /**
51 * Return the URL of the site
52 *
53 * @since 2.5.0
54 *
55 * @return string Site URL.
56 */
57 function wxr_site_url() {
58 // ms: the base url
59 if ( is_multisite() )
60 return network_home_url();
61 // wp: the blog url
62 else
63 return get_bloginfo_rss( 'url' );
64 }
65
66 /**
67 * Output a tag_description XML tag from a given tag object
68 *
69 * @since 2.3.0
70 *
71 * @param object $tag Tag Object
72 */
73 function wxr_tag_description( $tag ) {
74 if ( empty( $tag->description ) )
75 return;
76
77 echo '<wp:tag_description>' . wxr_cdata( $tag->description ) . '</wp:tag_description>';
78 }
79
80 /**
81 * Output a term_name XML tag from a given term object
82 *
83 * @since 2.9.0
84 *
85 * @param object $term Term Object
86 */
87 function wxr_term_name( $term ) {
88 if ( empty( $term->name ) )
89 return;
90
91 echo '<wp:term_name>' . wxr_cdata( $term->name ) . '</wp:term_name>';
92 }
93
94 /**
95 * Output a term_description XML tag from a given term object
96 *
97 * @since 2.9.0
98 *
99 * @param object $term Term Object
100 */
101 function wxr_term_description( $term ) {
102 if ( empty( $term->description ) )
103 return;
104
105 echo '<wp:term_description>' . wxr_cdata( $term->description ) . '</wp:term_description>';
106 }
107
108 /**
109 * Output list of authors with posts
110 *
111 * @since 3.1.0
112 */
113 function wxr_authors_list() {
114 global $wpdb;
115
116 $authors = array();
117 $results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts" );
118 foreach ( (array) $results as $result )
119 $authors[] = get_userdata( $result->post_author );
120
121 $authors = array_filter( $authors );
122
123 foreach( $authors as $author ) {
124 echo "\t<wp:author>";
125 echo '<wp:author_id>' . $author->ID . '</wp:author_id>';
126 echo '<wp:author_login>' . $author->user_login . '</wp:author_login>';
127 echo '<wp:author_email>' . $author->user_email . '</wp:author_email>';
128 echo '<wp:author_display_name>' . wxr_cdata( $author->display_name ) . '</wp:author_display_name>';
129 echo '<wp:author_first_name>' . wxr_cdata( $author->user_firstname ) . '</wp:author_first_name>';
130 echo '<wp:author_last_name>' . wxr_cdata( $author->user_lastname ) . '</wp:author_last_name>';
131 echo "</wp:author>\n";
132 }
133 }
134
135 header( 'Content-Description: File Transfer' );
136 header( 'Content-Disposition: attachment; filename=advanced-custom-field-export.xml' );
137 header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
138
139
140 echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . "\" ?>\n";
141
142 ?>
143 <!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. -->
144 <!-- It contains information about your site's posts, pages, comments, categories, and other content. -->
145 <!-- You may use this file to transfer that content from one site to another. -->
146 <!-- This file is not intended to serve as a complete backup of your site. -->
147
148 <!-- To import this information into a WordPress site follow these steps: -->
149 <!-- 1. Log in to that site as an administrator. -->
150 <!-- 2. Go to Tools: Import in the WordPress admin panel. -->
151 <!-- 3. Install the "WordPress" importer from the list. -->
152 <!-- 4. Activate & Run Importer. -->
153 <!-- 5. Upload this file using the form provided on that page. -->
154 <!-- 6. You will first be asked to map the authors in this export file to users -->
155 <!-- on the site. For each author, you may choose to map to an -->
156 <!-- existing user on the site or to create a new user. -->
157 <!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. -->
158 <!-- contained in this file into your site. -->
159
160 <?php the_generator( 'export' ); ?>
161 <rss version="2.0"
162 xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/"
163 xmlns:content="http://purl.org/rss/1.0/modules/content/"
164 xmlns:wfw="http://wellformedweb.org/CommentAPI/"
165 xmlns:dc="http://purl.org/dc/elements/1.1/"
166 xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/"
167 >
168
169 <channel>
170 <title><?php bloginfo_rss( 'name' ); ?></title>
171 <link><?php bloginfo_rss( 'url' ); ?></link>
172 <description><?php bloginfo_rss( 'description' ); ?></description>
173 <pubDate><?php echo date( 'D, d M Y H:i:s +0000' ); ?></pubDate>
174 <language><?php echo get_option( 'rss_language' ); ?></language>
175 <wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version>
176 <wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url>
177 <wp:base_blog_url><?php bloginfo_rss( 'url' ); ?></wp:base_blog_url>
178 <?php wxr_authors_list(); ?>
179 <?php if ( $_POST['acf_posts'] ) {
180
181 global $wp_query;
182 $wp_query->in_the_loop = true; // Fake being in the loop.
183
184 $where = 'WHERE ID IN (' . join( ',', $_POST['acf_posts'] ) . ')';
185 $posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" );
186
187 // Begin Loop
188 foreach ( $posts as $post ) {
189 setup_postdata( $post );
190 ?>
191 <item>
192 <title><?php echo apply_filters( 'the_title_rss', $post->post_title ); ?></title>
193 <link><?php the_permalink_rss() ?></link>
194 <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate>
195 <dc:creator><?php echo get_the_author_meta( 'login' ); ?></dc:creator>
196 <guid isPermaLink="false"><?php esc_url( the_guid() ); ?></guid>
197 <wp:post_id><?php echo $post->ID; ?></wp:post_id>
198 <wp:post_date><?php echo $post->post_date; ?></wp:post_date>
199 <wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt>
200 <wp:comment_status><?php echo $post->comment_status; ?></wp:comment_status>
201 <wp:ping_status><?php echo $post->ping_status; ?></wp:ping_status>
202 <wp:post_name><?php echo $post->post_name; ?></wp:post_name>
203 <wp:status><?php echo $post->post_status; ?></wp:status>
204 <wp:post_parent><?php echo $post->post_parent; ?></wp:post_parent>
205 <wp:menu_order><?php echo $post->menu_order; ?></wp:menu_order>
206 <wp:post_type><?php echo $post->post_type; ?></wp:post_type>
207 <wp:post_password><?php echo $post->post_password; ?></wp:post_password>
208 <?php $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) );
209 foreach( $postmeta as $meta ) : if ( $meta->meta_key != '_edit_lock' ) : ?>
210 <wp:postmeta>
211 <wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key>
212 <wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>
213 </wp:postmeta>
214 <?php endif; endforeach; ?>
215 </item>
216 <?php
217 }
218 }
219 ?>
220 </channel>
221 </rss>