[wp-hackers] Showing custom page types

Chris Jean gaarai at gaarai.com
Thu Jan 29 21:18:03 GMT 2009


Thanks for the heads-up on the flush rules call. I'll get that code 
locked down to only add the rules when the rules change or when the 
plugin activates and to only flush on activation.

I looked at the parse_request action and ended up settling on the 
template_redirect one instead. I'll look at the parse_request action 
again and see if I can gain any better/faster functionality by going 
that route.

I don't like the idea of shortcutting the WordPress system by directly 
calling the template file directly and exiting. I traced the code, and 
there won't directly be any actions, filters, or other calls directly 
bypassed because of this since loading the template file is the last 
thing that WordPress does. However, if any other actions are queued up 
in the template_redirect action or if any other actions are added at 
some point, this bypass could cause an issue in the future.

I always like to work with the system rather than breaking through the 
system if possible. My desire to learn the "right way" to do this was 
the reason for sending the original message.

Thanks for going through my code and being willing to help. I'll check 
out the template_redirect action and see what I can do with it.

Chris Jean
http://gaarai.com/
http://wp-roadmap.com/



Jennifer Hodgdon wrote:
> Since you asked for thoughts and suggestions on your plugin code 
> (which I won't include again here), here are a few ideas:
>
> a) Calling flush_rewrite_rules() in every 'init' action is not a good 
> idea. That means it will happen on every page load for every blog 
> visitor, and it's a time-consuming action (well, technically it is the 
> rebuild of rewrite rules that is expensive, not the flush itself). You 
> probably want to change the logic to flush rewrite rules only when 
> necessary, such as when someone changes the config. You might also 
> find the 'query_vars' filter and 'generate_rewrite_rules' action to be 
> useful to do some of the logic you put into your 'init' action.
>
> b) Besides the 'template_redirect' action, you can also use the 
> 'parse_request' action to override what WP is planning to do.
>
> c) In your function for the 'template_redirect' action, you can also 
> do something like this:
>
> if( logic to detect you are on one of your pages ) {
>    include( full path to your desired template file );
>    exit;
> }
>
> Hope this helps...
>     Jennifer
>
> Chris Jean wrote:
>> I'm working on a new project that uses WordPress as a framework 
>> rather than as just a blogging platform. I want to be able to have 
>> custom URL structures, such as /tool/option, that will end up passing 
>> variables to a set of code to render the page contents rather than 
>> one of the theme template files rendering the content.
>
>


More information about the wp-hackers mailing list