X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/849f15aeed7a5e39314057bdc0064d8edd60dd7d..3194d1bb103c2d8db4f44feeced5e58ee2756658:/wp-admin/includes/export.php diff --git a/wp-admin/includes/export.php b/wp-admin/includes/export.php index 1ffc1d34..4b18c9c0 100644 --- a/wp-admin/includes/export.php +++ b/wp-admin/includes/export.php @@ -20,6 +20,9 @@ define( 'WXR_VERSION', '1.2' ); * * @since 2.1.0 * + * @global wpdb $wpdb + * @global WP_Post $post + * * @param array $args Filters defining what should be included in the export. */ function export_wp( $args = array() ) { @@ -40,8 +43,21 @@ function export_wp( $args = array() ) { do_action( 'export_wp', $args ); $sitename = sanitize_key( get_bloginfo( 'name' ) ); - if ( ! empty($sitename) ) $sitename .= '.'; - $filename = $sitename . 'wordpress.' . date( 'Y-m-d' ) . '.xml'; + if ( ! empty( $sitename ) ) { + $sitename .= '.'; + } + $date = date( 'Y-m-d' ); + $wp_filename = $sitename . 'wordpress.' . $date . '.xml'; + /** + * Filter the export filename. + * + * @since 4.4.0 + * + * @param string $wp_filename The name of the file for download. + * @param string $sitename The site name. + * @param string $date Today's date, formatted. + */ + $filename = apply_filters( 'export_wp_filename', $wp_filename, $sitename, $date ); header( 'Content-Description: File Transfer' ); header( 'Content-Disposition: attachment; filename=' . $filename ); @@ -72,7 +88,7 @@ function export_wp( $args = array() ) { } } - if ( 'post' == $args['content'] || 'page' == $args['content'] ) { + if ( 'post' == $args['content'] || 'page' == $args['content'] || 'attachment' == $args['content'] ) { if ( $args['author'] ) $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] ); @@ -95,7 +111,7 @@ function export_wp( $args = array() ) { $cat = get_term( $term['term_id'], 'category' ); $cats = array( $cat->term_id => $cat ); unset( $term, $cat ); - } else if ( 'all' == $args['content'] ) { + } elseif ( 'all' == $args['content'] ) { $categories = (array) get_categories( array( 'get' => 'all' ) ); $tags = (array) get_tags( array( 'get' => 'all' ) ); @@ -130,9 +146,9 @@ function export_wp( $args = array() ) { * @return string */ function wxr_cdata( $str ) { - if ( seems_utf8( $str ) == false ) + if ( ! seems_utf8( $str ) ) { $str = utf8_encode( $str ); - + } // $str = ent2ncr(esc_html($str)); $str = '', ']]]]>', $str ) . ']]>'; @@ -244,6 +260,8 @@ function export_wp( $args = array() ) { * * @since 3.1.0 * + * @global wpdb $wpdb WordPress database abstraction object. + * * @param array $post_ids Array of post IDs to filter the query by. Optional. */ function wxr_authors_list( array $post_ids = null ) { @@ -265,12 +283,12 @@ function export_wp( $args = array() ) { foreach ( $authors as $author ) { echo "\t"; - echo '' . $author->ID . ''; - echo '' . $author->user_login . ''; - echo '' . $author->user_email . ''; + echo '' . intval( $author->ID ) . ''; + echo '' . wxr_cdata( $author->user_login ) . ''; + echo '' . wxr_cdata( $author->user_email ) . ''; echo '' . wxr_cdata( $author->display_name ) . ''; - echo '' . wxr_cdata( $author->user_firstname ) . ''; - echo '' . wxr_cdata( $author->user_lastname ) . ''; + echo '' . wxr_cdata( $author->first_name ) . ''; + echo '' . wxr_cdata( $author->last_name ) . ''; echo "\n"; } } @@ -286,7 +304,10 @@ function export_wp( $args = array() ) { return; foreach ( $nav_menus as $menu ) { - echo "\t{$menu->term_id}nav_menu{$menu->slug}"; + echo "\t"; + echo '' . intval( $menu->term_id ) . ''; + echo 'nav_menu'; + echo '' . wxr_cdata( $menu->slug ) . ''; wxr_term_name( $menu ); echo "\n"; } @@ -310,6 +331,12 @@ function export_wp( $args = array() ) { } } + /** + * + * @param bool $return_me + * @param string $meta_key + * @return bool + */ function wxr_filter_postmeta( $return_me, $meta_key ) { if ( '_edit_lock' == $meta_key ) $return_me = true; @@ -359,13 +386,13 @@ function export_wp( $args = array() ) { - term_id ?>slug; ?>parent ? $cats[$c->parent]->slug : ''; ?> + term_id ); ?>slug ); ?>parent ? $cats[$c->parent]->slug : '' ); ?> - term_id ?>slug; ?> + term_id ); ?>slug ); ?> - term_id ?>taxonomy; ?>slug; ?>parent ? $terms[$t->parent]->slug : ''; ?> + term_id ); ?>taxonomy ); ?>slug ); ?>parent ? $terms[$t->parent]->slug : '' ); ?> @@ -375,6 +402,9 @@ function export_wp( $args = array() ) { ?> post_excerpt ) ); ?> - ID; ?> - post_date; ?> - post_date_gmt; ?> - comment_status; ?> - ping_status; ?> - post_name; ?> - post_status; ?> - post_parent; ?> - menu_order; ?> - post_type; ?> - post_password; ?> - + ID ); ?> + post_date ); ?> + post_date_gmt ); ?> + comment_status ); ?> + ping_status ); ?> + post_name ); ?> + post_status ); ?> + post_parent ); ?> + menu_order ); ?> + post_type ); ?> + post_password ); ?> + post_type == 'attachment' ) : ?> - ID ); ?> + ID ) ); ?> get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) ); @@ -454,26 +484,27 @@ function export_wp( $args = array() ) { continue; ?> - meta_key; ?> + meta_key ); ?> meta_value ); ?> get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) ); + $_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) ); + $comments = array_map( 'get_comment', $_comments ); foreach ( $comments as $c ) : ?> - comment_ID; ?> + comment_ID ); ?> comment_author ); ?> - comment_author_email; ?> + comment_author_email ); ?> comment_author_url ); ?> - comment_author_IP; ?> - comment_date; ?> - comment_date_gmt; ?> + comment_author_IP ); ?> + comment_date ); ?> + comment_date_gmt ); ?> comment_content ) ?> - comment_approved; ?> - comment_type; ?> - comment_parent; ?> - user_id; ?> + comment_approved ); ?> + comment_type ); ?> + comment_parent ); ?> + user_id ); ?> get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) ); foreach ( $c_meta as $meta ) : /** @@ -493,7 +524,7 @@ function export_wp( $args = array() ) { } ?> - meta_key; ?> + meta_key ); ?> meta_value ); ?>