KC Widget Enhancements

Posted on 2011/04/06 Comments

As I promised when I wrote the functions for adding custom classes for WordPress widgets, I’m now announcing the release of KC Widget Enhancements. This plugin provides the ability to set custom classes and ID for any widgets, not just the built-in ones, but also widgets that comes with installed plugins/themes.

Update:
This plugin is now hosted at WordPress plugin repo so you can install it directly from the admin dashboard.

Currently there are three components, but I designed this plugin to be extendable so it should be easy to add more in the future:

  • Custom widget ID
  • Custom widget classes
  • Enable shortcode on text widgets

If you have idea on how to enhance the widgets even more, please don’t hesitate to leave a comment below. I may add them in the next versions.

To get the most of this plugin, I highly suggest the use of KC Settings together with this plugin so you can enable/disable the components easily. Or if you prefer to do it the geeky way, please read FAQ section in the readme.txt file.

You can download this plugin from here or clone/fork it from github. I’ll update this post when it’s available on WordPress’ plugins repo.

Notes:
As reported by Ed Nailor, the custom ID/classes won’t get printed if you’re using Widget Logic plugin, because it overrides the default callback for each widget.

Comments

  1. small error notice:

    Notice: Trying to get property of non-object in /var/www/vhosts/elektrickeauto.cz/httpdocs/wp-content/plugins/kc-widget-enhancements/custom_id_classes.php on line 58

    please always test your plugins with wp_debug enabled

    • Thanks for using the plugin Tomáš.
      Well, my local WordPress installs always have WP_DEBUG set to true, and I haven’t seen that notice before. Which widget did you see this error came from?

      • Oh i see a problem – it is probably somehow conflicting with widget logic plugin. It shows this notice on any widget with this plugin enabled.
        row 58 in your custom_id_classes.php is
        $widget_opt = get_option($widget_obj['callback'][0]->option_name);
        but with widget logic $widget_obj['callback'] variable contains
        [callback] => widget_logic_redirected_callback

  2. btw IMO it would be great, if you would make the fields in widget hidden by default – e.g. add an ‘Advanced’ link to Close | Delete at the widget bottom, and show the field after clicking the widget.

    Also it would be great, if you would create some own filters/actions, so if i would like some other behaviour, i could overwrite them, without need to create copy of your plugin. E.g. i would like to replace classes, not adding them. (or maybe some option, e.g. with “+” at the beggining of the field

    P.S.: great would be an integration of functionality of Widget Logic plugin. That would be completely Holy Grail of WP Widgets

    • That’s a great idea. I think I could make another option to hide the fields by default and add a link to open it.

      There are already two filters currently, kcwe_sanitize_custom_id and kcwe_sanitize_custom_classes, and you can use them to filter the custom ID and classes. I will add more info in the readme file about this.

      Replacing classes could be done, but IMO, it won’t make a big difference, since you can just ignore the other classes and not create a rule for them in your stylesheet. Or maybe you want to get simpler markup? :)

      I still have an old working version of this plugin that has Widget Logic’s functionality built-in. However, since it’s using the evil eval (just like Widget Logic), I don’t feel comfortable using it, let alone releasing it to the public. I’m still looking for the best approach to handle the logic without using eval.

      • yes, i just want cleaner code (i do not want to show wordpress markup), but i understand that this is just my deviation ;-) so i can live with your filters, sorry i missed them.

        About the eval – good point. On the other hand, only admins can change the widgets (or it should be so). And they have many other ways how to destroy the server then by eval.

        I do not know if there are some way how to do it without eval, i will ask my programmers.

        I understand if you do not want to put it to your plugin. I just wondered it would be nice, that those advanced features would be under one Advanced settings.

        • Yup, I realized that widget logic functionality is really needed, and I already have an idea on how to implement it without using eval. However, since WordPress conditional tags is little complex, it will take some time before I integrate it into the plugin :)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>