Last active
May 10, 2021 16:46
-
-
Save angelcosta/c8d1f0c5142c65d09ce430af2e550287 to your computer and use it in GitHub Desktop.
Download Monitor - Send as download as attachment template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Send download to user's email | |
*/ | |
if ($_SERVER['REQUEST_METHOD'] == 'POST') { | |
/*$versions = $dlm_download->get_file_versions(); | |
reset($versions); | |
$version = key($versions); | |
$attach = $versions[$version]->url;*/ | |
$versoes = $dlm_download->get_file_versions(); | |
$versao = key($versoes); | |
$attach = $versoes[$versao]->url; | |
$email = $_POST['email']; | |
$subject = $dlm_download->get_the_title(); | |
$message = $dlm_download->post->post_content; | |
if (!empty($email)){ | |
wp_mail( $email, $subject, $message, '', $attach); | |
$countv = absint( get_post_meta( $version, '_download_count', true ) ) + 1; | |
update_post_meta( $version, '_download_count', $countv ); | |
$count = absint( get_post_meta( $dlm_download->id, '_download_count', true ) ) + 1; | |
update_post_meta( $dlm_download->id, '_download_count', $count ); | |
$result = '<div class="alerta verde">Seu arquivo foi enviado com sucesso.</div>'; | |
} | |
else{ | |
$result = '<div class="alerta vermelho">Você precisa informar um email válido.</div>'; | |
} | |
} | |
?> | |
<div class="row" style='padding:20px 10px 10px; border-bottom:1px solid #eee; border-top:1px solid #eee'> | |
<?php $dlm_download->the_image('blog-download'); ?> | |
<div class="downloads"><strong>Baixe o arquivo logo ou receba-o por email:</strong></div> | |
<p style="margin-top:10px; text-align: center;"> | |
[ <i class="fa fa-download"></i> <a title="Baixar o arquivo" href="<?php $dlm_download->the_download_link(); ?>"> | |
<?php $dlm_download->the_title(); ?></a> - <?php echo $dlm_download->get_the_download_count(); ?> downloads | |
] | |
</p> | |
<?php if ($result !== "") echo $result; ?> | |
<form method="post"> | |
<label for="email"><input size="40" name="email" type="email" placeholder="Informe seu email" onclick="this.value='';" onfocus="this.select()" onblur="this.value=!this.value?'Informe seu email':this.value;" value="Informe seu email" required></label> | |
<input type="submit" class="button" value="Enviar por email"> | |
</form> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment