fix: add check for wp_get_current_user() before calling it (#51302)
* fix: add check for wp_get_current_user() before calling it * changelog * changed try catch to catch throwable
This commit is contained in:
parent
268fc4cf4d
commit
d7ccebc004
|
@ -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
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue