Support » Plugin: amr shortcode any widget » Empty Shortcode Sidebar & Theme Customiser

  • Plugin Author anmari

    (@anmari)



    I’ve observed a rather weird anomaly on one of my sites, where I had this plugin active, with no widgets in the shortcode sidebar. When this happens the wordpress theme customiser refused to load. Add a widget to the sidebar (make sure it saves) and the customiser is happy again. I’ve no idea why this is so, but it was damn annoying to figure out! So either make sure there is at least one widget in the sidebar, or deactivate the plugin if you are no longer using it.

Viewing 6 replies - 1 through 6 (of 6 total)
  • just that you know, I had a similar issue with the great “widget options” plugin while using the Divi theme…
    maybe it helps.

    Plugin Author anmari

    (@anmari)

    thanks for feedback

    Fiech

    (@fiech)

    Hi,

    I may have stumbled upon this same problem (in a Multi-Site installation, but I think this could be a problem in all installations) and I may have an explanation (given, it’s the same problem, anyway):

    If the shortcode widget is first installed without being ever used, the wordpress widget engine will try to access the stored widgets (which would normally be an empty array), but gets a “false” instead, which leads to warnings on the widget page, as well as in the customizer.

    To illustrate, in the file wp-includes/widgets.php:1159, the variable $sidebars_widgets will contain the following (note that ‘front-page-widget’ is a theme specific widget area, I added via a register_sidebar in the functions.php):

    
    array (
      'wp_inactive_widgets' => 
      array (
      ),
      'sidebar-1' => 
      array (
      ),
      'sidebar-2' => 
      array (
      ),
      'sidebar-3' => 
      array (
      ),
      'front-page-widget' => 
      array (
      ),
      'widgets_for_shortcodes' => false,
    )
    

    Subsequently, I receive the following PHP-Warnings on the widget page:

    
    PHP Warning:  array_merge(): Argument #6 is not an array in <path_to_wp>/wp-includes/widgets.php on line 1159
    PHP Warning:  array_diff(): Argument #2 is not an array in <path_to_wp>/wordpress/wp-includes/widgets.php on line 1160
    PHP Warning:  Invalid argument supplied for foreach() in <path_to_wp>/wp-includes/widgets.php on line 1162
    PHP Warning:  array_merge(): Argument #1 is not an array in <path_to_wp>/wp-includes/widgets.php on line 1170
    

    And in the customizer for the file wp-includes/class-wp-customize-widgets.php:

    
    PHP Warning:  array_intersect(): Argument #1 is not an array in <path_to_wp>/wp-includes/class-wp-customize-widgets.php on line 1343
    PHP Warning:  array_values() expects parameter 1 to be array, null given in <path_to_wp>/wp-includes/class-wp-customize-widgets.php on line 1343
    

    After adding a random widget to the Shortcode-Widget-Area and removing it, the corresponding array field is an empty array, as expected, and the warnings all disappear:

    
    array (
      'wp_inactive_widgets' => 
      array (
      ),
      'sidebar-1' => 
      array (
      ),
      'sidebar-2' => 
      array (
      ),
      'sidebar-3' => 
      array (
      ),
      'front-page-widget' => 
      array (
      ),
      'widgets_for_shortcodes' => 
      array (
      ),
    )
    

    So, the problem seems to either be, that the new widget area is not properly registered as such, leading to a false (maybe, because it tries to fetch a nonexisting entry in the options-table, which does not neccessarily exist), or because the WP-widget-engine is not sufficiently hardened against unexpected entries (false, instead of array()).

    PS: I simply had to add and remove a widget to the shortcode widget area on any sub-blog in my multi-site installation to have it work on all the sub-blogs. Not sure why though…

    • This reply was modified 12 months ago by  Fiech.
    • This reply was modified 12 months ago by  Fiech.
    Plugin Author anmari

    (@anmari)

    Hmm, I’v eplayed further with this. There’s not much to ‘register_sidebar’ – hard to do not do it ‘properly’ and the code is similar to what themes do – fires on widget init etc.

    With further playing around, tt seems to me that it happens:
    when plugin first activated and the shortcode sidebar is not yet used, but ok after that?
    when a new theme is first activated that has not been used with the plugin before. Dragging a widget to ANY sidebar fixes that.

    It’s very puzzling.
    Of course one option is to force a default widget in but that feels like a workaround rather than understanding why it happens.

    Fiech

    (@fiech)

    You’re right. It still happens, if a theme is used for the first time: The same problems occur, until the “Widgets for Shortcodes” area is used for the first time.

    Maybe this explains the behavior in a multi-site installation? Where is the content of the “Widgets for Shortcodes” area stored (for each sub-blog)? It seems, to me, that the area is sub-blog specific.

    Strangely enough, newly added sub-blogs do not have the problem, as long as the “Widgets for Shortcodes” area was filled once.

    Plugin Author anmari

    (@anmari)

    It’s related to the fact that the shortcode sidebar is NOT created by the theme, so the theme-mod subarray ‘sidebars-widgets’ doesn’t have that sidebar, so somehow the initial blank array doesn’t get setup. I’m working on adding a filter to the get theme mods to add the empty array. Testing to be SURE one has fixed it is tricky though. So far I’ve now ‘moved’ the message to wp now complaining that the ‘data’ in the theme mod is not set, but I think that’s because I’m manually deleting theme mods to create the appearance of not having used a theme before. and somehow wp not checking for that.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Empty Shortcode Sidebar & Theme Customiser’ is closed to new replies.