Warning: in_array() [function.in-array]: Wrong datatype for second argument

I’ve got this error when I activated one plugin. I’m not a professional programmer, but I have some php experience. Help me please. The error is in the if ( in_array('template-widget', $widgets)) { line.

function ActionWpPrintScripts() {
    global $post;

    // Check to see if widget is present on page
    $sidebars_widgets = wp_get_sidebars_widgets(false);
    $widget_loaded = false;

    if ( is_array($sidebars_widgets) ) {
        foreach ( $sidebars_widgets as $sidebar => $widgets ) {
            if ( in_array('template-widget', $widgets)) {
                $widget_loaded = true;
            }
        }
    }
}

Related posts

Leave a Reply

1 comment

  1. The function wp_get_sidebars_widgets is not supposed to be called by plugins, only used internally. The documentation also states that

    Upgraded list of widgets to version 3 array format when called from the admin.

    So that might be the reason why it does not work in the context you are calling it.
    My suggestion is to try another approach for whatever you are trying to accomplish.