Home>Support>Custom widget does not appear

Custom widget does not appear

Notice: This thread is over two years old; the information may be outdated. Please consider creating a new thread if you require free support. If you have an active SiteOrigin Premium license, you can email our premium support desk at [email protected].

Hi!

I want to create a series of widgets and am following your tutorial Creating a widget.
AFAIK I’ve done each step correctly but the widget does not appear on Plugins > SiteOrigin Widgets. What am I doing wrong?

– I’ve checked the content of $folders after I specify the location of my widgets folder, and the path is correct.

Here is the folder structure

Here is my Widgets code. Can you tell me what I am doing wrong?
Thank you!!

<?php
/*
Widget Name: customer Vignette
 */

class Customer_Vignette_Widget extends SiteOrigin_Widget {

	function get_template_name($instance) {
		return 'customer-vignette-template';
	}

	function get_style_name($instance) {
		return '';
	}


	function __construct() {
		//Here you can do any preparation required before calling the parent constructor, such as including additional files or initializing variables.

		//Call the parent constructor with the required arguments.
		parent::__construct(
			// The unique id for your widget.
			'customer-vignette-widget',

			// The name of the widget for display purposes.
			'customer Vignette Widget',

			// The $widget_options array, which is passed through to WP_Widget.
			// It has a couple of extras like the optional help URL, which should link to your sites help or support page.
			array(
				'description' => 'Ajouter un lien de type "vignette" vers un article et configurez son affichage.',
				'help'        => 'http://example.com/hello-world-widget-docs',
			),

			//The $control_options array, which is passed through to WP_Widget
			array(
			),

			//The $form_options array, which describes the form fields used to configure SiteOrigin widgets. We'll explain these in more detail later.
			array(
				'text' => array(
					'type' => 'text',
					'label' => 'Hello world! goes here.',
					'default' => 'Hello world!'
				),
			),

			//The $base_folder path string.
			plugin_dir_path(__FILE__)
		);
	}
}

siteorigin_widget_register('customer-vignette-widget', __FILE__, 'Customer_Vignette_Widget');

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 9 years, 5 months ago Greg Priday
    Hi, I Work Here

    Hi Alexandre

    Glad to hear you’re developing on top of the SiteOrigin Widgets Bundle. Your actual widget code looks fine, but the problem might be where you’re registering the widgets folder. Do you perhaps have your code on somewhere like Github? If you do, I’ll take a look and see if I can figure anything out.

  2. 9 years, 5 months ago Alexandre Plennevaux

    Hi Greg,

    … and loving it!
    I was trying to include my widgets via my theme’s functions.php file. At some point I found your example git repository and realized I had to actually make a plugin.

    My current setup is actually hybrid: I plan to make my theme rely on SO Page Builder so have bundled it (using http://tgmpluginactivation.com ); I created a “customer widgets” plugin with the siteorigin_widgets_widget_folders filter call, which register a custom “widgets/” folder hosting the widgets code sits inside my theme directory structure.

    so: my plugin

    /*
    Plugin Name: Custom Widgets Bundle Plugin
    Description: Widgets for [customername] based on SiteOrigin Widgets Bundle.
    */
    function add_customer_widgets_collection($folders){
    	$folders[] = dirname(__FILE__).'/../../themes/customer-v2/widgets/';
    	return $folders;
    }
    add_filter('siteorigin_widgets_widget_folders', 'add_customer_widgets_collection');
    
    

    It is weird, because if I called it inside my themes function.php file changing one line:

    $folders[] = get_template_directory() . '/widgets/';
    

    , it wouldn’t find the widgets. It seemed to me WP allows requiring plugins inside the themes folder (although it is not considered good practice). There might be something with the filter that prevents it (maybe declared after execution of functions.php ?).

    Anyways, thanks for getting back to me :-)

  3. 9 years, 5 months ago Greg Priday
    Hi, I Work Here

    I seem to remember that there’s a little snag with adding custom widgets inside a theme. I’ll look into this again, but for now, would it be possible for you to keep these widgets stored in a plugin instead?

    It’s a much better idea to keep this sort of functionality in plugins anyway.

  4. 9 years, 5 months ago Alexandre Plennevaux

    sure, that's what I did eventually. It makes sense. I've contributed a small bit to the documentation in this regard.
    https://github.com/pixeline/docs/commit/51ad2604013edc1eb404f04335df0e7ffaac1fb9

  5. 9 years, 5 months ago Greg Priday
    Hi, I Work Here

    Thanks for the docs contribution! I’ll check over it and merge when I’m next doing some documentation work.

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More