Skip to content

Instantly share code, notes, and snippets.

View Veraxus's full-sized avatar
🌅
Surviving

Dutch van Andel Veraxus

🌅
Surviving
View GitHub Profile
@Veraxus
Veraxus / React + Gravity Forms + WordPress.md
Last active June 14, 2020 16:37
Two approaches for allowing Gravity Forms (or other plugins) to work seamlessly when building a React frontend for WordPress

This question may be old, but building React applications on WordPress "facelessly" using the WP REST API is gaining momentum in a huge way (it's even the future for WordPress core), so this is bound to come up more and more.

So what is happening is that Gravity Forms sets it's form action by via $action = remove_query_arg( 'gf_token' ); which in turn calls add_query_arg() which then calls $uri = $_SERVER['REQUEST_URI']; - this means that when you use React to display WordPress content containing a Gravity Form, the form's action is set to the REST endpoint called, not the content's permalink. Whoops!

Although Gravity Forms has an bona-fide WP REST API add-on in works, there are two solid options I've been able to suss out so far:

Option 1 - Fully Headless

Ensure you have a REST route that accepts POST (I suggest just reusing a GET route) and add do_action('wp'); to your route callback. You could add it earlier if you like, like the rest_api_init hook. This will ensure that Gravity Forms gets

@Veraxus
Veraxus / wp-local-flagging.php
Created November 16, 2016 22:00
A WordPress plugin that shows a small green label during local development.
<?php
/*
Plugin Name: Local Flagging
Plugin URI:
Description: Shows a flag on the page when the site is detected to be local.
Version: 1.5
Author: Matt van Andel
Author URI:
License: GPL2
Text Domain:
@Veraxus
Veraxus / wp-aws-ses.php
Last active May 22, 2018 02:33
WordPress SMTP AWS SES Setup
<?php
/*
Plugin Name: SMTP Configuration
Plugin URI:
Description: Force WordPress to use SMTP settings for AWS SES.
Version: 1.0
Author: Matt van Andel
Author URI: http://mattvanandel.com
License: GPLv2 or later
*/