[wp-hackers] Plugins registering "urls"

Mark Jaquith mark.wordpress at txfx.net
Mon Dec 11 21:42:03 GMT 2006


On Dec 11, 2006, at 11:33 AM, Harald Nesland wrote:

> I was wondering if it was possible to register an URL (permalink,
> page..) from a plugin?

Here's some sample code that I had tucked away.  Hope it helps.  This  
could definitely be easier.

No guarantee on this, by the way... I just hacked PATHINFO vs  
mod_rewrite support in at the last second, and this doesn't have any  
fallbacks for people without pretty permalink of one kind or another,  
so you'll have to include that in your code.

> <?php
>
> function your_rewrite_rules($rules) {
> 	$prefix = ( strpos(get_option('permalink_structure'), '/ 
> index.php/') === 0 ) ? 'index.php/' : '';
> 	$rules[$prefix . 'yourspecialsomething/(.*?)/(.*?)/?$'] =  
> 'index.php?your_query_var=$matches[1]&another_qv=$matches[2]';
> 	return $rules;
> }
>
>
> function your_add_query_vars($query_vars) {
> 	$query_vars[] = 'your_query_var';
> 	$query_vars[] = 'another_qv';
> 	return $query_vars;
> }
>
>
> function your_template_redirect() {
> 	if ( get_query_var('your_query_var') && get_query_var 
> ('another_qv') ) {
> 		include(TEMPLATEPATH . '/your-template.php');
> 		exit;
> 	}
> }
>
> add_filter('rewrite_rules_array', 'your_rewrite_rules');
> add_filter('query_vars', 'your_add_query_vars');
> add_action('template_redirect', 'your_template_redirect');
>
> ?>


--
Mark Jaquith
http://markjaquith.com/

Covered Web Services
http://covered.be/




More information about the wp-hackers mailing list