WCSF 2011 Voodoo

Rarst asks: what magic turns pretty permalinks into query variables?

The setup:

The magic:

foreach ( $rewrite as $match => $query ) {
	if ( preg_match("#^$match#", $request_match, $matches) ) {
		// Got a match.
		$this->matched_rule = $match;
		break;
	}
}

The real voodoo is in creating the rewrite rules. Example: bbPress

  • register_post_types
  • register_taxonomies
  • add_rewrite_tags
  • generate_rewrite_rules

Exercise: optimize parse_request by restructuring the rules into a tree.

Nacin suggests: wp-hackers Skip Main Query

  • the grand scheme of things (png, blog post)
  • $wp->init()
  • class freshlypressed_wp extends wp
  • wp() calls $wp->main()
  • $wp->main() calls $this->parse_request()
  • $this is a freshlypressed_wp

Problems:

  • Can’t extend a variable class (class my_wp extends $wp_class)
  • No pluggable inheritance chaining
  • No way for several plugins to cooperatively extend a class
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 1,665 other followers

%d bloggers like this: