Automattic\WooCommerce\Internal\Logging

RemoteLogger::is_third_party_error │ protected │ WC 1.0

Check if the error exclusively contains third-party stack frames, for the sources that carry an engine-error backtrace.

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

Возвращает

bool.

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

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

Код RemoteLogger::is_third_party_error() WC 11.3.0

protected function is_third_party_error( string $message, array $context ): bool {
	if ( ! isset( $context['source'] ) || ! in_array( $context['source'], self::THIRD_PARTY_CHECK_SOURCES, true ) ) {
		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.
	 *
	 * Runs for `fatal-errors` entries from the shutdown handler and, since 11.3.0, for caught `store-api` errors. Both provide `error.type`, `error.file` and `error.line`; caught errors use the PHP error type they would produce if uncaught. Both also carry a `backtrace` list of `#N file(line): call` strings; `fatal-errors` entries carry `true` instead when PHP supplied no stack trace.
	 *
	 * @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, including `source`.
	 */
	return apply_filters( 'woocommerce_remote_logging_is_third_party_error', true, $message, $context );
}