Reduce dependency of remote logging on WC_Tracks (#51365)
* Simplify WC_Tracks::get_blog_details() to reduce its dependencies * Add changelog * Remove store_id field * Improve the check
This commit is contained in:
parent
cf953cf3cf
commit
83be8cb544
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: enhancement
|
||||
|
||||
Reduce dependency of remote logging on WC_Tracks
|
|
@ -8,6 +8,7 @@ use Automattic\WooCommerce\Utilities\StringUtil;
|
|||
use Automattic\WooCommerce\Internal\McStats;
|
||||
use WC_Rate_Limiter;
|
||||
use WC_Log_Levels;
|
||||
use Jetpack_Options;
|
||||
|
||||
/**
|
||||
* WooCommerce Remote Logger
|
||||
|
@ -72,9 +73,16 @@ class RemoteLogger extends \WC_Log_Handler {
|
|||
'php_version' => phpversion(),
|
||||
'wp_version' => get_bloginfo( 'version' ),
|
||||
'request_uri' => $this->sanitize_request_uri( filter_input( INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL ) ),
|
||||
'store_id' => get_option( \WC_Install::STORE_ID_OPTION, null ),
|
||||
),
|
||||
);
|
||||
|
||||
$blog_id = class_exists( 'Jetpack_Options' ) ? Jetpack_Options::get_option( 'id' ) : null;
|
||||
|
||||
if ( ! empty( $blog_id ) && is_int( $blog_id ) ) {
|
||||
$log_data['blog_id'] = $blog_id;
|
||||
}
|
||||
|
||||
if ( isset( $context['backtrace'] ) ) {
|
||||
if ( is_array( $context['backtrace'] ) || is_string( $context['backtrace'] ) ) {
|
||||
$log_data['trace'] = $this->sanitize_trace( $context['backtrace'] );
|
||||
|
@ -89,19 +97,6 @@ class RemoteLogger extends \WC_Log_Handler {
|
|||
unset( $context['tags'] );
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
if ( is_numeric( $blog_details['blog_id'] ) && $blog_details['blog_id'] > 0 ) {
|
||||
$log_data['blog_id'] = $blog_details['blog_id'];
|
||||
}
|
||||
|
||||
if ( ! empty( $blog_details['store_id'] ) ) {
|
||||
$log_data['properties']['store_id'] = $blog_details['store_id'];
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $context['error'] ) && is_array( $context['error'] ) && ! empty( $context['error']['file'] ) ) {
|
||||
$context['error']['file'] = $this->sanitize( $context['error']['file'] );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue