[wp-hackers] 2.next and categories functions

Jamie Talbot wphackers at jamietalbot.com
Sat Mar 4 11:10:45 GMT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ryan Boren wrote:
> As for #2328, I think we can be even more comprehensive than that. Let's
> make our hooks wish list for these functions.

I don't think it's necessary to have lots of hooks, just one good hook in the right place.  As David
suggested, I'd like to see a filter on the actual array content, instead of just the
outputted text.  However, I argued that it would be more useful to have a filter before the
categories or pages are even fetched by WordPress, so that plugins can generate their own subset of
categories or posts according to more complex criteria without having to filter the full set of results.

Getting all categories then providing a filter means we have to unset those categories in the array
that we don't want.  This probably involves the plugin making its own db access, then unsetting each
element of the object array.  It would work, but it's not pretty.  Relying solely on 'exclusions' or
'only' means a plugin has to generate a long string of ids.  (Incidentally, in the exclusions logic,
would it be more efficient to use NOT IN(1,2,...) instead of AND cat_id <> 1 AND cat_id <> 2 ... ?
Not sure of the speed comparison).

This is a rough idea of what I'd like to see, for example, in get_category(), where $r is the
supplied args merged with defaults:

// Takes arguments and returns an OBJECT array of category data.
$categories = do_action('get_category', $r);

// WordPress retrieves the categories if the plugin didn't.
if (!$categories) $categories = $wpdb->get_results("...");

This can take place even before the 'exclusions' (and the presumed 'only') loop as long as the
plugin has access to the arguments and handles them.

Note that the check above is too simple and would have to include the possibility that the plugin
deliberately returned no categories.  This method avoids the need for multiple db accesses and also
allows plugins to do other things like alter the cat_name here, if they were able, instead of having
to update it later in list_cats.  Mainly, it gives access to the source of the data, the effects of
which will happen throughout the site and admin interface from only one plugin function.  Similar
functionality in pages and bookmarks would be great too.

Finally, for building a category or page list, it would good if the _page_dropdown_element etc
callback functions were pluggable so formatting could be controlled.  At the moment, access only to
the HTML, through the wp_list_pages filter is a bit clunky.

Cheers,

Jamie.

- --
http://jamietalbot.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFECXW0rovxfShShFARAizqAJ9qLdg1ev+uB1go7BDWd/C+w74hBwCfdEnc
m2jLUx7fj7X+pzxtRY+ALzU=
=JFE6
-----END PGP SIGNATURE-----


More information about the wp-hackers mailing list