Home>Support>Custom Widgets

Custom Widgets

Hi, I am very confused. Trying to implement my own set of widgets and do not really have much WP knowledge, so please help:

https://siteorigin.com/docs/widgets-bundle/getting-started/creating-a-widget/

So I registered the widget copying this code into my functions.php file of my theme:

<?php
function add_my_awesome_widgets_collection($folders){
$folders[] = 'widgets/';
return $folders;
}
add_filter('siteorigin_widgets_widget_folders', 'add_my_awesome_widgets_collection');
?>

I created a widgets folder inside my theme’s directory, along with a subfolder with the name of accordion-widget, storing accordion-widget.php inside of it. Then I used this inside accordion-widget.php

<?php

/*
Widget Name: Hello world widget
Description: An example widget which displays 'Hello world!'.
Author: Me
Author URI: http://example.com
Widget URI: http://example.com/hello-world-widget-docs,
Video URI: http://example.com/hello-world-widget-video
*/

class Accordion extends SiteOrigin_Widget {

function get_template_name($instance) {
return 'default';
}

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

siteorigin_widget_register('accordion', __FILE__, 'Accordion');
?>

I also created a folder named tpl and stored default.php which is empty for now inside of it, in the same folder that accordion-widget.php is stored. Now in the post, it says that as soon you add this code, the widget will appear in the Plugins > SiteOrigin Widgets list, but it doesn’t. Any idea what I might be doing wrong?

UPDATE

Never mind, solved it!

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

====================================================

NEW ISSUE!

But now after copying this code in the accordion-widget.php file:

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.
'accordion_widget',

// The name of the widget for display purposes.
__('Accordion widget', 'accordion-widget-text-domain'),

// 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' => __('A hello world widget.', 'accordion-widget-text-domain'),
'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.', 'siteorigin-widgets'),
'default' => 'Hello world!'
),
),

//The $base_folder path string.
get_template_directory()
);
}

I get this error in my post editor in the admin panel
Warning: Missing argument 1 for SiteOrigin_Widget::__construct(), called in /home/*********/public_html/wp-includes/widgets.php on line 591 and defined in /home/*********/public_html/wp-content/plugins/so-widgets-bundle/base/siteorigin-widget.class.php on line 47

Warning: Missing argument 2 for SiteOrigin_Widget::__construct(), called in /home/*********/public_html/wp-includes/widgets.php on line 591 and defined in /home/*********/public_html/wp-content/plugins/so-widgets-bundle/base/siteorigin-widget.class.php on line 47

Which I am pretty sure has to do something with this line:

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

What should I do with this line? How can I approach this in a way that I can setup my new widget through the theme instead of creating a new plugin? Thank you!

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, 1 month ago Andrew Misplon
    Hi, I Work Here

    Hi Meysam

    Unfortunately, this isn’t possible without a fair amount of custom coding. This is beyond the scope of what we can help you with on the forums, but you could hire a developer to implement this for you.

    We highly recommend using https://codeable.io/.

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