This entry is part 2 of 9 in the Plugin Thoughts Series
- Plugin Thoughts Episode 1: Making Your Plugins More Extensible
- Plugin Thoughts Episode Two – Use Filters for Plugin Text
- Plugin Thoughts Episode 3 – Don’t Forget About Core Functions
- Plugin Thoughts Episode 4 – Learn How Core Does It
- Plugin Thoughts Episode 5 – Take Responsibility for Your Products
- Plugin Thoughts Episode 6 – Contribute to the WordPress Codex
- Plugin Thoughts Episode 7 – Remember Core CSS
- Plugin Thoughts Episode 8 – Create Clean Code
- Plugin Thoughts Episode 9 – Write Better Code; Release Better Plugins
In episode two of Plugin Thoughts, I talk about how and why to use filter hooks in your plugins to make it easy for your users and other developers to change text in your plugins.
Hi Pippin. I just signed up, cool tutorials you have there. I’m not sure if we need to use filter in such case. Why can’t we use the main localization file to provide another text? We’re not translating the plugin doing this, but I think it’s ok. Curious to hear your thoughts.
I’ve heard both sides and personally feel it is better to provide both. Let’s say that a user using your plugin in the same language it was written in wants to change the text, it is much easier for them to change it via a filter than it is by translating the MO files, especially since they may only need to change that one line. If a user is using the plugin not in the language it was written, then they can translate the entire plugin AND change the text at the same time.
I see.
I would just open the file ( en_US.po ) using PoEdit and “translate” Register New Account into “Membership Application”. It’s not a translation, but it seems to work ๐
Do you think it’s wrong if the user doesn’t want to translate a plugin, but just needs to modify the text using MO file? Is it ok to use MO files for something other than translations?
I don’t know that either way is necessarily right or wrong, but they both definitely work.
Cool. Just wanted to know your opinion. Thanks ๐
In your example, you have a parameter called $header – where does that come from? I think it’s something that always confuses me with filters. I couldn’t see a $header in member-forms.php either. Would it have worked without the $header?
$header comes from where the original filter was setup. In this case, Restrict Content Pro (the plugin being used as a demo), does this:
The first parameter in apply_filters() is the name of the filter and the second is the value passed to the filter ($header). So $header is this:
Note that the name of the parameter can be anything. I used $header simply because it made logical sense, but you could have just as easily used $text.
Make sense?
Thank you very much for that article ,
Just I donโt know why my `apply filter` broke the code
I have a custom home page `home.php`
Iโm trying to do
$the_content = get_the_content();
apply_filter(‘the_content’,$the_content);
the page stop loading after that point of code
Just I need a key so I can start solve that problem, Thanks in advanced
Looks like your single quotes are not plain quotes. Try rewriting it by hand, instead of copying and pasting.
Hi , Pippin ….Sorry but video cant load……there is a just blank space…:(
Fixed!
Thanks buddy for quick answer and fixing :))