latest version

Bee Widgets

Bee Widgets extension allows for easy widget creation by converting an existing shortcodes to widgets. It’s an easier and usually cleaner way than creating a widget from scratch.

Note

Bee Widget extension is automatically enabled when Theme Plugin is active.

Create sample widget

Let’s create a Theme socials widget based on ct_socials shortcode. In order to add a widget to the theme, create the following file in Theme Plugin structure: wp-content/plugins/theme-plugin/extensions/bee-widgets/includes/class-bee-widget-ct-socials.php

Important

There should be ct_socials shortcode defined in theme plugin already in the example path: wp-content\plugins\theme-plugin\extensions\shortcodes\shortcodes\ct-socials

Note

The name of the file should be class-bee-widget-widgetname.php. Thus it will be autoincluded and autoregistered.

class-bee-widget-ct-socials.php content:

<?php

/** Widget extending Bee Widget class */
class Bee_Widget_Ct_Socials extends Bee_Widget
{
    /**
     * Set the name of a shortcode which will be converted to widget
     * Throws an exception if specified shortcode not found
     * @return string
     */
    protected function get_bee_shortcode_name() {
        return 'ct_socials';
    }

    /**
     * Set desired widget name
     * @return string
     */
    protected function get_bee_widget_name() {
        return 'Theme socials';
    }

    /**
     * Set desired widget description
     * @return string
     */
    protected function get_bee_widget_description() {
        return 'Theme socials description';
    }

}

/** Widget will be autoregistered if put in proper file and location.
  * Otherwise, you can manually register the widget in WordPress with the code below:

    Bee_Widget_Ct_Socials::init_register();

**/

Note

Methods get_bee_widget_name and get_bee_widget_description are optional to overwrite.

That’s all! The widget should now be available in wp-admin

Hooks

Besides methods above, there are also filters:

  • bee_widget_options which allows you to change widget options,
  • fw_ext_bee_widgets_paths which allows you to look for widgets in custom locations
  • fw_ext_visual_composer_map_skip_shortcodes which allows you to hide shortcodes/widgets from VC editor

which is useful when designing a shortcode for widget context only. For more information, see Visual Composer Integration

Option dependency

Option dependency can be used in the same way as in shortcodes. Currently supported option types are most simple inputs including: text, select, radio, checkbox.