diff --git a/plugins/woocommerce/changelog/fix-remote-logger-undefined-wp-current-user b/plugins/woocommerce/changelog/fix-remote-logger-undefined-wp-current-user new file mode 100644 index 00000000000..be10eb2ec34 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-remote-logger-undefined-wp-current-user @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Adds a function_exists() check so that we don't add a secondary fatal in remote logging if wp_get_current_user does not exist yet diff --git a/plugins/woocommerce/src/Internal/Logging/RemoteLogger.php b/plugins/woocommerce/src/Internal/Logging/RemoteLogger.php index 3043cd110fe..a15792fb29b 100644 --- a/plugins/woocommerce/src/Internal/Logging/RemoteLogger.php +++ b/plugins/woocommerce/src/Internal/Logging/RemoteLogger.php @@ -88,7 +88,7 @@ class RemoteLogger extends \WC_Log_Handler { unset( $context['tags'] ); } - if ( class_exists( '\WC_Tracks' ) ) { + if ( class_exists( '\WC_Tracks' ) && function_exists( 'wp_get_current_user' ) ) { $user = wp_get_current_user(); $blog_details = \WC_Tracks::get_blog_details( $user->ID ); @@ -233,7 +233,7 @@ class RemoteLogger extends \WC_Log_Handler { } return true; - } catch ( \Exception $e ) { + } catch ( \Throwable $e ) { // Log the error locally if the remote logging fails. error_log( 'Remote logging failed: ' . $e->getMessage() ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log return false;