Skip to content

Instantly share code, notes, and snippets.

WordPress + HubSpot

A Tale of Two Mis-Capitalized Words

Lately we’ve run into some trouble here and there with the Gravity Forms Hubspot Add-On (and/or the Zapier... zap... thing) de-authenticating and losing its connection to the mothership. As a “workaround” we’re being asked to use HubSpot forms instead, but that solution sucks because then we lose all those sweet Gravity Forms styles we worked so hard on during development (not to mention whatever fancy backend stuff we did using filters/actions)

So, I did a little digging and I found that it’s actually super easy to integrate the entire site, forms and all, directly into HubSpot with no Gravity Forms add-on or Zapier integrations. The trick is that you need to install HubSpot’s official plugin: Contact Form Builder for WordPress – Conversion Tools by HubSpot. The title makes it sound like this is something you would use instead of Gravity Forms, but what it actually does is add the Hubspot tracking code to your site and aut

@antishow
antishow / debug.log
Created August 2, 2018 13:49
Output from write_log() at the end of the acf/update_field_group action
[01-Aug-2018 14:32:09 UTC] GRID DATA FIELD BEFORE:
[01-Aug-2018 14:32:09 UTC] Array
(
[ID] => 88
[key] => field_card_grid_data
[label] => Card Data
[name] => card_data
[prefix] => acf
[type] => repeater
[value] =>
@antishow
antishow / card_grid_data.php
Created August 2, 2018 13:48
Populate Grid Data repeater subfields with clones of all Card Layouts
<?php
/**
* Helper function to extract the Card Data field from the Card Grid field group
*/
function get_grid_data_field() {
$card_grid_field_group = acf_get_field_group('group_card_grid');
if (!$card_grid_field_group) {
return;
}
@antishow
antishow / card_grid_style.php
Last active August 2, 2018 13:43
Code to populate the Card Style field
<?php
/**
* Get all layouts with the "Card Layout:" prefix
*/
function get_card_layouts() {
$card_layouts = array_filter(acf_get_field_groups(), function($group) {
return strpos($group['title'], 'Card Layout:') === 0;
});
return array_values($card_layouts);
@antishow
antishow / group_card_grid.json
Created August 2, 2018 13:42
ACF Field Group JSON
{
"key": "group_card_grid",
"title": "Layout: Card Grid",
"fields": [
{
"key": "field_card_grid_style",
"label": "Card Style",
"name": "card_style",
"type": "select",
"instructions": "",

REDUCING Code Complexity

Reducers are an interesting and powerful tool in Javascript, but it can be difficult to come up with good examples that aren’t overly trivial or contrived to the point of uselessness. We use a LOT of Reducers in our boilerplate Resource Grid component, and Redux in general is pretty much built around the use of Reducers. They can be used for a lot more though! Like map and forEach, Array.reduce is a great way to process an entire set of data at once.

Wait, what’s a Reducer again?

A reducer is a function that works with Array.reduce to transform an array into some other value. This is very similar to Array.map, in that it’s used to process an array with a function, the difference is that instead of transforming from one Array to another, we’re going from an Array to some value.

When calling reduce on an array, you’ll pass in two things: your reducer and the start value. On the first call to the reducer, the function will be passed the start value and

@antishow
antishow / promises-and-schrodingers-async-op.md
Last active May 18, 2018 18:41
Promises and Schrodinger’s Asynchronous Operation

Promises and Schrodinger’s Asynchronous Operation

We’ve talked before about using Promises to write better asynchronous code and avoid “Callback Hell”, but it’s always a struggle to come up with a good example of Promise code that doesn’t feel super contrived.

BUT! Recently I made an update to the Duck Creek Content Exchange project that involved a change to one piece of logic in the middle of a chain of operations. In this moment, I knew my perfect Promise example had come.

Then I had to make yet another change that involved turning a simple synchronous operation into one that involved sometimes calling a third-party API, and I knew I made the right choice.

The Gist