[wp-hackers] Friendly plugin URL entrypoints?

Jeff Minard jeff at jrm.cc
Fri Feb 3 16:42:17 GMT 2006


Owen Winkler wrote:
> Would it be worthwhile to have a dedicated friendly-style URL entry 
> point for plugins?  For example...
> 
> Instead of requesting:
> http://example.com/wp-content/plugins/myplugin/myplugin.php?entrypoint=1
> 
> I could request something like:
> http://example.com/_plugin/myplugin/1
> 
> Suggestions for prettier alternatives are welcome.

I steal the 404 page for this sort of thing.

For example, I can't recall exactly which hook it is (404, page_query, 
something), but when I hook it I do a simple query against the query 
object to see what wordpress tells me the pagename is, then if it's what 
I'm looking for I steal the output right there -- or in some cases, will 
reset portions of the wp_query object to turn the "404" into a 
category/post/page.

-- really short example ---------------------------------------------
add_filter('the_posts', 'catch_the_posts_about');
function catch_the_posts_about($posts) {
   if( $_SERVER['QUERY_STRING'] == 'pagename=myplugin-ajax' ) {
     //jack output
     exit;
   }
   return $posts;
}
-- /really short example --------------------------------------------

Now, this of course spits in the face of what might be a perfectly valid 
URL structure, so I'm not quite sure how to assess damages here, but it 
works really nicely.

Jeff


More information about the wp-hackers mailing list