/**
 * Get the base path URL of a widget plugin.
 *
 * @param $id
 * @return string
 */
function siteorigin_widget_get_plugin_dir_url($id)
{
    return SiteOrigin_Widgets_Widget_Manager::single()->get_plugin_dir_url($id);
}
 /**
  * Activate a widget
  *
  * @param string $widget_id The ID of the widget that we're activating.
  * @param bool $include Should we include the widget, to make it available in the current request.
  *
  * @return bool
  */
 function activate_widget($widget_id, $include = true)
 {
     $exists = false;
     foreach ($this->widget_folders as $folder) {
         if (!file_exists($folder . $widget_id . '/' . $widget_id . '.php')) {
             continue;
         }
         $exists = true;
     }
     if (!$exists) {
         return false;
     }
     // There are times when we activate several widgets at once, so clear the cache.
     wp_cache_delete('siteorigin_widgets_active', 'options');
     $active_widgets = $this->get_active_widgets();
     $active_widgets[$widget_id] = true;
     update_option('siteorigin_widgets_active', $active_widgets);
     // If we don't want to include the widget files, then our job here is done.
     if (!$include) {
         return;
     }
     // Now, lets actually include the files
     include_once ABSPATH . 'wp-admin/includes/plugin.php';
     foreach ($this->widget_folders as $folder) {
         if (!file_exists($folder . $widget_id . '/' . $widget_id . '.php')) {
             continue;
         }
         include_once $folder . $widget_id . '/' . $widget_id . '.php';
         if (has_action('widgets_init')) {
             SiteOrigin_Widgets_Widget_Manager::single()->widgets_init();
         }
     }
     return true;
 }
 /**
  * Get instances of all the widgets. Even ones that are not active.
  */
 private function get_widget_objects()
 {
     $folders = $this->get_widget_folders();
     $widgets = array();
     $manager = SiteOrigin_Widgets_Widget_Manager::single();
     foreach ($folders as $folder) {
         $files = glob($folder . '*/*.php');
         foreach ($files as $file) {
             include_once $file;
             $widget_class = $manager->get_class_from_path($file);
             if ($widget_class && class_exists($widget_class)) {
                 $widgets[$file] = new $widget_class();
             }
         }
     }
     return $widgets;
 }