WC_Download_Handler::download_error │ private static │ WC 1.0

Die with an error message if the download fails.

Method of the class: WC_Download_Handler{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = WC_Download_Handler::download_error( $message, $title, $status );
$message(string) (required)
Error message.
$title(string)
Error title.
Default: ''
$status(int)
Error status.
Default: 404

WC_Download_Handler::download_error() code WC 11.2.2

private static function download_error( $message, $title = '', $status = 404 ) {
	/*
	 * Since we will now render a message instead of serving a download, we should unwind some of the previously set
	 * headers.
	 */
	if ( headers_sent() ) {
		wc_get_logger()->log( 'warning', __( 'Headers already sent when generating download error message.', 'woocommerce' ) );
	} else {
		self::remove_download_headers();
		header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
	}

	if ( ! strstr( $message, '<a ' ) ) {
		$message .= ' <a href="' . esc_url( wc_get_page_permalink( 'shop' ) ) . '" class="wc-forward">' . esc_html__( 'Go to shop', 'woocommerce' ) . '</a>';
	}
	wp_die( $message, $title, array( 'response' => $status ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_die() accepts HTML; callers pass fixed messages with explicitly escaped links.
}