export_wp( array $args = array() )
- Since
- 2.1.0, 5.7.0
- Source
wp-admin/includes/export.php:57
Description
Default behavior is to export all content, however, note that post content will only be exported for post types with the can_export argument enabled. Any posts with the 'auto-draft' status will be skipped.
Compatibility
- WordPress
- since 5.7.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$argsarrayoptional- Arguments for generating the WXR export file for download. Default empty array.Default:
array()$contentstringdefault: 'all'Type of content to export. If set, only the post content of this post type will be exported. Accepts 'all', 'post', 'page', 'attachment', or a defined custom post. If an invalid custom post type is supplied, every post type for whichcan_exportis enabled will be exported instead. If a valid custom post type is supplied butcan_exportis disabled, then 'posts' will be exported instead. When 'all' is supplied, only post types withcan_exportenabled will be exported.$authorstringdefault: false (all)Author to export content for. Only used when$contentis 'post', 'page', or 'attachment'. Accepts false (all) or a specific author ID.$categorystringdefault: is false (all categories)Category (slug) to export content for. Used only when$contentis 'post'. If set, only post content assigned to$categorywill be exported. Accepts false or a specific category slug.$start_datestringdefault: false (since the beginning of time)Start date to export content from. Expected date format is 'Y-m-d'. Used only when$contentis 'post', 'page' or 'attachment'.$end_datestringdefault: false (latest publish date)End date to export content to. Expected date format is 'Y-m-d'. Used only when$contentis 'post', 'page' or 'attachment'.$statusstringdefault: false (all statuses except 'auto-draft')Post status to export posts for. Used only when$contentis 'post' or 'page'. Accepts false (all statuses except 'auto-draft'), or a specific status, i.e. 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', or 'trash'.
Performance profile
How much work a call to export_wp() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 202–253
- Plugin surface
- 8 hooks
- Called by
- 0
Reaches the database via ->get_col().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 973.
Third-party callbacks on 'export_wp', 'export_wp_filename', 'rss2_head' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()called directly - optionoption read or write
get_option()called directly - querycontent query
get_term()called directly - sqldatabase query
->get_col()called directly - cacheobject cache
wp_cache_get()one call below export_wp() - serializeserialisation
maybe_unserialize()one call below export_wp()
Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 12 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost export_wp() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($sitename) && !$args | 202–206 | wp_parse_args(), do_action(), get_bloginfo(), sanitize_key(), gmdate(), apply_filters(), header(), header(), get_option(), header(), get_post_types(), array_fill(), ->prepare(), ->get_col(), add_filter(), get_bloginfo(), the_generator(), bloginfo_rss(), bloginfo_rss(), bloginfo_rss(), gmdate(), bloginfo_rss(), wxr_site_url(), bloginfo_rss(), wxr_authors_list(), do_action() |
empty($sitename) && !$args | 204–208 | wp_parse_args(), do_action(), get_bloginfo(), sanitize_key(), gmdate(), apply_filters(), header(), header(), get_option(), header(), get_post_types(), array_fill(), ->prepare(), ->get_col(), add_filter(), get_bloginfo(), the_generator(), bloginfo_rss(), bloginfo_rss(), bloginfo_rss(), gmdate(), bloginfo_rss(), wxr_site_url(), bloginfo_rss(), wxr_authors_list(), wxr_nav_menu_terms(), do_action() |
empty($sitename) && !$args | 213–217 | wp_parse_args(), do_action(), get_bloginfo(), sanitize_key(), gmdate(), apply_filters(), header(), header(), get_option(), header(), get_post_types(), array_fill(), ->prepare(), ->get_col(), add_filter(), get_bloginfo(), the_generator(), bloginfo_rss(), bloginfo_rss(), bloginfo_rss(), gmdate(), bloginfo_rss(), wxr_site_url(), bloginfo_rss(), wxr_authors_list(), do_action(), array_splice() |
empty($sitename) && !$args && isset($term) | 213–214 | wp_parse_args(), do_action(), get_bloginfo(), sanitize_key(), gmdate(), apply_filters(), header(), header(), get_option(), header(), get_post_types(), array_fill(), ->prepare(), ->get_col(), get_term(), add_filter(), get_bloginfo(), the_generator(), bloginfo_rss(), bloginfo_rss(), bloginfo_rss(), gmdate(), bloginfo_rss(), wxr_site_url(), bloginfo_rss(), wxr_authors_list(), do_action() |
empty($sitename) && !$args | 215–219 | wp_parse_args(), do_action(), get_bloginfo(), sanitize_key(), gmdate(), apply_filters(), header(), header(), get_option(), header(), get_post_types(), array_fill(), ->prepare(), ->get_col(), add_filter(), get_bloginfo(), the_generator(), bloginfo_rss(), bloginfo_rss(), bloginfo_rss(), gmdate(), bloginfo_rss(), wxr_site_url(), bloginfo_rss(), wxr_authors_list(), wxr_nav_menu_terms(), do_action(), array_splice() |
empty($sitename) && !$args && isset($term) | 215–216 | wp_parse_args(), do_action(), get_bloginfo(), sanitize_key(), gmdate(), apply_filters(), header(), header(), get_option(), header(), get_post_types(), array_fill(), ->prepare(), ->get_col(), get_term(), add_filter(), get_bloginfo(), the_generator(), bloginfo_rss(), bloginfo_rss(), bloginfo_rss(), gmdate(), bloginfo_rss(), wxr_site_url(), bloginfo_rss(), wxr_authors_list(), wxr_nav_menu_terms(), do_action() |
empty($sitename) && !$args && isset($term) | 224–225 | wp_parse_args(), do_action(), get_bloginfo(), sanitize_key(), gmdate(), apply_filters(), header(), header(), get_option(), header(), get_post_types(), array_fill(), ->prepare(), ->get_col(), get_term(), add_filter(), get_bloginfo(), the_generator(), bloginfo_rss(), bloginfo_rss(), bloginfo_rss(), gmdate(), bloginfo_rss(), wxr_site_url(), bloginfo_rss(), wxr_authors_list(), do_action(), array_splice() |
empty($sitename) && !$args && isset($term) | 226 | wp_parse_args(), do_action(), get_bloginfo(), sanitize_key(), gmdate(), apply_filters(), header(), header(), get_option(), header(), get_post_types(), array_fill(), ->prepare(), ->get_col(), get_term(), add_filter(), get_bloginfo(), the_generator(), bloginfo_rss(), bloginfo_rss(), bloginfo_rss(), gmdate(), bloginfo_rss(), wxr_site_url(), bloginfo_rss(), wxr_authors_list(), wxr_nav_menu_terms(), do_action(), array_splice() |
empty($sitename) && !$args | 236–240 | wp_parse_args(), do_action(), get_bloginfo(), sanitize_key(), gmdate(), apply_filters(), header(), header(), get_option(), header(), get_post_types(), array_fill(), ->prepare(), ->get_col(), get_categories(), get_tags(), get_taxonomies(), taxonomy(), array_shift(), array_shift(), add_filter(), get_bloginfo(), the_generator(), bloginfo_rss(), bloginfo_rss(), bloginfo_rss(), gmdate(), bloginfo_rss(), wxr_site_url(), bloginfo_rss(), wxr_authors_list(), do_action() |
empty($sitename) && !$args | 238–242 | wp_parse_args(), do_action(), get_bloginfo(), sanitize_key(), gmdate(), apply_filters(), header(), header(), get_option(), header(), get_post_types(), array_fill(), ->prepare(), ->get_col(), get_categories(), get_tags(), get_taxonomies(), taxonomy(), array_shift(), array_shift(), add_filter(), get_bloginfo(), the_generator(), bloginfo_rss(), bloginfo_rss(), bloginfo_rss(), gmdate(), bloginfo_rss(), wxr_site_url(), bloginfo_rss(), wxr_authors_list(), wxr_nav_menu_terms(), do_action() |
empty($sitename) && !$args | 247–251 | wp_parse_args(), do_action(), get_bloginfo(), sanitize_key(), gmdate(), apply_filters(), header(), header(), get_option(), header(), get_post_types(), array_fill(), ->prepare(), ->get_col(), get_categories(), get_tags(), get_taxonomies(), taxonomy(), array_shift(), array_shift(), add_filter(), get_bloginfo(), the_generator(), bloginfo_rss(), bloginfo_rss(), bloginfo_rss(), gmdate(), bloginfo_rss(), wxr_site_url(), bloginfo_rss(), wxr_authors_list(), do_action(), array_splice() |
empty($sitename) && !$args | 249–253 | wp_parse_args(), do_action(), get_bloginfo(), sanitize_key(), gmdate(), apply_filters(), header(), header(), get_option(), header(), get_post_types(), array_fill(), ->prepare(), ->get_col(), get_categories(), get_tags(), get_taxonomies(), taxonomy(), array_shift(), array_shift(), add_filter(), get_bloginfo(), the_generator(), bloginfo_rss(), bloginfo_rss(), bloginfo_rss(), gmdate(), bloginfo_rss(), wxr_site_url(), bloginfo_rss(), wxr_authors_list(), wxr_nav_menu_terms(), do_action(), array_splice() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 973 | 202–253 | 48 | |
| 8.5 | 973 | 202–253 | 48 | |
| 8.4 | 973 | 202–253 | 48 | 9 fewer instructions than PHP 8.3 |
| 8.3 | 982 | 205–256 | 48 | |
| 8.2 | 982 | 205–256 | 48 | 1 more instruction than PHP 8.1 |
| 8.1 | 981 | 205–261 | 48 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 983 | 205–261 | 48 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 8
8 hooks fire while export_wp() runs, in this order:
- do_action( export_wp )actionline 77 (+20 into the body)
Fires at the beginning of an export, before any headers are sent.
- apply_filters( the_title_export )filterline 605 (+548 into the body)
Filters the post title used for WXR exports.
- apply_filters( the_content_export )filterline 614 (+557 into the body)
Filters the post content used for WXR exports.
- apply_filters( the_excerpt_export )filterline 623 (+566 into the body)
Filters the post excerpt used for WXR exports.
- apply_filters( wxr_export_skip_postmeta )filterline 669 (+612 into the body)
Filters whether to selectively skip post meta used for WXR exports.
- apply_filters( wxr_export_skip_commentmeta )filterline 712 (+655 into the body)
Filters whether to selectively skip comment meta used for WXR exports.
Uses · 39
- wp_parse_args()Merges user defined arguments into defaults array.
- do_action()Calls the callback functions that have been added to an action hook.
- sanitize_key()Sanitizes a string key.
- get_bloginfo()Retrieves information about the current site.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_option()Retrieves an option value based on an option name.
- post_type_exists()Determines whether a post type is registered.
- get_post_type_object()Retrieves a post type object by name.
- get_post_types()Gets a list of all registered post type objects.
- term_exists()Determines whether a taxonomy term exists.
- get_term()Gets all term data from database by term ID.
- get_categories()Retrieves a list of category objects.
Show all 39
- get_tags()Retrieves all post tags.
- get_taxonomies()Retrieves a list of registered taxonomy names or objects.
- get_terms()Retrieves the terms in a given taxonomy or list of taxonomies.
- add_filter()Adds a callback function to a filter hook.
- the_generator()Displays the generator XML or Comment for RSS, ATOM, etc.
- bloginfo_rss()Displays RSS container for the bloginfo function.
- wxr_site_url()Returns the URL of the site.
- wxr_authors_list()Outputs list of authors with posts.
- wxr_cdata()Wraps given string in XML CDATA tag.
- wxr_cat_name()Outputs a cat_name XML tag from a given category object.
- wxr_category_description()Outputs a category_description XML tag from a given category object.
- wxr_term_meta()Outputs term meta XML tags for a given term object.
- wxr_tag_name()Outputs a tag_name XML tag from a given tag object.
- wxr_tag_description()Outputs a tag_description XML tag from a given tag object.
- wxr_term_name()Outputs a term_name XML tag from a given term object.
- wxr_term_description()Outputs a term_description XML tag from a given term object.
- wxr_nav_menu_terms()Outputs all navigation menu terms.
- setup_postdata()Set up global post data.
- is_sticky()Determines whether a post is sticky.
- the_permalink_rss()Displays the permalink to the post for use in feeds.
- mysql2date()Converts given MySQL date string into a different format.
- get_post_time()Retrieves the localized time of the post.
- get_the_author_meta()Retrieves the requested data of the author of the current post.
- the_guid()Displays the Post Global Unique Identifier (guid).
- wp_get_attachment_url()Retrieves the URL for an attachment.
- wxr_post_taxonomy()Outputs list of taxonomy terms, in XML tag format, associated with a post.
- sanitize_url()Sanitizes a URL for database or redirect usage.
Source code
function export_wp( $args = array() ) { global $wpdb, $post; $defaults = array( 'content' => 'all', 'author' => false, 'category' => false, 'start_date' => false, 'end_date' => false, 'status' => false, ); $args = wp_parse_args( $args, $defaults ); /** * Fires at the beginning of an export, before any headers are sent. * * @since 2.3.0 * * @param array $args An array of export arguments. */ do_action( 'export_wp', $args ); $sitename = sanitize_key( get_bloginfo( 'name' ) ); if ( ! empty( $sitename ) ) { $sitename .= '.'; } $date = gmdate( 'Y-m-d' ); $wp_filename = $sitename . 'WordPress.' . $date . '.xml'; /** * Filters 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 ); header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); if ( 'all' !== $args['content'] && post_type_exists( $args['content'] ) ) { $ptype = get_post_type_object( $args['content'] ); if ( ! $ptype->can_export ) { $args['content'] = 'post'; } $where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] ); } else { $post_types = get_post_types( array( 'can_export' => true ) ); $esses = array_fill( 0, count( $post_types ), '%s' ); // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare $where = $wpdb->prepare( "{$wpdb->posts}.post_type IN (" . implode( ',', $esses ) . ')', $post_types ); } if ( $args['status'] && ( 'post' === $args['content'] || 'page' === $args['content'] ) ) { $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_status = %s", $args['status'] ); } else { $where .= " AND {$wpdb->posts}.post_status != 'auto-draft'"; } $join = ''; if ( $args['category'] && 'post' === $args['content'] ) { $term = term_exists( $args['category'], 'category' ); if ( $term ) { $join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; $where .= $wpdb->prepare( " AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id'] ); } } if ( in_array( $args['content'], array( 'post', 'page', 'attachment' ), true ) ) { if ( $args['author'] ) { $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] ); } if ( $args['start_date'] ) { $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", gmdate( 'Y-m-d', strtotime( $args['start_date'] ) ) );Changelog
Introduced in 2.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
post_modified and post_modified_gmt fields to the export file.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-admin/includes/export.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.