WC_Download_Handler::download_error()private staticWC 1.0

Die with an error message if the download fails.

Method of the class: WC_Download_Handler{}

No Hooks.

Return

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 9.4.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 {
		header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
		header_remove( 'Content-Description;' );
		header_remove( 'Content-Disposition' );
		header_remove( 'Content-Transfer-Encoding' );
	}

	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 ) ); // WPCS: XSS ok.
}