WooCommerce::log_errors()publicWC 3.2.0

Ensures fatal errors are logged so they can be picked up in the status report.

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

Хуки из метода

Возвращает

null. Ничего (null).

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

$WooCommerce = new WooCommerce();
$WooCommerce->log_errors();

Список изменений

С версии 3.2.0 Введена.

Код WooCommerce::log_errors() WC 8.7.0

public function log_errors() {
	$error = error_get_last();
	if ( $error && in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ), true ) ) {
		$error_copy = $error;
		$message    = $error_copy['message'];
		unset( $error_copy['message'] );

		$context = array(
			'source' => 'fatal-errors',
			'error'  => $error_copy,
		);

		if ( false !== strpos( $message, 'Stack trace:' ) ) {
			$segments  = explode( 'Stack trace:', $message );
			$message   = str_replace( PHP_EOL, ' ', trim( $segments[0] ) );
			$backtrace = array_map(
				'trim',
				explode( PHP_EOL, $segments[1] )
			);

			$context['backtrace'] = $backtrace;
		} else {
			$context['backtrace'] = true;
		}

		$logger = wc_get_logger();
		$logger->critical(
			$message,
			$context
		);

		/**
		 * Action triggered when there are errors during shutdown.
		 *
		 * @since 3.2.0
		 */
		do_action( 'woocommerce_shutdown_error', $error );
	}
}