WC_Download_Handler::download_error()private staticWC 1.0

Die with an error message if the download fails.

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

Хуков нет.

Возвращает

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

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

$result = WC_Download_Handler::download_error( $message, $title, $status );
$message(строка) (обязательный)
Error message.
$title(строка)
Error title.
По умолчанию: ''
$status(int)
Error status.
По умолчанию: 404

Код WC_Download_Handler::download_error() WC 8.7.0

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.
}