简体   繁体   English

WordPress主题调试:插件侧边栏导致原始侧边栏不显示

[英]Wordpress Theme Debug: Plugin sidebar causes original sidebar not to display

I have determined that my plugin code works perfectly fine in other themes, but in the theme: Magazinly, the sidebar plugin I wrote, causes the sidebar not to display. 我确定我的插件代码可以在其他主题中正常运行,但是在主题中:我写的侧边栏插件Magazinly导致侧边栏不显示。 Through debugging, I've determined that the sidebars register, and two sidebar arrays are created, but one is not populated. 通过调试,我确定了侧边栏寄存器,并且创建了两个侧边栏数组,但未填充其中一个。

Here is the plugin code: 这是插件代码:

register_sidebar(array(
        'name'=>'Bottom Widget Area',
        'id'=> 'bottom-widget',
        'before_widget' => '<aside class="widget %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<div class="block-title"><span>',
        'after_title' => '</span></div>'
    ));

include 'add_bottom_bar.php';

This is add_bottom_bar.php: 这是add_bottom_bar.php:

    // Register Bottom_Bar
function add_bottom_widget(){

    echo '<div class=\'bottombar\'>';
    if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('bottom-widget')) : 
        endif;
    echo '</div>'; 
}

 add_action ('get_footer', 'add_bottom_widget');


// Register style sheet.
add_action( 'wp_enqueue_scripts', 'register_plugin_styles' );


// Register style sheet.
function register_plugin_styles() {
    wp_register_style( 'custom_widget_final', plugins_url( 'custom_widget_final/css/bottom_bar.css' ) );
    wp_enqueue_style( 'custom_widget_final' );
}

And here is the code for the sidebar in Magazinly: 这是Magazinly中侧边栏的代码:

http://pastebin.com/eJu7Wk3C http://pastebin.com/eJu7Wk3C

There's also this code that appears to use whatever this thing the theme creator called 'dinamic sidebar' to... well... I would imagine... render dynamic sidebars : 还有这个代码似乎使用了主题创建者称为“ dinical sidebar”的任何东西来...好吧...我想...渲染动态边栏:

http://pastebin.com/T0LW3QTS http://pastebin.com/T0LW3QTS

But, my guess is that this is the culprit: The Magazinly theme uses this sidebar loader, but it seems like serious overkill. 但是,我的猜测是是罪魁祸首:《 Magazinly》主题使用此侧边栏加载程序,但似乎严重过头了。 I am guessing that the sidebar widget I'm registering, is disrupting this sidebar loader. 我猜我正在注册的侧边栏小部件正在破坏此侧边栏加载器。

http://pastebin.com/jCtvjVqC http://pastebin.com/jCtvjVqC

With all code presented, my next question is: what are my options? 显示所有代码后,我的下一个问题是:我有什么选择? I need to add widget positions to three sites, all using the same theme, but preserve the sidebar. 我需要将窗口小部件位置添加到三个站点,所有站点都使用相同的主题,但保留侧边栏。 Presently, if I activate my plugin, the sidebar won't load, but the plugin works. 目前,如果我激活插件,则侧栏将不会加载,但是该插件可以工作。 If I deactivate the plugin, the sidebar returns. 如果我停用插件,则侧边栏会返回。 Both are important, but I cannot modify the theme, and creating a child theme seems excessive. 两者都很重要,但是我不能修改主题,创建子主题似乎很麻烦。 I'd prefer to debug this theme, and use widgets. 我更喜欢调试此主题,并使用小部件。

Here's what I have tried/tested: 这是我尝试/测试:

  1. Tested this plugin on four other WP sites. 在其他四个WP网站上测试了此插件。 No issues. 没有问题。 Sidebars render fine. 侧栏很好。 Plugin works like a charm. 插件的工作原理很吸引人。

  2. On problem site: wp_debug, set to true... throws no errors, but gives a warning for each of the theme's native sidebars (no id set, which is a pre 4.1 thing). 在问题站点上:wp_debug,设置为true ...不会引发任何错误,但是会为每个主题的本机侧边栏发出警告(未设置id,这是4.1之前的版本)。 To my knowledge, it does not affect anything. 据我所知,它不会影响任何东西。

  3. I removed the include at the bottom, just to narrow down where the problem could be in my code. 我删除了包括底部,只是来缩小的问题可能是在我的代码。 I determined that even when the css enqueue is disabled, or even if add_bottom_bar.php is not included, the theme's native sidebars still break. 我确定即使禁用css入队,或者即使不包括add_bottom_bar.php,主题的本机侧边栏仍然会中断。 This makes it abundantly, totally clear to me that there is a register_sidebar conflict. 这使我非常清楚地知道存在register_sidebar冲突。

  4. I've looked at the source when the plugin is activated, and when it is deactivated. 我已经查看了激活插件和禁用插件的源。 I find after diffing the source, when the plugin is activated, the sidebars do not show in the source, so it is not a css/js thing, as far as I can tell. 我在比较源代码后发现,当插件被激活时,侧边栏不会显示在源代码中,据我所知,这不是css / js。

What, if any workaround might there be for this? 如果有解决方法,该怎么办? A widget would greatly improve workflow, but I'm beginning to consider that letting go of the sidebar/widget situation might be smarter. 小部件将大大改善工作流程,但我开始考虑放开边栏/小部件的情况可能更聪明。

Any hints, tips, or insight? 有任何提示,技巧或见解吗? I know my question is a bit general, but I've hit a brick wall, here, in trying to stay hands-off with this theme code. 我知道我的问题有点笼统,但是在这里我试图碰到这个主题代码时遇到了麻烦。

Any help would be much appreciated! 任何帮助将非常感激! Thanks! 谢谢!

Ok. 好。 Figured it out. 弄清楚了。

add_action( 'widgets_init', 'bottom-widget' );

Needed to initialize the widget right after registering the sidebar. 注册侧栏后需要立即初始化小部件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM