Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary feedback button #456

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
68 changes: 46 additions & 22 deletions wp-content/mu-plugins/feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use \TANIOS\Airtable\Airtable;

// add_action('wp_ajax_feedback', 'FeedbackNYC\feedbackHandler');
// add_action('wp_ajax_nopriv_feedback', 'FeedbackNYC\feedbackHandler');
add_action('wp_ajax_feedback', 'FeedbackNYC\feedbackHandler');
add_action('wp_ajax_nopriv_feedback', 'FeedbackNYC\feedbackHandler');

/**
* Creates a record on an Airtable based on the feedback form submission.
Expand All @@ -14,29 +14,53 @@
*/
function feedbackHandler() {
$nonce = $_POST['feedback-nonce'];
if (defined('GRECAPTCHA_SITE_SECRET')) {
$recaptcha = [
'secret' => GRECAPTCHA_SITE_SECRET,
'response' => $_POST['g-recaptcha-response']
];
}

$headers = [
'Content-type: application/x-www-form-urlencoded',
];

$url = 'https://www.google.com/recaptcha/api/siteverify';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($recaptcha));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = json_decode(curl_exec($curl));
$responseResult = $response->success;

if (wp_verify_nonce($nonce, 'feedback')) {
try {
$client = get_airtable_client();
$feedback_fields = get_values_from_submission($_POST);
$airtable_record = create_record($feedback_fields, $client);

wp_send_json([
'success' => true,
'error' => 200,
'message' => __('Thank you for your feedback.'),
'retry' => false
]);
} catch (Exception $e) {
$message = $e->getMessage();

if ($responseResult == true) {
if (wp_verify_nonce($nonce, 'feedback')) {
try {
$client = get_airtable_client();
$feedback_fields = get_values_from_submission($_POST);
$airtable_record = create_record($feedback_fields, $client);

wp_send_json([
'success' => true,
'error' => 200,
'message' => __('Thank you for your feedback.'),
'retry' => false
]);
} catch (Exception $e) {
$message = $e->getMessage();

failure(400, $message);
}
} else {
$message = 'Feedback form nonce not verified';

failure(400, $message);
}
};
} else {
$message = 'Feedback form nonce not verified';

failure(400, $message);
};
failure(400, "User is a robot");
}
}

/**
Expand Down

This file was deleted.

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion wp-content/themes/access/assets/svg/icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion wp-content/themes/access/src/js/single-programs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env browser */

import StepByStep from 'modules/step-by-step';
// import 'modules/feedback';
import 'modules/feedback';
import 'modules/share-form';

(() => {
Expand Down
6 changes: 3 additions & 3 deletions wp-content/themes/access/views/programs/single.twig
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@
</p>
</footer>

{# {% include 'components/feedback.twig' with {this: post, action: shareAction} only %} #}
{% include 'components/feedback.twig' with {this: post, action: shareAction} only %}

<div class="sticky bottom-0 z-10">
{# {% if fn('defined', 'AIRTABLE_FEEDBACK_BASE_KEY') and fn('defined', 'AIRTABLE_FEEDBACK_API_KEY') %}
{% if fn('defined', 'AIRTABLE_FEEDBACK_BASE_KEY') and fn('defined', 'AIRTABLE_FEEDBACK_API_KEY') %}
<div class="wrap text-end pb-2">
<button aria-controls="aria-c-modal" aria-expanded="false" class="btn btn-small btn-tertiary" data-dialog="open" data-dialog-lock="true" data-js="dialog">{{ __('Feedback', 'accessnyctheme') }}</button>
</div>
{% endif %} #}
{% endif %}

{% if alert_sitewide %}
{% include 'objects/alert-banner.twig' with {this: alert_sitewide, active: true} only %}
Expand Down