[wp-hackers] Useless Filter

Nathan Rice ncrice at gmail.com
Tue Feb 17 17:07:08 GMT 2009


So last night I was trying to build a plugin when I ran across this code in
http://svn.automattic.com/wordpress/trunk/wp-includes/classes.php

$output .= $indent . '<li class="' . $css_class . '"><a href="' .
get_page_link($page->ID) . '" title="' .
attribute_escape(apply_filters('the_title', $page->post_title)) . '">' .
$link_before . apply_filters('the_title', $page->post_title) . $link_after .
'</a>';
As you can see, the title is generated using the $page->post_title object.
 But since the the_title filter doesn't have any way of passing the
$page->post_title into a filter, this filter ends up being useless.  At
best, you can use a function to output something, but since it doesn't have
a way to pass a variable into the filter function, the result is EXACTLY the
same no matter where the the_title filter is used (which is pretty much
everywhere a post/page title is called).

Ideally, I could pass $title and $id into my filter function.  But better
yet, use a separate function (like the get_page_link function).  Like so:

$title = $page->post_title;
$id = $page->ID;
$use = 'Walker_Page';
$output .= $indent . '<li class="' . $css_class . '"><a href="' .
get_page_link($page->ID) . '" title="' .
attribute_escape(apply_filters('the_title', $title, $id, $use)) . '">' .
$link_before . apply_filters('the_title', $title, $id, $use) . $link_after .
'</a>';

The plugin I was trying to create would allow you to set a custom field in a
page that let you specify a different title for a page when it's outputted
by wp_list_pages.

Am I missing something, or am I right in thinking that the use of this
filter here is completely non-existent?

My Website
http://www.nathanrice.net/

My Twitter
http://twitter.com/nathanrice


More information about the wp-hackers mailing list