Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Runs after a review is submitted
- *
- * IMPORTANT: In order to use this, you will need to edit the @todo part
- * and handle inserting the review HTML into the page yourself.
- */
- add_filter('site-reviews/enqueue/public/inline-script/after', function () {
- return "GLSR.Event.on('site-reviews/form/handle', (data) => {
- let request = {
- body: 'action=get_review&id='+data.review.ID,
- headers: { 'Content-Type': 'application/x-www-form-urlencoded;' },
- method: 'POST',
- };
- fetch(GLSR.ajaxurl, request)
- .then(response => response.json())
- .then(response => {
- if (response.success) {
- const reviewHtml = response.data;
- // @todo insert the reviewHtml string into your page
- }
- })
- .catch(error => console.error(error))
- })";
- });
- /**
- * Get the review HTML with AJAX
- */
- function glsr_ajax_get_review() {
- $review = glsr_get_review(filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT));
- if ($review->isValid()) {
- wp_send_json_success((string) $review);
- }
- wp_send_json_error();
- }
- add_action('wp_ajax_get_review', 'glsr_ajax_get_review');
- add_action('wp_ajax_nopriv_get_review', 'glsr_ajax_get_review');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement