Call filters for default option values only as needed to reduce number of filter calls. Props Ott042. see #20448

git-svn-id: http://core.svn.wordpress.org/trunk@20784 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2012-05-14 17:00:13 +00:00
parent db3da0b695
commit 7c3c1267ec
2 changed files with 81 additions and 74 deletions

View File

@ -753,6 +753,77 @@ class wp_xmlrpc_server extends IXR_Server {
return apply_filters( 'xmlrpc_prepare_media_item', $_media_item, $media_item, $thumbnail_size );
}
/**
* Prepares page data for return in an XML-RPC object.
*
* @access protected
*
* @param object $page The unprepared page data
* @return array The prepared page data
*/
protected function _prepare_page( $page ) {
// Get all of the page content and link.
$full_page = get_extended( $page->post_content );
$link = post_permalink( $page->ID );
// Get info the page parent if there is one.
$parent_title = "";
if ( ! empty( $page->post_parent ) ) {
$parent = get_page( $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();
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
);
return apply_filters( 'xmlrpc_prepare_page', $_page, $page );
}
/**
* Create a new post for any registered post type.
*
@ -1833,66 +1904,7 @@ class wp_xmlrpc_server extends IXR_Server {
// If we found the page then format the data.
if ( $page->ID && ($page->post_type == 'page') ) {
// Get all of the page content and link.
$full_page = get_extended($page->post_content);
$link = post_permalink($page->ID);
// Get info the page parent if there is one.
$parent_title = "";
if ( !empty($page->post_parent) ) {
$parent = get_page($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();
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_struct = 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
);
return($page_struct);
return $this->_prepare_page( $page );
}
// If the page doesn't exist indicate that.
else {
@ -1935,11 +1947,9 @@ class wp_xmlrpc_server extends IXR_Server {
if ( $num_pages >= 1 ) {
$pages_struct = array();
for ( $i = 0; $i < $num_pages; $i++ ) {
$page = wp_xmlrpc_server::wp_getPage(array(
$blog_id, $pages[$i]->ID, $username, $password
));
$pages_struct[] = $page;
foreach ($pages as $page) {
if ( current_user_can( 'edit_page', $page->ID ) )
$pages_struct[] = $this->_prepare_page( $page );
}
return($pages_struct);

View File

@ -44,13 +44,11 @@ function get_option( $option, $default = false ) {
if ( defined( 'WP_SETUP_CONFIG' ) )
return false;
$default = apply_filters( 'default_option_' . $option, $default );
if ( ! defined( 'WP_INSTALLING' ) ) {
// prevent non-existent options from triggering multiple queries
$notoptions = wp_cache_get( 'notoptions', 'options' );
if ( isset( $notoptions[$option] ) )
return $default;
return apply_filters( 'default_option_' . $option, $default );
$alloptions = wp_load_alloptions();
@ -69,7 +67,7 @@ function get_option( $option, $default = false ) {
} else { // option does not exist, so we must cache its non-existence
$notoptions[$option] = true;
wp_cache_set( 'notoptions', $notoptions, 'options' );
return $default;
return apply_filters( 'default_option_' . $option, $default );
}
}
}
@ -80,7 +78,7 @@ function get_option( $option, $default = false ) {
if ( is_object( $row ) )
$value = $row->option_value;
else
return $default;
return apply_filters( 'default_option_' . $option, $default );
}
// If home is not set use siteurl.
@ -756,9 +754,8 @@ function get_site_option( $option, $default = false, $use_cache = true ) {
if ( false !== $pre )
return $pre;
$default = apply_filters( 'default_site_option_' . $option, $default );
if ( !is_multisite() ) {
if ( ! is_multisite() ) {
$default = apply_filters( 'default_site_option_' . $option, $default );
$value = get_option($option, $default);
} else {
$cache_key = "{$wpdb->siteid}:$option";
@ -774,7 +771,7 @@ function get_site_option( $option, $default = false, $use_cache = true ) {
$value = maybe_unserialize( $value );
wp_cache_set( $cache_key, $value, 'site-options' );
} else {
$value = $default;
$value = apply_filters( 'default_site_option_' . $option, $default );
}
}
}