Home>Support>Custom So Widget only partially working (2 issues)

Custom So Widget only partially working (2 issues)

By julian, 5 years ago. Last reply by Andrew Misplon, 5 years ago.

I followed the Create Widget page (would be nice if this had a complete source to go with it) – and have a widget that sort of works.
Two environments
1. Local – basic WP with TwentySeventeen theme + Plugins (these are the only active plugins)
Page Builder by SiteOrigin
SiteOrigin Widgets Bundle
My Custom Widget Plugin
2. Sever – Weaver Xtreme Theme – all the above plugins plus several more.
Local Issue
Local server: Widget shows in the Page builder. I can add it to a layout and it works perfectly – I can fill in the various data items – save and the values are retained.
However, when the page is opened nothing is displayed. I have put debug statements in the code for the get_template_name() and get_template_dir() – both of which get output. In the dump I output both the name / dir and do a print_r of the $instance – in both cases correct name and dir output and the Instance shows all the data captured in the widget.

The template does not render and debug statements placed in the template file do not show in the log.
In the generated page it appears the container for the widget is being created

<div class="so-widget-my-custom-widget so-widget-my-custom-widget-default-d75171398898"></div>

But the container is empty.

Live Server
Plugin does not install – even if I copy folder manually – does not show up in plugins page. If I do an upload – white screen of death – refresh shows the Plugin is installed – but there is no folder in plugins for it and (obviously) it does not show in widgets.

Plugin implementation
I have put the widget definition directly into the Plugin file (rather than registering a widget folder – earlier attempts with this did not work and with no sample to follow I decided to fall back to a simpler implementation).

/**
 * Plugin Name:   My Custom Widget
 * Plugin URI:    ***************
 * Description:   My Custom Widget
 * Version:       1.0
 * Author:        Julian Hansen
 * Author URI:    ***************
 */
class My_Custom_Widget extends SiteOrigin_Widget {
    function __construct() {
        parent::__construct(
           // as per create widget page and form fields page    
        )
    }
    function get_template_name($instance) {
        // Debug here - file_put_contents('trace.log', ....);    
        return 'default';
    }
    function get_template_dir($instance) {
        // Debug here - file_put_contents('trace.log', ....);    
        return plugin_dir_path(__FILE__) . 'tpl';
    }
}    
siteorigin_widget_register('lsow-clients', __FILE__, 'My_Custom_Widget');

Directory structure
my-custom-widget
  my-custom-widget.php
  tpl
     default.php

default.php
<?php
  // Debug here - file_put_contents('trace.log', ....);    
?>
<div>My Custom widget</div>

Any ideas

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

  1. 5 years, 5 months ago julian

    I have managed to solve issue 1 – I had a typo in the id of siteorigin_widget_register so the widget was not being found.

    The second problem has not been resolved – why the plugin is not working on the live site. Just does not show up in the plugins list despite being in the plugins folder

  2. 5 years, 5 months ago julian

    Issue two solved – problem was the live site was broken – was not allowing any plugins to register – refreshed site from backup and now plugin loads fine and is rendering.

  3. 5 years, 5 months ago Andrew Misplon
    Hi, I Work Here

    Hi Julian

    Super, glad to hear you were able to locate the problems and troubleshoot your way through. Thanks for keeping us up to date :) All the best with your project.

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