Filters in WordPress
Having just read the very interesting and throughout explaination by Michel Fortin of his problems with the WordPress filters when trying to get [PHP Markdown][] right, I think it’s amazing that it works at all!
His experience together with the recent discussion started by Denis de Bernardy about the plugin system (and specifically the hooks offered to plugins) seems to suggest that the whole system could use some rethinking. (And when doing so, then please document it! :-)
Denis de Bernardy:
I wish… ;) I might fork the plugin system with my CMS theme’s next version.
1 June 2005, 3:08 pmMartin Geisler:
I’ve been doing some thinking myself about how a plugin system should
work. For the filters it’s evident that it is too simple to just have
a chain of functions doing “stuff” to the text. We need more
structure, so that the “text” is in a well-defined format, and we need
to define what you can do to this text.
Perhaps this could be done by defining an [XML][] format for the text,
and then all filters would modify this? One could require that the
text is [XHTML][] at the beginning of the filter chain, and then the
filters should have access to a proper parser and only modify the text
through that. I’m not that much into this stuff, but I believe that
this is what the XSL Transformation language lets you do.
Of course, having all plugins modify the text using those style sheets
would make it a lot harder to write plugins. Perhaps using full
stylesheets should be optional — with the knowledge that the text is
(valid!) XHTML, the plugins will still be able to parse and change it
reliably without necessarily having to use an XML parser.
I guess my ideas goes somewhat along the lines of the changes
1 June 2005, 11:42 pmoutlined by Michel Fortin on the mailinglist: draw a line
somewhere and say: “Here we deal with the raw input from the user,
and here we deal with valid XHTML.” If such a division was actually
made, then lots of things would be easier.
Denis de Bernardy:
What you are describing is, more or less, what I’m doing with the latest versions of my plugins fuzzy recent plugins, as well as what I’m doing in the upcoming version of my theme.
Basically, I do something along the lines of:
I might bypass the filtering system entirely in a next version of my theme, and do something along the lines of the following instead:
as suggested in the hackers list a couple of days ago. this would assume a limited number of use cases could be defined. I can name three:
there are possibly a few more. but not that many. in any event, this would significantly reduce the amount of plugin hooks, and do so for the better.
2 June 2005, 12:00 amMartin Geisler:
Yep, I’ve noticed that your plugins are moving to XML, which I think it great! And as you say: make fewer plugin hooks but make them better, or to say the same using other words: “less is more” :-)
2 June 2005, 9:10 am