[wp-hackers] wp-config.php, wp-load.php, and ABSPATH

Jörn Röder kontakt at joernroeder.de
Tue Sep 15 22:04:55 UTC 2009


Ok… thanks for this…

Am 15.09.2009 um 16:07 schrieb Otto:

> Wow. Everybody else got that one wrong too. :)
>
> The right way is to not load "styles.css.php" directly in the first
> place. If you need to load the WordPress files, then you should load
> WordPress itself, and direct it to do what you want it to do.
>
> If you want to make some kind of output outside the normal "flow" of
> WordPress, but need the WordPress functions to do it:
>
> First, realize that WordPress is going to load twice anyway. The goal
> is not to eliminate this (if you need wpdb access in your separate
> file, then you sorta have to do load WP again), but to eliminate the
> need to know the WordPress file paths and such.
>
> Example code:
> function plugin_query_vars($public_query_vars) {
> 	$public_query_vars[] = 'SOME_IDENTIFIER';
> 	return $public_query_vars;
> }
> function plugin_special_output() {
> 	if(intval(get_query_var('SOME_IDENTIFIER')) == 1) {
> 		// do whatever output you like here
> 		exit; // stop normal WordPress execution
> 	}
> }
> add_filter('query_vars', 'plugin_query_vars');
> add_action('template_redirect', 'plugin_special_output');
>
>
> After you add this code, a call to any normal WordPress URL with
> ?SOME_IDENTIFIER=1 stuck on the end will return your code instead.
> That code can be *anything*. If you want to output CSS, output CSS.
> Change the headers if you like. Whatever.
>
>
> -Otto
> _______________________________________________
> 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