[wp-hackers] The problem with WP_Rewrite <<< RE: Options for Controller - Views

Otto otto at ottodestruct.com
Thu Dec 3 17:01:15 UTC 2009


On Thu, Dec 3, 2009 at 10:37 AM, Mike Schinkel
<mikeschinkel at newclarity.net> wrote:
> First, that's far more complicated than it should be if this is something people will be doing a lot.

I fail to understand how two function calls is at all "complicated".
Yes, you need to know regular expressions. They're not that complex.

> Unless I misunderstand, that's not I'm looking for.  Using your example, this might be what I'm looking for (not sure about the "add_rewrite_tag()" as I don't really understand what it does):

You know how custom permalinks work? Like /%year%/%month%/%postname%
and so forth?

%postname% is a rewrite tag. It takes whatever is in that space and
puts it into the $wp_query->postname variable.

When you add a rewrite tag, you're creating a new one of those. The
second parameter is a limiter, so I can limit the value to be all
digits or something, if I wanted. The .* is simply a way of saying it
can be anything (regular expressions again).

So I can define a tag like, say, product. The rewrite matches
something and puts it into the URL as index.php?product=whatever.
Because I've defined "product" as being okay, that gets read and put
into my wp_query object.

> Can I assume that post_type is not supported until 2.9?  It doesn't seem to work in 2.8 (which is what I'm working with.)

The post_type variable is supported in 2.8, but *custom* post_type
support wasn't added until 2.9.

>> function plugin_add_template() {
>>  if (get_query_var('post_type') == 'whatever') {
>>    locate_template(array('custom/product.php'),true);
>>    exit;
>>  }
>> }
>> add_action('template_redirect', 'plugin_add_template');
>
> Again, too complex for doing often.  But let's hold that thought too...

I'm utterly floored by this statement. What part of that is at all
"complex"? That's about the simplest possible code I can imagine to do
something like this. If you want to abstract 10 lines of code into 1,
then that's fine, but that sort of nonsense shouldn't be core code.


> It helps yes.  OTOH, it's not much different from what I did before in that it seems to be leveraging 2.9 functionality I had no access to in 2.8.
>
> Also, it requires a level of complexity that few if any theme developers will go to.  Themers *will* be willing to use a simplifying layer like what I showed with add_custom_url() and I strongly believe such a functionality is needed.  Yes it will not cover every potential use case as the lower level examples can but it will cover the most common use cases and make them very easy to implement.
>
> I'll try to implement add_custom_url() on the 2.9 platform and submit it as a patch soon.

I would suggest that you submit it as a plugin instead. I don't think
that this sort of needless wrappers and abstraction should be in the
core.

-Otto
Sent from Memphis, TN, United States


More information about the wp-hackers mailing list