/wp-admin/plugins.php'; return; } if (!class_exists('acf') ) { echo 'ACF not activated. Make sure you activate the plugin in /wp-admin/plugins.php'; return; } $context = Timber::get_context(); if (is_page()) { $context['segments'] = Timber::get_posts(['post_type' => 'segment', 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'asc']); $context['post'] = new TimberPost(); $template = [$context['post']->_wp_page_template . '.twig', 'page-' . $context['post']->post_name . '.twig', 'page.twig']; } else if (is_post_type_archive('segment')) { $context['posts'] = new Timber\PostQuery(); $template = ['segment-archive.twig']; } else if (is_singular('segment')) { $context['post'] = new TimberPost(); $template = ['segment-single.twig']; } else if (is_search()) { $url = get_home_url(); wp_safe_redirect($url, 301); exit(); } else if (is_404()) { $template = ['errors/404.twig']; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { global $wp; $request = (object) array_map('stripslashes', $_POST); $referer = home_url($wp->request); $error = false; if (empty($request->name)) { $error = 'name'; } if (!filter_var($request->email, FILTER_VALIDATE_EMAIL)) { $error = 'email'; } if (!empty($request->url)) { $error = 'honeypot'; } if (!wp_verify_nonce($request->_wpnonce, 'contact')) { $error = 'nonce'; } if (!$error) { $endpoint = 'https://de225682ff99.rest.akismet.com/1.1/comment-check'; $data = ['blog' => 'https://www.ticketworks.nl', 'user_ip' => $_SERVER['REMOTE_ADDR'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referrer' => $_SERVER['HTTP_REFERER'], 'comment_type' => 'contact-form', 'comment_author' => $request->name, 'comment_author_email' => $request->email, 'comment_content' => $request->question]; $server_keys = array_fill_keys(['HTTP_HOST', 'HTTP_USER_AGENT', 'HTTP_ACCEPT', 'HTTP_ACCEPT_LANGUAGE', 'HTTP_ACCEPT_ENCODING', 'HTTP_ACCEPT_CHARSET', 'HTTP_KEEP_ALIVE', 'HTTP_REFERER', 'HTTP_CONNECTION', 'HTTP_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'REMOTE_ADDR', 'REMOTE_HOST', 'REMOTE_PORT', 'SERVER_PROTOCOL', 'REQUEST_METHOD'], 0); $server_data = array_intersect_key($_SERVER, $server_keys); $data = array_merge($server_data, $data); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $endpoint); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); $spam = ($response == 'true'); $error = $spam ? 'spam' : false; if (!$spam) { wp_mail(['janjaap@ticketworks.nl', 'service@ticketworks.nl'], 'Vraag van ' . $request->email, $request->question, ['From: contact@ticketworks.nl', 'Cc: ' . $request->name . ' <' . $request->email . '>']); wp_safe_redirect('/bedankt-voor-je-vraag'); exit(); } curl_close($ch); } wp_safe_redirect($referer . '/?error=' . $error); exit(); } Timber::render($template, $context); ?>