<div class="form-group"> <input type="email" class="form-control" name="email" placeholder="<?php echo __('E-mail', 'realia'); ?> "> </div><!-- /.form-group --> <div class="form-group"> <textarea class="form-control" name="message" placeholder="<?php echo __('Message', 'realia'); ?> " style="overflow: hidden; word-wrap: break-word; height: 68px;"></textarea> </div><!-- /.form-group --> <?php if (Realia_Recaptcha::is_recaptcha_enabled()) { ?> <div id="recaptcha-agent-card" class="recaptcha" data-sitekey="<?php echo get_theme_mod('realia_recaptcha_site_key'); ?> "></div> <?php } ?> <button class="btn pull-right" name="contact-form"><?php echo __('Send message', 'realia'); ?> </button> </form> </div><!-- /.agent-card-form -->
/** * Loads javascript into footer * * @access public * @return void */ public static function enqueue_footer() { if (Realia_Recaptcha::is_recaptcha_enabled() && !is_admin()) { ?> <script type="text/javascript"> var recaptchaCallback = function() { jQuery('.recaptcha').each(function() { var id = jQuery(this).attr('id'); var sitekey = jQuery(this).data('sitekey'); grecaptcha.render(id, { 'sitekey': sitekey }); }); }; </script> <?php } }
/** * Process enquire form * * @access public * @return void */ public static function process_enquire_form() { if (!isset($_POST['enquire_form']) || empty($_POST['post_id'])) { return; } $post = get_post($_POST['post_id']); $email = esc_html($_POST['email']); $name = esc_html($_POST['name']); $subject = __('Message from enquire form', 'realia'); $headers = sprintf("From: %s <%s>\r\n Content-type: text/html", $name, $email); $is_recaptcha = Realia_Recaptcha::is_recaptcha_enabled(); $is_recaptcha_valid = array_key_exists('g-recaptcha-response', $_POST) ? Realia_Recaptcha::is_recaptcha_valid($_POST['g-recaptcha-response']) : false; ob_start(); include Realia_Template_Loader::locate('mails/enquire'); $message = ob_get_contents(); ob_end_clean(); $emails = array(); // Author if (!empty($_POST['receive_author'])) { $emails[] = get_the_author_meta('user_email', $post->post_author); } // Admin if (!empty($_POST['receive_author'])) { $emails[] = get_bloginfo('admin_email'); } // Agent if (!empty($_POST['receive_agent'])) { $agent = Realia_Query::get_property_agent($post->ID); if (!empty($agent)) { $email = get_post_meta($agent->ID, REALIA_AGENT_PREFIX . 'email', true); if (!empty($email)) { $emails[] = $email; } } } // Default fallback if (empty($_POST['receive_admin']) && empty($_POST['receive_agent']) && empty($_POST['receive_author'])) { $emails[] = get_the_author_meta('user_email', $post->post_author); } $emails = array_unique($emails); if ($is_recaptcha && $is_recaptcha_valid) { $_SESSION['messages'][] = array('danger', __('CAPTCHA is not valid.', 'realia')); } foreach ($emails as $email) { $status = wp_mail($email, $subject, $message, $headers); } if (!empty($status) && $status == 1) { $_SESSION['messages'][] = array('success', __('Message has been successfully sent.', 'realia')); } else { $_SESSION['messages'][] = array('danger', __('Unable to send a message.', 'realia')); } }