[wp-hackers] Taking over URL space

Braydon ronin at braydon.com
Tue Feb 21 22:04:49 UTC 2012


Here is another way to have new rules without using add_rewrite_rule:

add_action( 'generate_rewrite_rules', 'my_rewrite_rules' );

function my_rewrite_rules(){
     global $wp_rewrite;
     $rules = array(
         'myplugin/?$' => 'index.php?myplugin=1'
     )
     $wp_rewrite->rules =array_merge($rules,$wp_rewrite->rules);
}

For using extensions on p, something like this could work:

add_action('parse_request','my_parse_request' );

function my_parse_request( &$request ) {
     $post_id = $request->query_vars['p'];
     // check if the post id has an extension
     // also check the "Accept:" header
     // add a new query_var for the extension, and change "p" variable 
back to an id
}

However adding a new query_var for extension would be needed either way.

add_filter( 'query_vars, 'my_query_vars' );

function my_query_vars( $query_vars ){
     $query_vars[] = 'myplugin';
     $query_vars[] = 'ext';
     return $query_vars;
}

And then at the template redirect check for both the myplugin and ext 
query_vars and then have your plugin handle those.

On 02/21/2012 01:58 AM, Phillip Lord wrote:
> I was wondering whether someone could give me pointers in the right
> direction. I'm not after a complete solution! I was just hoping that
> someone with more knowledge of wordpress could tell me if I am heading
> in the right way.
>
> I wanted to write a new plugin which returns metadata about posts in a
> variety of different ways. To do this, I need to use various parts of
> the URL space, but I don't know how best to do this.
>
>
> Essentially, I want to do three things.
>
> 1) I would like to be able to use bits of the URL space from top level.
>     So, for a wordpress at
>
> http://mydomain.org.uk
>
> I would like to be able to serve all requests to..
>
> http://mydomain.org.uk/myplugin
>
> My initial idea was to achieve all this with rewrite rules, but
> requiring users to modify .htaccess com. wp-rewrite seems the next
> option -- I can just rewrite requests to this and underlying rewrite
> plugin php?
>
>
> 2) I want to add support for file extension based access. So for a
> URL such as
>
> http://mydomain.org.uk/?p=46
>
> I'd like requests to
>
> http://mydomain.org.uk/?p=46.bib
>
> to be handled by my plugin, probably by sending the browser straight to
> a URL of the http://mydomain.org.uk/myplugin. I am not sure how well
> this would interact with pretty permalinks -- something of the form
>
> http://mydomain.org.uk/2012/02/02/mypost/
>
> looks daft with an extension
> http://mydomain.org.uk/2012/02/02/mypost/.bib
>
> However, as far as I can see this is a similar problem to the last.
>
> 3)
>
> And, finally, I'd like to provide a content negotiated solution. So
> requests to:
>
> http://mydomain.org.uk/?p=46
>
> will return different results depending on the content type in the
> Accept: header of the request; again, this will probably be implemented
> by forwarding the browser.
>
> This one seems to be the most taxing -- I can't do this with rewrite
> rules because it is the same in all cases.
>
> Any pointers gratefully received!
>
> Phil
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> !DSPAM:4f436acf300322900114539!
>


-- 
Braydon Fuller
http://braydon.com/



More information about the wp-hackers mailing list