Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a load of custom widgets that all look pretty much the same. I have a multisite blog with 3 blogs. The widgets are configured individually to show up on all 3 blogs with their own settings in Appearance -> Widgets.

All widgets show normally on the first, main blog. On the other blogs, some of the widgets don't appear. I've given a sample of two widgets below - gem_countryFilter_Widget() shows up everywhere like it should, but gem_joinConversation_Widget() only appears on the main blog, even though it's configured on all of them and is part of the same sidebar as the other widget that does work. I can't see any difference between the two, so I'm baffled as to what the problem is.

The widgets are also used in a previous custom theme, and have not been modified. In the previous theme, the widgets appeared on all blogs as expected. I've tried copying the functions.php file (where the widgets are declared) from the old theme directly into the new one and it's had no effect - some of the widgets just disappear on the non-main blogs.

It seems logical that the theme is the problem, but I'm drawing a blank over where to look to diagnose it. Has anybody encountered a similar problem before?

sample code:

/**join conversation**/
class gem_joinConversation_Widget extends WP_Widget {
    function gem_joinConversation_Widget() {
        parent::WP_Widget(false, 'Join the Conversation');
    }
function form($instance) {
        // outputs the options form on admin
        echo '<p>Displays the social and sharing icons in the sidebar. There are no options for this widget.</p>';
    }
function update($new_instance, $old_instance) {
        // processes widget options to be saved
        return $new_instance;
    }
function widget($args, $instance) {
        // outputs the content of the widget
        gem_joinConversation();
    }
}
register_widget('gem_joinConversation_Widget');
function gem_joinConversation($args = array()){
    ?>
    <ul class="featurebox">
        <li>
            <div class="widget text-3">
                <h2>Join the conversation</h2>
                <div class="body">
                    <div class="textwidget">
                        <div class="social-icons">
                            <a href="/" target="_blank"><img width="27" height="27" src="/wp-content/themes/gem_main/images/icon-gem.png" alt="Corporate"/></a>
                            <a href="/" target="_blank"><img width="27" height="27" src="/wp-content/themes/gem_main/images/icon-facebook.gif" alt="Facebook"/></a>
                        </div>
                    </div>
                </div>
            </div>
        </li>
    </ul>           
    <?php
}

/**Country filter**/
class gem_countryFilter_Widget extends WP_Widget {
    function gem_countryFilter_Widget() {
        parent::WP_Widget(false, 'Country filter');
    }
function form($instance) {
        // outputs the options form on admin
        echo '<p>Displays a dropdown list of blogs. There are no options for this widget.</p>';
    }
function update($new_instance, $old_instance) {
        // processes widget options to be saved
        return $new_instance;
    }
function widget($args, $instance) {
        // outputs the content of the widget
        gem_countryFilter();
    }
}
register_widget('gem_countryFilter_Widget');
function gem_countryFilter($args = array()){
    ?>
    <ul class="country-filter">
        <li>
            <h2>Filter by country</h2>
            <ul class="country-filter-list">
                <li><a href="#" class="country-brazil">Brazil</a></li>          
                <li><a href="#" class="country-china">China</a></li>
                <li><a href="#" class="country-france">France</a></li>
            </ul>
        </li>
    </ul>       
    <?php
}
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

I got a Tumbleweed badge for this :(

FWIW I eventually "fixed" this by restoring the database from backup and recreating the theme files afresh with a new theme name and directory. It seems like a lot more effort than it should be. I figure there was some kind of weird database corruption / conflict somewhere that made it impossible to use widgets that had been used and then removed from the sidebar before being put back.

I could not find a code-based solution, and clearing out references to widgets from the database manually had no effect. I am now terrified of removing and replacing widgets. :/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.