Automattic\WooCommerce\Internal\Logging

RemoteLogger::is_third_party_errorprotectedWC 1.0

Check if the error exclusively contains third-party stack frames for fatal-errors source context.

Метод класса: RemoteLogger{}

Возвращает

true|false.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->is_third_party_error( $message, $context ): bool;
$message(строка) (обязательный)
The error message.
$context(массив) (обязательный)
The error context.

Код RemoteLogger::is_third_party_error() WC 9.9.3

protected function is_third_party_error( string $message, array $context ): bool {
	// Only check for fatal-errors source context.
	if ( ! isset( $context['source'] ) || 'fatal-errors' !== $context['source'] ) {
		return false;
	}

	$wc_plugin_dir = StringUtil::normalize_local_path_slashes( WC_ABSPATH );

	// Check if the error message contains the WooCommerce plugin directory.
	if ( str_contains( $message, $wc_plugin_dir ) ) {
		return false;
	}

	// Without a backtrace, it's impossible to ascertain if the error is third-party. To avoid logging numerous irrelevant errors, we'll consider it a third-party error and ignore it.
	if ( isset( $context['backtrace'] ) && is_array( $context['backtrace'] ) ) {
		$wp_includes_dir = StringUtil::normalize_local_path_slashes( ABSPATH . WPINC );
		$wp_admin_dir    = StringUtil::normalize_local_path_slashes( ABSPATH . 'wp-admin' );

		// Find the first relevant frame that is not from WordPress core and not empty.
		$relevant_frame = null;
		foreach ( $context['backtrace'] as $frame ) {
			if ( empty( $frame ) || ! is_string( $frame ) ) {
				continue;
			}

			// Skip frames from WordPress core.
			if ( strpos( $frame, $wp_includes_dir ) !== false || strpos( $frame, $wp_admin_dir ) !== false ) {
				continue;
			}

			$relevant_frame = $frame;
			break;
		}

		// Check if the relevant frame is from WooCommerce.
		if ( $relevant_frame && strpos( $relevant_frame, $wc_plugin_dir ) !== false ) {
			return false;
		}
	}

	if ( ! function_exists( 'apply_filters' ) ) {
		require_once ABSPATH . WPINC . '/plugin.php';
	}
	/**
	 * Filter to allow other plugins to overwrite the result of the third-party error check for remote logging.
	 *
	 * @since 9.2.0
	 *
	 * @param bool   $is_third_party_error The result of the third-party error check.
	 * @param string $message              The error message.
	 * @param array  $context              The error context.
	 */
	return apply_filters( 'woocommerce_remote_logging_is_third_party_error', true, $message, $context );
}