| 1 |
<?php |
| 2 |
/** |
| 3 |
* Template Name: Contact |
| 4 |
* |
| 5 |
* @package Kadence Toolkit |
| 6 |
*/ |
| 7 |
|
| 8 |
global $virtue, $post; |
| 9 |
$page_map = get_post_meta( $post->ID, '_kad_contact_map', true ); |
| 10 |
$form_math = get_post_meta( $post->ID, '_kad_contact_form_math', true ); |
| 11 |
$contactformtitle = get_post_meta( $post->ID, '_kad_contact_form_title', true ); |
| 12 |
$form = get_post_meta( $post->ID, '_kad_contact_form', true ); |
| 13 |
$consent = apply_filters( 'kadence-virtue-contact-consent', false ); |
| 14 |
|
| 15 |
if ( isset( $_POST['submitted'] ) && isset( $_POST['virtue_contact_nounce'] ) ) { |
| 16 |
if ( wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['virtue_contact_nounce'] ) ), 'virtue_contact_nounce_action' ) ) { |
| 17 |
$spam_hook = apply_filters( 'kadence-contact-spam-check', true, $_POST ); |
| 18 |
|
| 19 |
if ( ! $spam_hook ) { |
| 20 |
$has_error = true; |
| 21 |
$spam_error = __( 'Your post appears to be spam, if this is incorrect please contact the site admnistator.', 'virtue-toolkit' ); |
| 22 |
} |
| 23 |
if ( isset( $form_math ) && 'yes' === $form_math ) { |
| 24 |
if ( isset( $_POST['kad_captcha'] ) && isset( $_POST['hval'] ) ) { |
| 25 |
$math_answer = trim( sanitize_text_field( wp_unslash( $_POST['kad_captcha'] ) ) ); |
| 26 |
if ( md5( $math_answer ) != sanitize_text_field( wp_unslash( $_POST['hval'] ) ) ) { |
| 27 |
$kad_captcha_error = __( 'Check your math.', 'virtue-toolkit' ); |
| 28 |
$has_error = true; |
| 29 |
} |
| 30 |
} else { |
| 31 |
$kad_captcha_error = __( 'Check your math.', 'virtue-toolkit' ); |
| 32 |
$has_error = true; |
| 33 |
} |
| 34 |
} |
| 35 |
if ( isset( $consent ) && 'true' == $consent ) { |
| 36 |
if ( isset( $_POST['gdpr-consent'] ) ) { |
| 37 |
$gdpr_consent = sanitize_text_field( wp_unslash( $_POST['gdpr-consent'] ) ); |
| 38 |
if ( 'on' != $gdpr_consent ) { |
| 39 |
$kad_consent_error = __( 'Please check the box.', 'virtue-toolkit' ); |
| 40 |
$has_error = true; |
| 41 |
} |
| 42 |
} else { |
| 43 |
$kad_consent_error = __( 'Please check the box.', 'virtue-toolkit' ); |
| 44 |
$has_error = true; |
| 45 |
} |
| 46 |
} |
| 47 |
if ( isset( $_POST['contactName'] ) && ! empty( $_POST['contactName'] ) ) { |
| 48 |
$name = trim( sanitize_text_field( wp_unslash( $_POST['contactName'] ) ) ); |
| 49 |
} else { |
| 50 |
$name_error = __( 'Please enter your name.', 'virtue-toolkit' ); |
| 51 |
$has_error = true; |
| 52 |
} |
| 53 |
if ( ! isset( $_POST['email'] ) || empty( $_POST['email'] ) ) { |
| 54 |
$email_error = __( 'Please enter your email address.', 'virtue-toolkit' ); |
| 55 |
$has_error = true; |
| 56 |
} elseif ( ! is_email( trim( sanitize_text_field( wp_unslash( $_POST['email'] ) ) ) ) ) { |
| 57 |
$email_error = __( 'You entered an invalid email address.', 'virtue-toolkit' ); |
| 58 |
$has_error = true; |
| 59 |
} else { |
| 60 |
$email = trim( sanitize_text_field( wp_unslash( $_POST['email'] ) ) ); |
| 61 |
} |
| 62 |
|
| 63 |
if ( ! isset( $_POST['comments'] ) || empty( $_POST['comments'] ) ) { |
| 64 |
$comment_error = __( 'Please enter a message.', 'virtue-toolkit' ); |
| 65 |
$has_error = true; |
| 66 |
} else { |
| 67 |
$contact_comments = wp_kses_post( wp_unslash( $_POST['comments'] ) ); |
| 68 |
} |
| 69 |
|
| 70 |
if ( ! isset( $has_error ) ) { |
| 71 |
|
| 72 |
if ( isset( $virtue['contact_email'] ) ) { |
| 73 |
$email_to = $virtue['contact_email']; |
| 74 |
} else { |
| 75 |
$email_to = get_option( 'admin_email' ); |
| 76 |
} |
| 77 |
$sitename = get_bloginfo( 'name' ); |
| 78 |
$subject = '[' . $sitename . ' ' . __( 'Contact', 'virtue-toolkit' ) . '] ' . __( 'From ', 'virtue-toolkit' ) . $name; |
| 79 |
$body = __( 'Name', 'virtue-toolkit' ) . ':' . $name . "\n\n" . 'Email:' . $email . "\n\n" . 'Comments:' . $contact_comments; |
| 80 |
$headers = 'Content-Type: text/plain; charset=UTF-8' . "\r\n"; |
| 81 |
$headers .= 'Content-Transfer-Encoding: 8bit' . "\r\n"; |
| 82 |
$headers .= 'From: ' . $name . ' <' . $email . '>' . "\r\n"; |
| 83 |
$headers .= 'Reply-To: <' . $email . '>' . "\r\n"; |
| 84 |
|
| 85 |
wp_mail( $email_to, $subject, $body, $headers ); |
| 86 |
$email_sent = true; |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* @hooked virtue_page_title - 20 |
| 93 |
*/ |
| 94 |
do_action( 'virtue_page_title_container' ); |
| 95 |
|
| 96 |
if ( 'yes' == $page_map ) { |
| 97 |
$address = get_post_meta( $post->ID, '_kad_contact_address', true ); |
| 98 |
$maptype = get_post_meta( $post->ID, '_kad_contact_maptype', true ); |
| 99 |
$height = get_post_meta( $post->ID, '_kad_contact_mapheight', true ); |
| 100 |
$mapzoom = get_post_meta( $post->ID, '_kad_contact_zoom', true ); |
| 101 |
if ( isset( $virtue['google_map_api'] ) && ! empty( $virtue['google_map_api'] ) ) { |
| 102 |
$gmap_api = $virtue['google_map_api']; |
| 103 |
} else { |
| 104 |
$gmap_api = ''; |
| 105 |
} |
| 106 |
if ( ! empty( $height ) ) { |
| 107 |
$mapheight = $height; |
| 108 |
} else { |
| 109 |
$mapheight = 300; |
| 110 |
} |
| 111 |
if ( ! empty( $mapzoom ) ) { |
| 112 |
$zoom = $mapzoom; |
| 113 |
} else { |
| 114 |
$zoom = 15; |
| 115 |
} |
| 116 |
if ( ! empty( $gmap_api ) ) { |
| 117 |
if ( wp_script_is( 'virtue_gmap', 'registered' ) ) { |
| 118 |
wp_enqueue_script( 'virtue_gmap' ); |
| 119 |
} |
| 120 |
?> |
| 121 |
<div id="mapheader" class="titleclass"> |
| 122 |
<div class="container"> |
| 123 |
<div id="map_address" style="height:<?php echo esc_attr( $mapheight ); ?>px; margin-bottom:20px;" class="kt-gmap-js-init" data-maptype="<?php echo esc_attr( $maptype ); ?>" data-mapzoom="<?php echo esc_attr( $zoom ); ?>" data-mapcenter="<?php echo esc_attr( $address ); ?>" data-address1="<?php echo esc_attr( $address ); ?>"> |
| 124 |
</div> |
| 125 |
</div><!--container--> |
| 126 |
</div><!--titleclass--> |
| 127 |
<?php |
| 128 |
} else { |
| 129 |
if ( 'TERRAIN' === $maptype ) { |
| 130 |
$maptype = 'p'; |
| 131 |
} elseif ( 'HYBRID' === $maptype ) { |
| 132 |
$maptype = 'h'; |
| 133 |
} elseif ( 'SATELLITE' === $maptype ) { |
| 134 |
$maptype = 'k'; |
| 135 |
} else { |
| 136 |
$maptype = 'm'; |
| 137 |
} |
| 138 |
$query_string = 'q=' . rawurlencode( $address ) . '&cid=&t=' . rawurlencode( $maptype ) . '¢er=' . rawurlencode( $address ); |
| 139 |
echo '<div class="kt-map"><iframe height="' . esc_attr( $mapheight ) . '" style="width:100%; max-width: 100%; border:0;" src="https://maps.google.com/maps?&' . esc_attr( htmlentities( $query_string ) ) . '&output=embed&z=' . esc_attr( $zoom ) . '&iwloc=A&visual_refresh=true"></iframe></div>'; |
| 140 |
|
| 141 |
} |
| 142 |
} |
| 143 |
?> |
| 144 |
<div id="content" class="container"> |
| 145 |
<div class="row"> |
| 146 |
<div id="main" class="<?php echo ( 'yes' === $form ? 'col-md-6' : 'col-md-12' ); ?>" role="main"> |
| 147 |
<?php do_action( 'kadence_page_before_content' ); ?> |
| 148 |
<div class="entry-content" itemprop="mainContentOfPage"> |
| 149 |
<?php get_template_part( 'templates/content', 'page' ); ?> |
| 150 |
</div> |
| 151 |
</div> |
| 152 |
<?php |
| 153 |
if ( 'yes' === $form ) { |
| 154 |
if ( wp_script_is( 'virtue_contact_validation', 'registered' ) ) { |
| 155 |
wp_enqueue_script( 'virtue_contact_validation' ); |
| 156 |
} |
| 157 |
?> |
| 158 |
<div class="contactformcase col-md-6"> |
| 159 |
<?php |
| 160 |
$contactformtitle = get_post_meta( $post->ID, '_kad_contact_form_title', true ); |
| 161 |
if ( ! empty( $contactformtitle ) ) { |
| 162 |
echo '<h3>' . wp_kses_post( $contactformtitle ) . '</h3>'; |
| 163 |
} |
| 164 |
if ( isset( $email_sent ) && true === $email_sent ) { |
| 165 |
do_action( 'kt_contact_email_sent' ); |
| 166 |
?> |
| 167 |
<div class="thanks"> |
| 168 |
<p><?php esc_html_e( 'Thanks, your email was sent successfully.', 'virtue-toolkit' ); ?></p> |
| 169 |
</div> |
| 170 |
<?php |
| 171 |
} else { |
| 172 |
|
| 173 |
if ( isset( $has_error ) ) { |
| 174 |
?> |
| 175 |
<p class="error"><?php esc_html_e( 'Sorry, an error occured.', 'virtue-toolkit' ); ?><p> |
| 176 |
<?php |
| 177 |
} |
| 178 |
?> |
| 179 |
<form action="<?php the_permalink(); ?>" id="contactForm" method="post"> |
| 180 |
<div class="contactform"> |
| 181 |
<p> |
| 182 |
<label for="contactName"><b><?php esc_html_e( 'Name:', 'virtue-toolkit' ); ?></b><span class="contact-required">*</span></label> |
| 183 |
<input type="text" name="contactName" id="contactName" value="<?php echo ( isset( $_POST['contactName'] ) ? esc_attr( wp_kses_post( wp_unslash( $_POST['contactName'] ) ) ) : '' ); ?>" class="required requiredField full" /> |
| 184 |
<?php if ( isset( $name_error ) ) { ?> |
| 185 |
<label class="error"><?php esc_html( $name_error ); ?></label> |
| 186 |
<?php } ?> |
| 187 |
</p> |
| 188 |
<p> |
| 189 |
<label for="email"><b><?php esc_html_e( 'Email:', 'virtue-toolkit' ); ?></b><span class="contact-required">*</span></label> |
| 190 |
<input type="text" name="email" id="email" value="<?php echo ( isset( $_POST['email'] ) ? esc_attr( wp_kses_post( wp_unslash( $_POST['email'] ) ) ) : '' ); ?>" class="required requiredField email full" /> |
| 191 |
<?php if ( isset( $email_error ) ) { ?> |
| 192 |
<label class="error"><?php echo esc_html( $email_error ); ?></label> |
| 193 |
<?php } ?> |
| 194 |
</p> |
| 195 |
<p><label for="commentsText"><b><?php esc_html_e( 'Message: ', 'virtue-toolkit' ); ?></b><span class="contact-required">*</span></label> |
| 196 |
<textarea name="comments" id="commentsText" rows="10" class="required requiredField"><?php echo ( isset( $_POST['comments'] ) ? esc_textarea( wp_kses_post( wp_unslash( $_POST['comments'] ) ) ) : '' ); ?></textarea> |
| 197 |
<?php if ( isset( $comment_error ) ) { ?> |
| 198 |
<label class="error"><?php echo esc_html( $comment_error ); ?></label> |
| 199 |
<?php } ?> |
| 200 |
</p> |
| 201 |
<?php |
| 202 |
if ( isset( $form_math ) && 'yes' === $form_math ) { |
| 203 |
$one = wp_rand( 5, 50 ); |
| 204 |
$two = wp_rand( 1, 9 ); |
| 205 |
$result = md5( $one + $two ); |
| 206 |
?> |
| 207 |
<p> |
| 208 |
<label for="kad_captcha"><b><?php echo esc_html( $one . ' + ' . $two ); ?> = </b><span class="contact-required">*</span></label> |
| 209 |
<input type="text" name="kad_captcha" id="kad_captcha" class="required requiredField kad_captcha kad-quarter" /> |
| 210 |
<?php if ( isset( $kad_captcha_error ) ) { ?> |
| 211 |
<label class="error"><?php echo esc_html( $kad_captcha_error ); ?></label> |
| 212 |
<?php } ?> |
| 213 |
<input type="hidden" name="hval" id="hval" value="<?php echo esc_attr( $result ); ?>" /> |
| 214 |
</p> |
| 215 |
<?php } ?> |
| 216 |
<?php if ( isset( $consent ) && 'true' === $consent ) { ?> |
| 217 |
<p> |
| 218 |
<input type="checkbox" name="gdpr-consent" id="gdpr-consent" class="required requiredField kad_gdpr-consent" /> |
| 219 |
<?php |
| 220 |
if ( isset( $virtue_premium['contact_consent'] ) && ! empty( $virtue_premium['contact_consent'] ) ) { |
| 221 |
$contact_consent_label = $virtue_premium['contact_consent']; |
| 222 |
} else { |
| 223 |
if ( function_exists( 'the_privacy_policy_link' ) ) { |
| 224 |
$privacy_link = get_the_privacy_policy_link(); |
| 225 |
} |
| 226 |
if ( ! empty( $privacy_link ) ) { |
| 227 |
// translators: %1$s = privacy page link. |
| 228 |
$contact_consent_label = sprintf( __( 'Please check to consent to our %s.', 'virtue-toolkit' ), $privacy_link ); |
| 229 |
} else { |
| 230 |
$contact_consent_label = __( 'Please check to consent to our privacy policy.', 'virtue-toolkit' ); |
| 231 |
} |
| 232 |
} |
| 233 |
?> |
| 234 |
<label for="gdpr-consent" class="gdpr-consent-label"><?php echo wp_kses_post( $contact_consent_label ); ?><span class="contact-required">*</span></label> |
| 235 |
<?php if ( isset( $kad_consent_error ) ) { ?> |
| 236 |
<label class="error"><?php echo esc_html( $kad_consent_error ); ?></label> |
| 237 |
<?php } ?> |
| 238 |
</p> |
| 239 |
<?php } ?> |
| 240 |
<?php |
| 241 |
$spam_field = apply_filters( 'kadence-contact-spam-field', null ); |
| 242 |
$spam_field = apply_filters( 'kadence_contact_spam_field', $spam_field ); |
| 243 |
if ( ! empty( $spam_field ) && is_array( $spam_field ) ) { |
| 244 |
?> |
| 245 |
<p> |
| 246 |
<?php |
| 247 |
if ( isset( $spam_field['label'] ) && ! empty( $spam_field['label'] ) ) { |
| 248 |
echo wp_kses_post( $spam_field['label'] ); |
| 249 |
} |
| 250 |
if ( isset( $spam_field['input'] ) && ! empty( $spam_field['input'] ) ) { |
| 251 |
echo wp_kses_post( $spam_field['input'] ); |
| 252 |
} |
| 253 |
|
| 254 |
if ( isset( $spam_error ) ) { |
| 255 |
?> |
| 256 |
<label class="error"><?php echo esc_html( $spam_error ); ?></label> |
| 257 |
<?php } ?> |
| 258 |
</p> |
| 259 |
<?php } ?> |
| 260 |
<p> |
| 261 |
<?php wp_nonce_field( 'virtue_contact_nounce_action', 'virtue_contact_nounce' ); ?> |
| 262 |
<input type="submit" class="kad-btn kad-btn-primary" id="submit" value="<?php esc_attr_e( 'Send Email', 'virtue-toolkit' ); ?>" ></input> |
| 263 |
</p> |
| 264 |
</div><!-- /.contactform--> |
| 265 |
<input type="hidden" name="submitted" id="submitted" value="true" /> |
| 266 |
</form> |
| 267 |
<?php |
| 268 |
} |
| 269 |
?> |
| 270 |
</div><!--contactform--> |
| 271 |
<?php } ?> |
| 272 |
|