[wp-hackers] siteurl and home variables / constants

SoJ Web sojweb at indiana.edu
Mon Mar 30 12:57:25 GMT 2009


Sounds like a good idea to me; performance issues aside, I'd think it  
ought to do that anyway. Isn't that the point of those constants?


-Jeff Johnson

On Mar 30, 2009, at 4:29 AM, Joost de Valk wrote:

> Hey,
>
> I was looking at the code for site_url in /wp-includes/link- 
> template.php, and saw that it /always/ does a get_option('siteurl'),  
> even when, as on my site, WP_SITEURL is defined in wp-config.php.  
> The same goes for get_bloginfo in /wp-includes/general-template.php,  
> for both WP_SITEURL and WP_HOME.
>
> Wouldn't it be good to check for that before doing the get_option,  
> to save a query or two on each page load?
>
> It would be quite easy to make those functions use check for the  
> defined constants before doing a database call.
>
> A quick plugin I cooked[1] up that does this by using the  
> pre_option_* hook, showed me that this would save quite a number of  
> calls (though of course after the two first calls, these would be  
> cached). The only "issue" I encountered was that in functions.php's  
> is_blog_installed function, a db query is done to check whether a  
> blog is installed, and the query that's done is, you've guessed it,  
> retrieving the siteurl...
>
> Anyway, I think some performance improvement could be made by adding  
> in a check for the defined constants, but maybe I'm missing something?
>
> Best,
> Joost
>
>
> [1] The source for that plugin is very simple:
>
> function checkwp_config_siteurl() {
>    if ( defined( 'WP_SITEURL' ) ) {
>        // error_log("Prevented get_option");
>        return WP_SITEURL;
>    }
>    return false;
> }
> add_filter('pre_option_wpurl','checkwp_config_siteurl',10,1);
>
> function checkwp_config_home() {
>    if ( defined( 'WP_HOME' ) ) {
>        // error_log("Prevented get_option");
>        return WP_HOME;
>    }
>    return false;
> }
> add_filter('pre_option_url','checkwp_config_home',10,1);
> add_filter('pre_option_siteurl','checkwp_config_home',10,1);
> add_filter('pre_option_home','checkwp_config_home',10,1);
>
>
> me *Joost de Valk*
> Online Marketing, WordPress, SEO & Social Media Strategy
> OrangeValley <http://www.orangevalley.nl> & Yoast <http://yoast.com>
> E: joost at orangevalley.nl <mailto:joost at orangevalley.nl> - joost at yoast.com 
>  <mailto:joost at yoast.com>
> T: +316-24-555-808 | @yoast <http://twitter.com/yoast> on Twitter
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list