Hello, fellow WordPress Users and Developers!
I have created a plugin, which allows one to create widgets out of other plugins for which the authors offer only raw PHP function hooks.
For example, the famous Popularity Contest plugin by Alex King can now be used without editing your theme files.
Custom Function Widgets plugin doesn’t use the PHP
evalfunction, which means you will never get
function not founderrors, even if you disable the plugin which provides the function hook.
View screenshots and the list of features at this blog post:
Custom Function Widgets
Would this work differently that Otto’s plugin?
Michael, yes it works differently than Otto’s plugin, because of the following reasons:
- Custom Function Widgets (CFW) plugin doesn’t use PHP
evalfunction, but rather
call_user_func_array. More importantly, the name of the function is being verified by
is_callable. This makes CFW much safer, and also potentially available to WordPress MU users, as the owners/admins of the MU installation most likely wouldn’t prefer any PHP executed by the users, but at the same time may find the
- If the function becomes unavailable (source plugin disabled or incorrect function name), the CF Widget will simply not be displayed, instead of various error message you would typically get when writing raw
PHPinside a widget.
- CFW gives you the option to remove default widget wrapper, including title (set in
functions.php), which might be useful for displaying content which shouldn’t resemble the typical look of a widget.
I think that these are serious improvements over the available plugins that enable similar functionality. What do you think?
It’s an interesting idea, however the use is somewhat limited. Might be more useful for MU users. However, it’s not entirely ‘safe’ by any stretch of the imagination. call_user_func_array can be exploited too. Not as simply as eval, I admit, but still…
On the whole, I think it would be better to encourage plugin authors to actually write widgets into their plugins. Perhaps giving them a simple widget code template that they can easily plug into their plugins would be a good idea.
Understand that I don’t like the ExecPHP widget either, and I’m the one who wrote it in the first place. I think too many lazy plugin authors refer to it when telling their users how to put bits in the sidebar.
CFW gives you the option to remove default widget wrapper, including title (set in functions.php), which might be useful for displaying content which shouldn’t resemble the typical look of a widget.
I hate, hate, hate it when widgets allow this sort of thing. It defeats the whole point of the separation of content and presentation. The “look” should be controlled by the theme and by the theme alone. Not by the widget itself. If you want a specific widget to look different, then use styling to make it look different. All widgets should have unique identifiers for them if the theme is written correctly.
Otto, thank you for your insight. I didn’t mean to imply that that there is something wrong with your work, as I was only trying to detail my reasons for writing this plugin instead of using any of the existing solutions. Sorry if it did sound that way.
I completely agree with you that plugin authors are doing wrong by not supplying widget output, but nobody can’t blame them, because it is the nature of open source — you either use it, improve it or create your own.
At the same time it is obvious that plugin authors would make the world of WordPress a better place by taking that extra hour to actually create widgets for their plugin (if applicable, of course), instead of asking users to install an extra plugin.
Taking your suggestion, I will definitely try to write a tutorial for the plugin authors to explain how easy it is to add a widget, and will provide a few templates as well.
For me the confusing part while writing this (my first) plugin was when to use the
add_actionhooks. It took me days to figure out how to pass additional variables to the function defined at
register_sidebar_widgetwithout making an extra call to
Now, regarding the “limitations” of this idea — to use only one function call and not allow PHP execution.
- I think that the function hooks provided by the plugin authors should never require users to supply variables derived from the WordPress core (like
$post->ID), as they all are available to the plugin itself. Moreover,
$post->IDis not even available outside the post loop, which makes it more complicated for an average user. It would be much better to ask the user for a simple argument, like
$whichpost = 'this', or
$whichpost = 'next'. The plugin should do the work of finding which post ID it is that the user wants.
- It is hard for me to image a situation when the plugin would need multiple function calls to generate the output for a widget, if written correctly. In fact, it depends only on the number of variables that the widget has to consider to generate the desired output. In WordPress, all the dynamic information is available to plugins. Information required from the user is really very minimal.
Therefore, I think that the functionality of CFW plugin is not limited if the function hooks of the plugin it uses have been written with flexibility and usability in mind.
Finally, I would like to explain why the option to turn off widget wrapper is valid and sound from the perspective of presentation (theme) authors and content creators (widget authors). It is important to note that this options is turned off by default, and that there are in fact two options: (1) to turn off only the title, and (2) to turn off the title and the wrapper.
It is assumed that people wouldn’t normally want to do it (therefore the defaults), but in special cases it might useful. Widgets can be used outside the sidebars, if the theme allows, and it probable that such an option may be required for more advances users/websites, while the average users may simply ignore it.
It doesn’t break the theme by default and it behaves just like the author of the theme has intended for a widget to behave. That is the most important thing.
- Custom Function Widgets (CFW) plugin doesn’t use PHP
- The topic ‘New Plugin: Custom Function Widgets’ is closed to new replies.