Skip to content

Instantly share code, notes, and snippets.

Avatar

Thomas Griffin thomasgriffin

View GitHub Profile
@thomasgriffin
thomasgriffin / deletecustomvariable.js
Created Dec 9, 2015
OptinMonster Dynamic Text Replacement API - deleteCustomVariable
View deletecustomvariable.js
<script type="text/javascript">
var OptinMonsterCustomVariables = function(app) {
/**
* API method for deleting a custom variable. Must be accessed via the app object.
*
* @param string $key The custom variable to delete.
* @return null
*/
app.deleteCustomVariable('foo');
};
@thomasgriffin
thomasgriffin / hascustomvariables.js
Created Dec 9, 2015
OptinMonster Dynamic Text Replacement API - hasCustomVariables
View hascustomvariables.js
<script type="text/javascript">
var OptinMonsterCustomVariables = function(app) {
/**
* API method for checking if any custom variable has been registered.
* Must be accessed via the app object.
*
* @return bool True if any custom variable has been registered, false otherwise.
*/
app.hasCustomVariables();
};
@thomasgriffin
thomasgriffin / hascustomvariable.js
Last active May 7, 2020
OptinMonster Dynamic Text Replacement API - hasCustomVariable
View hascustomvariable.js
<script type="text/javascript">
var OptinMonsterCustomVariables = function(app) {
/**
* API method for checking if a custom variable has been registered.
* Must be accessed via the app object.
*
* @param string $key The custom variable key to check.
* @return bool True if the custom variable exists, false otherwise.
*/
app.hasCustomVariable('foo');
@thomasgriffin
thomasgriffin / getcustomvariables.js
Created Dec 9, 2015
OptinMonster Dynamic Text Replacement API - getCustomVariables
View getcustomvariables.js
<script type="text/javascript">
var OptinMonsterCustomVariables = function(app) {
/**
* API method for retrieving all custom variables. Must be accessed via the app object.
*
* @return object A JavaScript object with key/value pairs for custom variables.
*/
app.getCustomVariables();
};
</script>
@thomasgriffin
thomasgriffin / getcustomvariable.js
Created Dec 9, 2015
OptinMonster Dynamic Text Replacement API - getCustomVariable
View getcustomvariable.js
<script type="text/javascript">
var OptinMonsterCustomVariables = function(app) {
/**
* API method for retrieving a custom variable. Must be accessed via the app object.
*
* @param string $key The custom variable key to retrieve.
* @return string|bool The value of the custom variable key or false if not found.
*/
app.getCustomVariable('foo');
};
@thomasgriffin
thomasgriffin / setcustomvariable.js
Last active May 7, 2020
OptinMonster Dynamic Text Replacement API - setCustomVariable
View setcustomvariable.js
<script type="text/javascript">
var OptinMonsterCustomVariables = function(app) {
/**
* API method for setting a custom variable. Must be accessed via the app object.
*
* @param string $key The custom variable key to set.
* @param string $value The custom variable value to set for the key.
* @return null
*/
app.setCustomVariable('foo', 'bar');
@thomasgriffin
thomasgriffin / gist:4159035
Last active Dec 30, 2019
Add custom post types to search results in WordPress.
View gist:4159035
<?php
add_filter( 'pre_get_posts', 'tgm_io_cpt_search' );
/**
* This function modifies the main WordPress query to include an array of
* post types instead of the default 'post' post type.
*
* @param object $query The original query.
* @return object $query The amended query.
*/
function tgm_io_cpt_search( $query ) {
@thomasgriffin
thomasgriffin / gist:891c405de8b6475a6772
Created Nov 21, 2014
Redirect any non-business email addresses to a custom page.
View gist:891c405de8b6475a6772
add_action( 'wp_footer', 'tgm_om_force_specific_email_address', 999 );
function tgm_om_force_specific_email_address() {
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$(document).on('OptinMonsterBeforeOptin', function(e, data){
// Grab the email address submitted by the user.
var email = $('#om-' + data.optin).find('input[type="email"]').val();
View gist:3504420
<?php
add_filter( 'gform_ajax_spinner_url', 'tgm_io_custom_gforms_spinner' );
/**
* Changes the default Gravity Forms AJAX spinner.
*
* @since 1.0.0
*
* @param string $src The default spinner URL.
* @return string $src The new spinner URL.
*/
View gist:4253190
<?php
add_filter( 'wp_nav_menu_objects', 'tgm_filter_menu_class' );
/**
* Filters the first and last nav menu objects in your menus
* to add custom classes.
*
* @since 1.0.0
*
* @param object $objects An array of nav menu objects.
* @return object $objects Amended array of nav menu objects with new class.
You can’t perform that action at this time.