[wp-hackers] siteurl and home variables / constants

Jason Webster jason at intraffic.net
Mon Mar 30 15:52:01 GMT 2009


There is already a function that does exactly that on the option_siteurl filter. (_config_wp_siteurl 
to be exact).

That is to say, that get_option('siteurl') will _always_ return the value of the constant, if it is 
set.

It doesn't make a database call regardless, because those options are all prefetched and stored in 
memory anyway. wp_load_alloptions is only called once, and siteurl is autoloaded.... I fail to see 
how this would save "quite a number of calls".


On 30/03/2009 1: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