WC_Download_Handler::check_download_login_required()private staticWC 1.0

Check if a download requires the user to login first.

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

Хуков нет.

Возвращает

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

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

$result = WC_Download_Handler::check_download_login_required( $download );
$download(WC_Customer_Download) (обязательный)
Download instance.

Код WC_Download_Handler::check_download_login_required() WC 9.3.3

private static function check_download_login_required( $download ) {
	if ( $download->get_user_id() && 'yes' === get_option( 'woocommerce_downloads_require_login' ) ) {
		if ( ! is_user_logged_in() ) {
			if ( wc_get_page_id( 'myaccount' ) ) {
				wp_safe_redirect( add_query_arg( 'wc_error', rawurlencode( __( 'You must be logged in to download files.', 'woocommerce' ) ), wc_get_page_permalink( 'myaccount' ) ) );
				exit;
			} else {
				self::download_error( __( 'You must be logged in to download files.', 'woocommerce' ) . ' <a href="' . esc_url( wp_login_url( wc_get_page_permalink( 'myaccount' ) ) ) . '" class="wc-forward">' . __( 'Login', 'woocommerce' ) . '</a>', __( 'Log in to Download Files', 'woocommerce' ), 403 );
			}
		} elseif ( ! current_user_can( 'download_file', $download ) ) {
			self::download_error( __( 'This is not your download link.', 'woocommerce' ), '', 403 );
		}
	}
}