2

I'm not quite sure about when this exactly occurs since it only happens on the live server and not locally. But every now and then (few times per minute) i get a PHP notice in my debug.log.

The PHP notice is: Trying to get property of non-object in /path/to/wordpress/wp-content/themes/themename/vendor/roots/sage-woocommerce/src/woocommerce.php on line 57

I even managed to pinpoint the exact problem, which is get_current_screen()->id.

The strangest thing is, if i take the exact same actions on my local site as on the live site, locally i get 0 notices about this, but on the live site i get approximately 4 notices per minute. (due to it's a live site and people are ordering etc.)

Maybe also good to mention. The live site is hosted on cloudways and has it's own server.

I have tried requiring the require_once(ABSPATH . 'wp-admin/includes/screen.php'); in the sage woocommerce.php file and var_dump(get_current_screen()); but this simply returns NULL.

In time i tried many things to fix this issue, but to be honest it's been some time since i last tried this and i don't have any code left of this.

The exact code where this issue occurs in this file is:

add_filter('wc_get_template', function ($template, $template_name, $args) {
        $theme_template = locate_template(WC()->template_path() . $template_name);

        // return theme filename for status screen
        if (is_admin() && ! wp_doing_ajax() && function_exists('get_current_screen') && get_current_screen() && get_current_screen()->id === 'woocommerce_page_wc-status') {
            return $theme_template ? : $template;
        }

        // return empty file, output already rendered by 'woocommerce_before_template_part' hook
        return $theme_template ? get_stylesheet_directory() . '/index.php' : $template;
    }, 100, 3);

The plus side of this is, it doesn't break the possibility to order items, the down side is, i don't like this notice and it seriously fills the debug.log

I expect the ->id part to return 'woocommerce_page_wc-status' but as mentioned before, it simply returns NULL no matter what i do.

Any help would be greatly appreciated since there are no articles/posts about this anywhere.

Samuel Lelièvre
  • 3,212
  • 1
  • 14
  • 27
jandje
  • 21
  • 3
  • 1
    I still would greatly appreciate any input on this issue. It apparently only happens on the live site. for now, i'm unable to replicate this issue locally.. – jandje Jun 04 '19 at 11:42
  • this may be a little late (lol) but i wager the most likely explanation is... you are trying to use `get_current_screen()` BEFORE the parameters have been assigned... for example `add_action( 'init', function() { print_r( get_current_screen() ); } );` will return null "almost anywhere" within the wordpress environment on the 'init' hook – aequalsb Mar 22 '23 at 18:04
  • you can also hook to the `current_screen` hook like this `add_action( 'current_screen', function() { // stuff you want to do here } );` – aequalsb Mar 22 '23 at 18:12

0 Answers0