Skip to content

Instantly share code, notes, and snippets.

@miguelpeixe
Last active December 14, 2015 03:29
Show Gist options
  • Save miguelpeixe/5021930 to your computer and use it in GitHub Desktop.
Save miguelpeixe/5021930 to your computer and use it in GitHub Desktop.
BAIXOCENTRO - Código no functions.php para armazenar query retornada pelo formulário e associar demanda à voluntário cadastrado
<?php
function baixocentro_save_demanda() {
global $cfs;
if(isset($_REQUEST['save_demanda'])) {
$post_id = $_REQUEST['project_id'];
$tipo_demanda = $_REQUEST['tipo_demanda'] == 'producao' ? 'demandas_producao' : 'demandas_equipamento';
$nome = $_REQUEST['nome'];
if(get_post($post_id)) {
$demandas = $cfs->get($tipo_demanda, $post_id);
$update = false;
foreach($demandas as &$demanda) {
if($demanda['demanda'] == $_REQUEST['demanda'] && !$demanda['voluntario']) {
$demanda['voluntario'] = $nome;
$update = true;
}
}
if($update) {
$cfs->save(array($tipo_demanda => $demandas), array('ID' => $post_id));
baixocentro_demanda_email($post_id, $_REQUEST);
}
}
}
}
add_action('init', 'baixocentro_save_demanda');
function baixocentro_demanda_email($post_id, $data) {
// send email to produtor
//$email = get_post_meta($post_id, 'email', true);
$email = 'miguspeixe@gmail.com';
$message = '<p>Olá ' . get_post_meta($post_id, 'autorxs', true) . ', </p>';
$message .= '<p><strong>' . $data['nome'] . '</strong> acaba de se voluntariar para resolver a demanda <strong>' . $data['demanda'] . '</strong> no seu projeto <strong>' . get_the_title($post_id) . '</strong></p>';
$message .= '<p>Entre em contato:</p><p>';
if(isset($data['telefone']))
$message .= '<strong>Telefone: </strong>' . $data['telefone'] . '<br/>';
if(isset($data['email']))
$message .= '<strong>Email: </strong>' . $data['email'];
$message .= '</p>';
$message .= '<p>Caso haja alteração neste acordo, por favor, entre em contato com baixocentro@googlegroups.com para que possamos reabrir a demanda.</p>';
$message .= '<p>Grato e bora dançar na rua!<br/><strong>Equipe BxC</strong></p>';
$headers[] = 'From: BaixoCentro <baixocentro@googlegroups.com>';
if(get_post_meta($post_id, 'email_bxc', true))
$headers[] = 'Cc: ' . get_post_meta($post_id, 'produtor_bxc', true) . ' <' . get_post_meta($post_id, 'email_bxc', true) . '>';
add_filter('wp_mail_content_type', 'set_html_content_type');
wp_mail($email, '[BaixoCentro] Novo voluntário para ' . get_the_title($post_id) . '!', $message, $headers);
remove_filter('wp_mail_content_type', 'set_html_content_type');
}
function set_html_content_type() {
return 'text/html';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment