Roots Discourse

Getting some strange error with Sage 9.0.9

I had a complain of critical error on one of the wordpress website. When I checked teh debug log I found mutiple warnings but This was the consistent error which was reoccuring. The error doesnt stay for too long, a couple of refresh fixes it, but it seems like something is happneing in the themes filter.php file. I have added the stacktrace changed the name of theme file and redacted the IP address.

Stack Trace

2021-07-06 [NOTICE] [XXX.XXX.XXX.XXX:48998#wordpress] [STDERR] PHP Fatal error:  Uncaught TypeError: Argument 1 passed to App\{closure}() must be of the type array, nu$Stack trace:
#0 /var/www/html/wp-includes/class-wp-hook.php(294): App\{closure}(NULL)
#1 /var/www/html/wp-includes/plugin.php(212): WP_Hook->apply_filters(NULL, Array)
#2 /var/www/html/wp-includes/post-template.php(836): apply_filters('body_class', Array, Array)
#3 /var/www/html/wp-content/themes/mytheme/vendor/roots/sage-woocommerce/src/woocommerce.php(41): get_body_class()
#4 /var/www/html/wp-includes/class-wp-hook.php(292): App\{closure}('emails/admin-ne...', '', '/var/www/html/w...', Array)
#5 /var/www/html/wp-includes/class-wp-hook.php(316): WP_Hook->apply_filters('', Array)
#6 /var/www/html/wp-includes/plugin.php(484): WP_Hook->do_action(Array)
#7 /var/www/html/wp-content/plugins/woocommerce/includes/wc-core-functions.php(343): do_action('woocommerce_bef...', 'emails/a in /var/www/html/wp-content/themes/mytheme/app/filters$

Could this be triggered because of some other code ?

1 Like

It seems that the error originates from the sage-woocommerce composer library dependency (not a WordPress plugin btw.!) of the sage theme.

The latest release of this library at time of writing is 1.0.4 (see
Have you updated the version of it in your theme to this latest release yet?
This may fix the issue and incompatibility issues that arise when WordPress core or WooCommerce plugin are updated.

Hey @strarsis,

I think I am on the latest verison of sage-woocommerce.

    "soberwp/controller": "~2.1.0",
    "roots/sage-woocommerce": "^1.0",
    "drewm/mailchimp-api": "^2.5",

This is what my composer.json looks like, and I also tried composer update roots/sage-woocommerce and nothing got updated so I can say that I am on the latest verison of sage-woocommerce.

I have added chnaged the code to this to get rid of critical error notices.

 if(is_array($classes)) {
    add_filter('body_class', function (array $classes) {
        /** Add page slug if it doesn't exist */
        if (is_single() || is_page() && !is_front_page()) {
            if (!in_array(basename(get_permalink()), $classes)) {
                $classes[] = basename(get_permalink());
        /** Add class if sidebar is active */
        if (display_sidebar()) {
            $classes[] = 'sidebar-primary';
        /** Clean up class names for custom templates */
        $classes = array_map(function ($class) {
            return preg_replace(['/-blade(-php)?$/', '/^page-template-views/'], '', $class);
        }, $classes);
        return array_filter($classes);

This topic was automatically closed after 42 days. New replies are no longer allowed.