Skip to content

Instantly share code, notes, and snippets.

View jtsternberg's full-sized avatar
😎
Awesome Motive-ing

Justin Sternberg jtsternberg

😎
Awesome Motive-ing
View GitHub Profile
@jtsternberg
jtsternberg / setcustomvariable.js
Last active May 7, 2020 21:54 — forked from thomasgriffin/setcustomvariable.js
OptinMonster Dynamic Text Replacement API - setCustomVariable
<script type="text/javascript">
document.addEventListener('om.Dtr.init', function(event) {
/**
* API method for setting a custom variable. Must be accessed via the Dtr object.
*
* @param string $key The custom variable key to set.
* @param string $value The custom variable value to set for the key.
* @return null
*/
event.detail.Dtr.setCustomVariable('foo', 'bar');
@jtsternberg
jtsternberg / query-args-anon-function.js
Created April 15, 2020 15:02
Output query args in console
(function (qs) {
var query = (qs || window.location.search).substring(1),
bits = query ? query.split('&').map(function (params) {
var p = params.split('=')
return [ p[0], p[1] ? decodeURIComponent(p[1]) : p[1] ]
}) : [],
index = -1,
result = {},
pair
@jtsternberg
jtsternberg / wpforms-to-optin-monster.php
Last active December 5, 2019 20:10
Automatically trigger an OptinMonster form to show, filled out, when an WP Form is submitted.
<?php
/*
* Plugin Name: WP Forms to OptinMonster
* Plugin URI: http://optinmonster.com
* Description: Automatically trigger an OptinMonster form to show, filled out, when an WP Form is submitted.
* Version: 0.1.0
* Author: Justin Sternberg
* Author URI: http://optinmonster.com
*/
@jtsternberg
jtsternberg / om-image-data-attribute.html
Created December 2, 2019 21:57
Add pinterest no-pin data attribute to OptinMonster-loaded images
<script type="text/javascript">
document.addEventListener('om.Campaign.load', function(event) {
var slug = event.detail.Campaign.id;
var images = document.querySelectorAll('#om-' + slug + ' img');
if ( images ) {
images.forEach(function(el) {
el.setAttribute('data-pin-nopin', true);
});
}
});
@jtsternberg
jtsternberg / cmb2-register-reset-field.php
Last active November 11, 2019 18:00
replace CMB2 register_rest_field handlers with our own
<?php
/**
* Registers a new post type
* @uses $wp_post_types Inserts new post type object into the list
*
* @param string Post type key, must not exceed 20 characters
* @param array|string See optional args description above.
* @return object|WP_Error the registered post type object, or an error object
*/
@jtsternberg
jtsternberg / filter-om-campaigns-by-name.php
Last active March 14, 2019 19:48
Filter OptinMonster campaigns loaded into WordPress by name
<?php
function filter_om_campaigns_by_name( $campaigns, $save ) {
// Make sure this is the refresh request and that we have data.
if ( ! isset( $campaigns->success ) && ! empty( $campaigns ) ) {
// Loop through the campaigns
foreach ( (array) $campaigns as $slug => $campaign ) {
@jtsternberg
jtsternberg / am-ascii.html
Last active February 4, 2019 21:16
AwesomeMotive ascii
<pre>
````````````````````````````````````````````````````````````````````````````````````````````````````
````````````````````````````````````````````````````````````````````````````````````````````````````
````````````````````````````````````````````````````````````````````````````````````````````````````
````````````````````````````````````````````````````````````````````````````````````````````````````
````````````````````````````````````````````````````````````````````````````````````````````````````
````````````````````````````````````````````````````````````````````````````````````````````````````
````````````````````````````````````````````````````````````````````````````````````````````````````
````````````````````````````````````````````````````````````````````````````````````````````````````
@jtsternberg
jtsternberg / om-webhook-arbitrary-data.html
Last active September 1, 2020 22:09
send arbitrary to the webhook via the debugInfo field
<script>
document.addEventListener('om.Optin.init.submit', function( evt ) {
// Only do this for a specific campaign
if ( '<slug>' !== evt.detail.Campaign.id ) {
return;
}
var meta = { products_form: jQuery(document.forms.products_form).serialize() };
@jtsternberg
jtsternberg / add-x++-language-to-cpt-plugin.php
Created January 16, 2019 14:58
Add additional languages to code-snippet-cpt plugin
<?php
add_action( 'admin_init', function() {
$exists = get_term_by( 'slug', 'xpp', $taxonomy );
if ( empty( $exists ) ) {
$result = wp_insert_term( 'X++', 'languages', array( 'slug' => 'xpp' ) );
wp_die( '<xmp>'. __LINE__ .') $result: '. print_r( $result, true ) .'</xmp>', 'Debug' );
}
wp_die( '<xmp>'. __LINE__ .') $exists: '. print_r( $exists, true ) .'</xmp>', 'Debug' );
} );
@jtsternberg
jtsternberg / meh-rathon-countdown-alarm.js
Last active November 18, 2021 19:51
meh.com meh-RATHON! countdown alarm
clear();
var cdSettings = {
debug: true,
evt: null,
audio: null,
audioUrl: 'https://jtsternberg.com/file-drop/analog-watch-alarm_daniel-simion.mp3',
secondsLeft: 0,
timeLeft: 0,
log: true,
alarming: false,