function fu_recaptcha_check_submission($should_process, $layout) { // Recaptcha is enabled but payload is missing g-recaptcha-response field // or it's empty if (!isset($_POST['g-recaptcha-response']) || !$_POST['g-recaptcha-response']) { return false; } $req = wp_remote_post('https://www.google.com/recaptcha/api/siteverify', array('body' => array('secret' => fu_get_option('recaptcha_secret_key'), 'response' => sanitize_text_field($_POST['g-recaptcha-response']), 'remoteip' => $_SERVER['REMOTE_ADDR']), 'timeout' => 3)); // Request failed, fail the check // Because we have no means to verify if it's a valid submission if (is_wp_error($req)) { return false; } $res = json_decode(wp_remote_retrieve_body($req)); return $res->success; }
function fu_get_recaptcha_markup() { return '<div class="g-recaptcha" data-sitekey="' . esc_attr(fu_get_option('recaptcha_site_key')) . '"></div>'; }