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:
RJ 2024-09-13 12:44:28 +08:00 committed by GitHub
parent 268fc4cf4d
commit d7ccebc004
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -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

View File

@ -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;