• Resolved palychwp

    (@palychwp)


    Custom widget won’t activate. I folowed your guide but widget doesn’t work. I activated it but after page reload it’s disabled again and I can’t use it.

    I created plugin

    <?php
    /*
    Plugin Name: My Extended Widgets
    Description: Custom Widgets.
    Version: 0.1
    */
    function add_my_awesome_widgets_collection($folders){
        $folders[] = __DIR__ . '/widgets';
        return $folders;
    }
    add_filter('siteorigin_widgets_widget_folders', 'add_my_awesome_widgets_collection');

    and widget:

    <?php
    /*
    Widget Name: First Test Widget!!
    Description: An example widget.
    Author: Me
    */
    
    class My_First_Test_Widget extends SiteOrigin_Widget {
    
        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.
                'my-first-test-widget',
    
                // The name of the widget for display purposes.
                __('First Test Widget', 'hello-world-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.', 'hello-world-widget-text-domain'),
                    'help'        => 'https://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.
                plugin_dir_path(__FILE__)
            );
        }
    
        function get_template_name($instance) {
            return 'first-widget-template';
        }
    
        function get_template_dir($instance) {
            return 'templates';
        }
    
        function get_style_name($instance) {
            return '';
        }
    
    }
    
    siteorigin_widget_register('my-first-test-widget', __FILE__, 'My_First_Test_Widget');

    This is my directory structure : https://prnt.sc/hzf0fg

    • This topic was modified 6 years, 10 months ago by palychwp.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor alexgso

    (@alexgso)

    Hi palychwp,

    Based on your screenshot and code, the issue is your widgets directory. Specifically, it’s not widgets directory, it’s literally a widget. You need to move the contents of the widgets directory into a directory specific to that widget so SiteOrigin Page Builder can reliability pick up on.

    For reference, here’s a screenshot from the linked document with the correct structure.

    Thread Starter palychwp

    (@palychwp)

    Hi alexgso

    I have changed directory structure: https://prntscr.com/i1n6qt
    My plugin file extend-widgets-bundle.php code:

    <?php
    /*
    Plugin Name: My Extended Widgets
    Description: Custom Widgets.
    Version: 0.1
    */
    function add_my_awesome_widgets_collection($folders){
        $folders[] = __DIR__ . '/extra-widgets';
        return $folders;
    }
    add_filter('siteorigin_widgets_widget_folders', 'add_my_awesome_widgets_collection');

    Widget isn’t displaying in the list of widgets now.

    I’m confused. Can I download sample of custom widget anywhere?

    Plugin Contributor alexgso

    (@alexgso)

    Hi palychwp,

    You can find example widgets here.

    Would it be possible for you to send me a complete copy of your plugin so I can inspect your setup more closely?

    Thread Starter palychwp

    (@palychwp)

    Thanks alexgso!

    This demos works perfectly.
    Thanks for help!

    Plugin Contributor alexgso

    (@alexgso)

    Hi palychwp,

    Did you manage to get your widget working? If so, do you still need assistance with this issue?

    Thread Starter palychwp

    (@palychwp)

    I created my widget based on this demo. It’s working now.

    Thanks a lot.

    Plugin Contributor alexgso

    (@alexgso)

    Hi palychwp,

    Okay cool. I’m marking this thread as resolved.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom widget doesn’t activate.’ is closed to new replies.