[wp-testers] 2.3 Beta 1 changes semantics of get_the_title

Travis Snoozy ai2097 at users.sourceforge.net
Sun Sep 2 18:48:19 GMT 2007


On Sun, 02 Sep 2007 10:35:04 -0700, Jennifer Hodgdon
<yahgrp at poplarware.com> wrote:

> Travis Snoozy wrote:
> 
> >   The get_the_title function is now filtered, whereas in the past
> > (through all the versions back to 2.0; I haven't checked earlier)
> > it was not. 
> 
> See  http://trac.wordpress.org/ticket/4477  for discussion of why
> this was done.

Thanks for the pointer.

I understand why it was done -- the issue is that it breaks everything
that depended on the old behavior (i.e., getting an _unfiltered_
title, and processing it as needed), and there is no API for getting the
title that doesn't ride right on top of the database (get_post/global
$post/etc., which break if there's a schema change).

[SpecificRant]

So, the issue I have specifically is that this will at least break my
plugin insofar as trying to escape post titles that have already been
escaped, and consequently printing out rubbish. It's fixable, but rather
obnoxious (especially in terms of forwards/backwards compatibility).

It may also break how other parts of WordPress interacts with my plugin.
There's a "Title Prefix" option which (as the name would suggest) adds
a prefix to the title of certain posts. This is accomplished using a
filter. get_the_title was previously immune to this change in name, and
now it is not -- I have no idea what the consequences will be, and the
feature (which was rather handy, IMHO) may now be untenable, because
having the prefixed name show up -everywhere- is likely to be too
cluttered, compared to having it show up in just the places that
filtered before.

[GeneralRant]

Where's the insulated, reliable, public API? The one that's _not_
subject to change? Clearly the database is subject to change (see the
recent post2cat stuff), and now the APIs are too? How the heck is
anyone supposed to program on top of this mess if it keeps changing out
from under their feet*?

The correct (albeit ugly) solution is to introduce either a new
function call entirely (get_the_filtered_title), or add a defaulting
parameter to the current call (get_the_title($pid, $filter=false)), or
both (with a latter being a shortcut to the former, but defaulting to
true for the filter instead). Yes, it adds bloat. Yes, it's not pretty.
That's why -public APIs need to be designed and documented
thoroughly- -- so that implementers know exactly how the function
should behave, testers know exactly how to verify the correct
operation of the function, and (ultimately) programmers know how they
can rely on the thing to work (and know if they're relying on a bug
vs. intended behavior).

--
Travis

* The question is rhetorical, of course, but the answer is that
developers need to write their own compatibility/stability/
abstraction layer. That's what I've done to handle other
breaking changes between versions, but it's very obnoxious to have to
do, since that's what a public API is supposed to provide in the first
place.


More information about the wp-testers mailing list