wp_xmlrpc_server::_prepare_page( WP_Post $page ): array
- Source
wp-includes/class-wp-xmlrpc-server.php:1114
Compatibility
- WordPress
- core
- 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
$pageWP_Post- The unprepared page data.
Return value
array- The prepared page data.
Performance profile
How much work a call to wp_xmlrpc_server::_prepare_page() 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
- 118–137
- Plugin surface
- 1 hook
- Called by
- 2
Reaches the database via get_post().
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 145.
Third-party callbacks on 'xmlrpc_prepare_page' run inside this call, and their cost is not bounded by anything here.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_option()one call below wp_xmlrpc_server::_prepare_page()
Further down the call graph this can also reach cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_xmlrpc_server::_prepare_page() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($page) && !is_object_in_taxonomy() | 118–121 | get_extended(), get_permalink(), comments_open(), pings_open(), ->_convert_date(), ->_convert_date_gmt(), is_object_in_taxonomy(), get_userdata(), get_page_template_slug(), ->get_custom_fields(), apply_filters() |
empty($page) && is_object_in_taxonomy() | 125–129 | get_extended(), get_permalink(), comments_open(), pings_open(), ->_convert_date(), ->_convert_date_gmt(), is_object_in_taxonomy(), wp_get_post_categories(), get_userdata(), get_page_template_slug(), ->get_custom_fields(), apply_filters() |
!empty($page) && !is_object_in_taxonomy() | 126–129 | get_extended(), get_permalink(), get_post(), comments_open(), pings_open(), ->_convert_date(), ->_convert_date_gmt(), is_object_in_taxonomy(), get_userdata(), get_page_template_slug(), ->get_custom_fields(), apply_filters() |
!empty($page) && is_object_in_taxonomy() | 133–137 | get_extended(), get_permalink(), get_post(), comments_open(), pings_open(), ->_convert_date(), ->_convert_date_gmt(), is_object_in_taxonomy(), wp_get_post_categories(), get_userdata(), get_page_template_slug(), ->get_custom_fields(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 145 instructions, 118–137 executed per call, 7 branches. The work does not change between versions.
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 · 1
One hook fires while wp_xmlrpc_server::_prepare_page() runs, in this order:
- apply_filters( xmlrpc_prepare_page )filterline 1185 (+71 into the body)
Filters XML-RPC-prepared data for the given page.
Uses · 14
- get_extended()Gets extended entry info ().
- get_permalink()Retrieves the full permalink for the current post or post ID.
- get_post()Retrieves post data given a post ID or post object.
- comments_open()Determines whether the current post is open for comments.
- pings_open()Determines whether the current post is open for pings.
- is_object_in_taxonomy()Determines if the given object type is associated with the given taxonomy.
- wp_get_post_categories()Retrieves the list of categories for a post.
- get_cat_name()Retrieves the name of a category from its ID.
- get_userdata()Retrieves user info by user ID.
- get_page_template_slug()Gets the specific template filename for a given post.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_xmlrpc_server::_convert_date()Converts a WordPress date string to an IXR_Date object.
Show all 14
- wp_xmlrpc_server::_convert_date_gmt()Converts a WordPress GMT date string to an IXR_Date object.
- wp_xmlrpc_server::get_custom_fields()Retrieves custom fields for post.
Used by · 2
- wp_xmlrpc_server::wp_getPage()Retrieves a page.
- wp_xmlrpc_server::wp_getPages()Retrieves Pages.
Source code
protected function _prepare_page( $page ) { // Get all of the page content and link. $full_page = get_extended( $page->post_content ); $link = get_permalink( $page->ID ); // Get info the page parent if there is one. $parent_title = ''; if ( ! empty( $page->post_parent ) ) { $parent = get_post( $page->post_parent ); $parent_title = $parent->post_title; } // Determine comment and ping settings. $allow_comments = comments_open( $page->ID ) ? 1 : 0; $allow_pings = pings_open( $page->ID ) ? 1 : 0; // Format page date. $page_date = $this->_convert_date( $page->post_date ); $page_date_gmt = $this->_convert_date_gmt( $page->post_date_gmt, $page->post_date ); // Pull the categories info together. $categories = array(); if ( is_object_in_taxonomy( 'page', 'category' ) ) { foreach ( wp_get_post_categories( $page->ID ) as $cat_id ) { $categories[] = get_cat_name( $cat_id ); } } // Get the author info. $author = get_userdata( $page->post_author ); $page_template = get_page_template_slug( $page->ID ); if ( empty( $page_template ) ) { $page_template = 'default'; } $_page = array( 'dateCreated' => $page_date, 'userid' => $page->post_author, 'page_id' => $page->ID, 'page_status' => $page->post_status, 'description' => $full_page['main'], 'title' => $page->post_title, 'link' => $link, 'permaLink' => $link, 'categories' => $categories, 'excerpt' => $page->post_excerpt, 'text_more' => $full_page['extended'], 'mt_allow_comments' => $allow_comments, 'mt_allow_pings' => $allow_pings, 'wp_slug' => $page->post_name, 'wp_password' => $page->post_password, 'wp_author' => $author->display_name, 'wp_page_parent_id' => $page->post_parent, 'wp_page_parent_title' => $parent_title, 'wp_page_order' => $page->menu_order, 'wp_author_id' => (string) $author->ID, 'wp_author_display_name' => $author->display_name, 'date_created_gmt' => $page_date_gmt, 'custom_fields' => $this->get_custom_fields( $page->ID ), 'wp_page_template' => $page_template, ); /** * Filters XML-RPC-prepared data for the given page. * * @since 3.4.0 * * @param array $_page An array of page data. * @param WP_Post $page Page object. */ return apply_filters( 'xmlrpc_prepare_page', $_page, $page ); }Changelog
Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/class-wp-xmlrpc-server.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.