Rewrite API
add_rewrite_rule()
A function for adding a straight rewrite rule.
Parameters:
- Regex to match
- URL to redirect to.
- Optional flag indicating if rule should be added to top or bottom (default) of the rules.
The URL should look like 'index.php?var1=$matches[1]&var2=$matches[2]&var3=$matches[3]' where var1-3 are the relevant query variables and $matches refers to matches in the regular expression.
What it does:
- Builds a rewrite rule from the regex and redirect URL.
- Theoretically it could then filter rewrite_rules_array and add the rules itself, but I think we should add a function to WP_Rewrite for adding 'extra' rules that needn't be generated by generate_rewrite_rules(). rewrite_rules() would then just tack on these extra rules after the ones generated. These extra rules should probably be stored in an option.
add_rewrite_tag()
Add a new tag (like %postname%):
Parameters:
- Name of tag
- Regex to match
What it does:
- Get a query var name by stripping the % signs from the name of the tag: trim($name, '%')
- Call $wp_rewrite->add_rewrite_tag() with the name, generated QV name and regex.
- Add the QV as a query var (again, this could be done by filtering query_vars but it might be nicer to add a function to the WP class that stores 'extra' QVs like above)
add_rewrite_endpoint()
Add a new endpoint like /trackback/
Parameters:
- Name of endpoint
- Places mask which indicates on which links the endpoint should be added (EP_PERMALINK, EP_PAGES, EP_ATTACHMENT, etc).
This adds the endpoint to all link types indicated (e.g. posts, pages, category, author, search) and then template-loader.php includes the relevent handler file
The name of the endpoint is added as query variable and this gets as value any text present after the endpoint name, separated from the name with a '/'. The template_redirect handler should test this query variable.
This can be used for all sorts of things:
- ajax handler
- form submission handler
- alternative notification handler
add_feed()
Add a new feed type like /atom1/
Parameters:
- feed
- File to include to handle feed / or should it be a function to call / either
This simply adds/overrides the feed type and then wp-feed.php includes the relavent handler file
add_base()
NOTE: The function described below has never implemented within WordPress, It is likely that this document was a rough draft of proposed functionality
Add a new base permalink type (equivalent of author, archives, category etc. or equivalent of search)
Parameters:
- permalink name
- normal query (bool) - If true then this base supports a normal query type - ie the same child permalink structure as archives. If false then the handler will parse the rest of the query.
- File to include to handle it / or should it be a function to call / either
This simply adds a new permalink base type. Either with or without the standard permalink appendage. It could be used for a /tags/tagname type structure, or to embedded a gallery or for something like /wibble/2005/12/3 where you wanted to put a particular spin on the query results