Make WordPress Core

Changeset 20784


Ignore:
Timestamp:
05/14/2012 05:00:13 PM (12 years ago)
Author:
ryan
Message:

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

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-xmlrpc-server.php

    r20782 r20784  
    755755
    756756    /**
     757     * Prepares page data for return in an XML-RPC object.
     758     *
     759     * @access protected
     760     *
     761     * @param object $page The unprepared page data
     762     * @return array The prepared page data
     763     */
     764    protected function _prepare_page( $page ) {
     765        // Get all of the page content and link.
     766        $full_page = get_extended( $page->post_content );
     767        $link = post_permalink( $page->ID );
     768
     769        // Get info the page parent if there is one.
     770        $parent_title = "";
     771        if ( ! empty( $page->post_parent ) ) {
     772            $parent = get_page( $page->post_parent );
     773            $parent_title = $parent->post_title;
     774        }
     775
     776        // Determine comment and ping settings.
     777        $allow_comments = comments_open( $page->ID ) ? 1 : 0;
     778        $allow_pings = pings_open( $page->ID ) ? 1 : 0;
     779
     780        // Format page date.
     781        $page_date = $this->_convert_date( $page->post_date );
     782        $page_date_gmt = $this->_convert_date_gmt( $page->post_date_gmt, $page->post_date );
     783
     784        // Pull the categories info together.
     785        $categories = array();
     786        foreach ( wp_get_post_categories( $page->ID ) as $cat_id ) {
     787            $categories[] = get_cat_name( $cat_id );
     788        }
     789
     790        // Get the author info.
     791        $author = get_userdata( $page->post_author );
     792
     793        $page_template = get_page_template_slug( $page->ID );
     794        if ( empty( $page_template ) )
     795            $page_template = 'default';
     796
     797        $_page = array(
     798            'dateCreated'            => $page_date,
     799            'userid'                 => $page->post_author,
     800            'page_id'                => $page->ID,
     801            'page_status'            => $page->post_status,
     802            'description'            => $full_page['main'],
     803            'title'                  => $page->post_title,
     804            'link'                   => $link,
     805            'permaLink'              => $link,
     806            'categories'             => $categories,
     807            'excerpt'                => $page->post_excerpt,
     808            'text_more'              => $full_page['extended'],
     809            'mt_allow_comments'      => $allow_comments,
     810            'mt_allow_pings'         => $allow_pings,
     811            'wp_slug'                => $page->post_name,
     812            'wp_password'            => $page->post_password,
     813            'wp_author'              => $author->display_name,
     814            'wp_page_parent_id'      => $page->post_parent,
     815            'wp_page_parent_title'   => $parent_title,
     816            'wp_page_order'          => $page->menu_order,
     817            'wp_author_id'           => (string) $author->ID,
     818            'wp_author_display_name' => $author->display_name,
     819            'date_created_gmt'       => $page_date_gmt,
     820            'custom_fields'          => $this->get_custom_fields( $page->ID ),
     821            'wp_page_template'       => $page_template
     822        );
     823
     824        return apply_filters( 'xmlrpc_prepare_page', $_page, $page );
     825    }
     826
     827    /**
    757828     * Create a new post for any registered post type.
    758829     *
     
    18341905        // If we found the page then format the data.
    18351906        if ( $page->ID && ($page->post_type == 'page') ) {
    1836             // Get all of the page content and link.
    1837             $full_page = get_extended($page->post_content);
    1838             $link = post_permalink($page->ID);
    1839 
    1840             // Get info the page parent if there is one.
    1841             $parent_title = "";
    1842             if ( !empty($page->post_parent) ) {
    1843                 $parent = get_page($page->post_parent);
    1844                 $parent_title = $parent->post_title;
    1845             }
    1846 
    1847             // Determine comment and ping settings.
    1848             $allow_comments = comments_open($page->ID) ? 1 : 0;
    1849             $allow_pings = pings_open($page->ID) ? 1 : 0;
    1850 
    1851             // Format page date.
    1852             $page_date = $this->_convert_date( $page->post_date );
    1853             $page_date_gmt = $this->_convert_date_gmt( $page->post_date_gmt, $page->post_date );
    1854 
    1855             // Pull the categories info together.
    1856             $categories = array();
    1857             foreach ( wp_get_post_categories($page->ID) as $cat_id ) {
    1858                 $categories[] = get_cat_name($cat_id);
    1859             }
    1860 
    1861             // Get the author info.
    1862             $author = get_userdata($page->post_author);
    1863 
    1864             $page_template = get_page_template_slug( $page->ID );
    1865             if ( empty( $page_template ) )
    1866                 $page_template = 'default';
    1867 
    1868             $page_struct = array(
    1869                 'dateCreated'           => $page_date,
    1870                 'userid'                => $page->post_author,
    1871                 'page_id'               => $page->ID,
    1872                 'page_status'           => $page->post_status,
    1873                 'description'           => $full_page['main'],
    1874                 'title'                 => $page->post_title,
    1875                 'link'                  => $link,
    1876                 'permaLink'             => $link,
    1877                 'categories'            => $categories,
    1878                 'excerpt'               => $page->post_excerpt,
    1879                 'text_more'             => $full_page['extended'],
    1880                 'mt_allow_comments'     => $allow_comments,
    1881                 'mt_allow_pings'        => $allow_pings,
    1882                 'wp_slug'               => $page->post_name,
    1883                 'wp_password'           => $page->post_password,
    1884                 'wp_author'             => $author->display_name,
    1885                 'wp_page_parent_id'     => $page->post_parent,
    1886                 'wp_page_parent_title'  => $parent_title,
    1887                 'wp_page_order'         => $page->menu_order,
    1888                 'wp_author_id'          => (string) $author->ID,
    1889                 'wp_author_display_name'    => $author->display_name,
    1890                 'date_created_gmt'      => $page_date_gmt,
    1891                 'custom_fields'         => $this->get_custom_fields($page_id),
    1892                 'wp_page_template'      => $page_template
    1893             );
    1894 
    1895             return($page_struct);
     1907            return $this->_prepare_page( $page );
    18961908        }
    18971909        // If the page doesn't exist indicate that.
     
    19361948            $pages_struct = array();
    19371949
    1938             for ( $i = 0; $i < $num_pages; $i++ ) {
    1939                 $page = wp_xmlrpc_server::wp_getPage(array(
    1940                     $blog_id, $pages[$i]->ID, $username, $password
    1941                 ));
    1942                 $pages_struct[] = $page;
     1950            foreach ($pages as $page) {
     1951                if ( current_user_can( 'edit_page', $page->ID ) )
     1952                    $pages_struct[] = $this->_prepare_page( $page );
    19431953            }
    19441954
  • trunk/wp-includes/option.php

    r20783 r20784  
    4545        return false;
    4646
    47     $default = apply_filters( 'default_option_' . $option, $default );
    48 
    4947    if ( ! defined( 'WP_INSTALLING' ) ) {
    5048        // prevent non-existent options from triggering multiple queries
    5149        $notoptions = wp_cache_get( 'notoptions', 'options' );
    5250        if ( isset( $notoptions[$option] ) )
    53             return $default;
     51            return apply_filters( 'default_option_' . $option, $default );
    5452
    5553        $alloptions = wp_load_alloptions();
     
    7068                    $notoptions[$option] = true;
    7169                    wp_cache_set( 'notoptions', $notoptions, 'options' );
    72                     return $default;
     70                    return apply_filters( 'default_option_' . $option, $default );
    7371                }
    7472            }
     
    8179            $value = $row->option_value;
    8280        else
    83             return $default;
     81            return apply_filters( 'default_option_' . $option, $default );
    8482    }
    8583
     
    757755        return $pre;
    758756
    759     $default = apply_filters( 'default_site_option_' . $option, $default );
    760 
    761     if ( !is_multisite() ) {
     757    if ( ! is_multisite() ) {
     758        $default = apply_filters( 'default_site_option_' . $option, $default );
    762759        $value = get_option($option, $default);
    763760    } else {
     
    775772                wp_cache_set( $cache_key, $value, 'site-options' );
    776773            } else {
    777                 $value = $default;
     774                $value = apply_filters( 'default_site_option_' . $option, $default );
    778775            }
    779776        }
Note: See TracChangeset for help on using the changeset viewer.