[wp-hackers] Hooks, Actions, Filters
Jeremy Visser
jeremy at visser.name
Wed Jul 29 10:20:42 UTC 2009
On Wed, 2009-07-29 at 08:38 +0200, Bruno Alexandre wrote:
> the idea is to override the get_title() method in order to erase the
> "Protected: " sentence from the title if the page is protected, there is a
> protected_title_format filter, and I thought using it ...
> $protected_title_format = apply_filters('protected_title_format',
> __('Protected: %s'));
What you need is something like this:
function remove_protected_title_format($s) {
return str_replace('Protected: ', '', $s);
}
add_filter('protected_title_format',
'remove_protected_title_format');
To help you understand it, look at the original code:
$protected_title_format =
apply_filters('protected_title_format', __('Protected: %s'));
So the string is *starting out* as 'Protected: %s'. We can't change
that, because that is what is fed into the filter. However, we can
change it after it has been fed into the filter. So...
[Start] $protected_title_format = 'Protected: %s'
[Apply filters] call remove_protected_title_format()
-- strips out 'Protected: ' of variable
[Finish] $protected_title_format = '%s'
And that is what gets ultimately assigned to the variable.
Hope this helps,
Jeremy.
More information about the wp-hackers
mailing list