Skip to content

Instantly share code, notes, and snippets.

View bhubbard's full-sized avatar
:octocat:
Hello

Brandon Hubbard bhubbard

:octocat:
Hello
View GitHub Profile
@bhubbard
bhubbard / ajax_class.php
Created September 18, 2021 02:45 — forked from sfgarza/ajax_class.php
Boilerplate code for making AJAX calls to wordpress.
<?php
if (!defined('ABSPATH')) {
exit;
}
class ajax_class
{
public function __construct()
{
//Hook = 'wp_ajax_{$action}' where $action must equal the AJAX request's 'action' property.
@crtag
crtag / hubspot-workflow-create-company.js
Last active October 13, 2020 05:52
Hubspot workflow Node JS webhook to create a company record via API call.
// TODO: configure your own hubspot client
/**
* This webhook is triggered by Hubspot workflow and receives a full Hubspot contact object
* to create the company for. It does expect company name property, but will default
* company name to contact `${firstname} ${lastname} construct
*
*/
module.exports = async (req, res) => {
@gzalinski
gzalinski / HubSpot & GravityForms
Created March 16, 2020 11:46
HubSpot CURL for Gravity Form
function curl_to_hubspot($entry, $str_post, $form_ID){
$hubspotutk = $_COOKIE['hubspotutk'];
$portalID = '******'; //HubSpot USER ID
$hs_context = array(
'hutk' => $hubspotutk,
'ipAddress' => $entry['ip'],
'pageURL' => $entry['source_url'],
'pageName' => get_the_title( $entry['post_id'])
@brenes
brenes / pagespeed_code.gs
Last active December 29, 2022 16:23
Page SPeed monitorization through Google Spreadsheet
// This script is based on https://ithoughthecamewithyou.com/post/automate-google-pagespeed-insights-with-apps-script
// STEP 0: Create a spreadsheet document on Google Drive, go to the code editor
// (in spanish "Editor de la secuencia de comandos").
// Then paste this code and modify it.
// STEP 1: Insert your pagespeed API KEY
var pageSpeedApiKey = '';
// STEP 2: Insert the monitored URL
@RiFi2k
RiFi2k / removeContent.js
Created June 21, 2019 18:04
Cloudflare Worker Function to find and replace content on a page
addEventListener("fetch", event => {
event.respondWith(handle(event.request))
})
async function handle(request) {
// Fetch from origin server.
let response = await fetch(request)
// Make sure we only modify text, not images.
let type = response.headers.get("Content-Type") || ""

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

@robertuniqid
robertuniqid / example.php
Created January 8, 2019 11:07
PHP WordPress Example Nested parent->id mapping
<?php
/**
* If WordPress will ever work smoothly with procedures, we want to refactor this.
* @param $search_term
* @return array
*/
function example_nested_parent_map_search( $search_term ) {
global $wpdb;
@n-ts
n-ts / worker.js
Created October 3, 2018 20:21
Cloudflare Workers - Load balancing to nearest datacenter from current POP
/*
--------------------------------------------------------
Please note that this grouping is just for example...
You can rearrange POPs, remove or add dacaneters according to your needs.
--------------------------------------------------------
First, we have to get all Cloudflare POP codes (three letter airport codes) from https://www.cloudflarestatus.com/
North America is routed to Chigaco datacenter;
Europe, Africa and Middle East is routed to Amsterdam datacenter;
@jakebellacera
jakebellacera / hubspot-adwords-gclid-tracking.js
Last active December 21, 2022 00:56
Simple HubSpot gclid tracking code integration
// The script below will ensure that gclid parameters are associated with
// contacts in HubSpot.
//
// A few things are required before this script will work:
//
// * You will need to have the HubSpot tracking code installed on the page. A
// few modifications will be required if you don't have the tracking code
// installed. Additionally, you will lose out on the built-in cross-domain
// features that the hubspot tracking code uses to store cookies.
// * You will need to have this script installed on every page.
@icodeforlove
icodeforlove / worker.js
Last active May 31, 2018 00:02
GDPR Block All European Countries (Cloudflare Worker)
const BLOCKED_COUNTRIES = [
'AL', 'AD', 'AM', 'AT', 'BY', 'BE', 'BA', 'BG', 'CH', 'CY', 'CZ', 'DE',
'DK', 'EE', 'ES', 'FO', 'FI', 'FR', 'GB', 'GE', 'GI', 'GR', 'HU', 'HR',
'IE', 'IS', 'IT', 'LT', 'LU', 'LV', 'MC', 'MK', 'MT', 'NO', 'NL', 'PL',
'PT', 'RO', 'RU', 'SE', 'SI', 'SK', 'SM', 'TR', 'UA', 'VA'
];
addEventListener('fetch', event => {
event.respondWith((async request => {
let country = request.headers.get('CF-IpCountry'),