Skip to content

Instantly share code, notes, and snippets.

View thomasgriffin's full-sized avatar
👋

Thomas Griffin thomasgriffin

👋
View GitHub Profile
@thomasgriffin
thomasgriffin / gist:c4e9e0d2f8254f6c4cf9
Created May 4, 2015 11:33
Exclude optin if on a certain category.
<?php
add_filter( 'optin_monster_api_output', 'tgm_om_filter_lightbox_by_category', 10, 4 );
function tgm_om_filter_lightbox_by_category( $optins, $optin, $fields, $post_id ) {
// If in a particular category, remove the lightbox.
$cat_exc = 362; // Replace with the category ID to target.
$slug = 'sjdfhsjakdkg'; // Replace with the unique slug for the lightbox you want to remove.
$categories = wp_get_object_terms( $post_id, 'category', array( 'fields' => 'ids' ) );
foreach ( (array) $categories as $category_id ) {
if ( $category_id && $category_id == $cat_exc && in_array( $slug, $optins ) ) {
@thomasgriffin
thomasgriffin / api-helper.php
Last active March 13, 2019 13:46
API Helper to be used during API requests. Should be used as a must-use plugin in WordPress.
<?php
/**
* Plugin Name: TGM API Helper
* Plugin URI: https://thomasgriffin.io
* Description: Whitelists the plugins to be loaded during API requests to reduce overhead.
* Author: Thomas Griffin
* Author URI: https://thomasgriffin.io
* Version: 1.0.0
*/
@thomasgriffin
thomasgriffin / gist:984c3e2dfa4b7bc24578
Created February 18, 2015 15:14
Updates all slides in all sliders and sets the status to active in Soliloquy.
<?php
add_action( 'wp_loaded', 'tgm_soliloquy_set_slides_to_published' );
function tgm_soliloquy_set_slides_to_published() {
if ( ! class_exists( 'Soliloquy' ) ) {
return;
}
$sliders = Soliloquy::get_instance()->_get_sliders();
foreach ( (array) $sliders as $slider ) {
<?php // Do not include this opening tag.
add_filter( 'optin_monster_data', 'tgm_om_disable_tracking' );
function tgm_om_disable_tracking( $data ) {
$data['tracked'] = true;
return $data;
}
(function() {
tinymce.create('tinymce.plugins.typekit', {
init: function(ed, url) {
ed.onPreInit.add(function(ed) {
// Get the iframe.
var doc = ed.getDoc();
// Create the script to inject into the header asynchronously.
var typekit = 'xxxxxx', // PLACE YOUR TYPEKIT KIT ID HERE!
jscript = "!function(){var t={kitId:\"" + typekit + "\"},e=!1,a=document.createElement(\"script\");a.src=\"//use.typekit.net/\"+t.kitId+\".js\",a.type=\"text/javascript\",a.async=\"true\",a.onload=a.onreadystatechange=function(){var a=this.readyState;if(!(e||a&&\"complete\"!=a&&\"loaded\"!=a)){e=!0;try{Typekit.load(t)}catch(c){}}};var c=document.getElementsByTagName(\"script\")[0];c.parentNode.insertBefore(a,c)}();";
@thomasgriffin
thomasgriffin / typekit-load.php
Created December 27, 2014 00:50
Loads the TypeKit plugin into TinyMCE.
<?php // Do not include this opening PHP tag.
add_filter( 'mce_external_plugins', 'tgm_io_typekit_plugin' );
/**
* Adds an external TinyMCE plugin to be loaded into the TinyMCE editor.
*
* @since 1.0.0
*
* @param array $plugins Default array of plugins to be loaded by TinyMCE.
* @return array $plugins Amended array of plugins to be loaded by TinyMCE.
*/
@thomasgriffin
thomasgriffin / typekit.js
Created December 27, 2014 00:46
Load a TypeKit Font Kit inside of the TinyMCE Visual Editor in WordPress.
(function() {
tinymce.create('tinymce.plugins.typekit', {
init: function(ed, url) {
ed.onPreInit.add(function(ed) {
// Get the iframe.
var doc = ed.getDoc();
// Create the script to inject into the header asynchronously.
var jscript = "(function() {
var config = {
@thomasgriffin
thomasgriffin / gist:e82ac5bb6d66734b6112
Created December 15, 2014 16:46
Filter data sent to Mailchimp (send IP address).
<?php
add_filter( 'optin_monster_pre_optin_mailchimp', 'tgm_om_custom_mailchimp_data', 10, 4 );
/**
* Filter the data sent to Mailchimp.
*
* See here for more info on what is passed: https://apidocs.mailchimp.com/api/2.0/lists/subscribe.php
*
* @param array $data Array of data being sent to Mailchimp.
* @param array $lead Array of lead data captured from the optin submission.
* @param string $list_id The unique list ID to subscribe the lead to.
@thomasgriffin
thomasgriffin / gist:d9653e3abf9ee80d52ac
Created December 13, 2014 12:42
Change the comment link in WordPress
<?php
add_filter( 'get_comments_link', 'tgm_io_change_comment_link', 99 );
/**
* Filters the comment link to have the hash match a different
* comment system, such as Disqus.
*
* @since 1.0.0
*
* @global object $post The current post object.
* @param string $link The default comment link.
@thomasgriffin
thomasgriffin / gist:525dc80a20cb69c7e8bf
Created December 11, 2014 20:00
Turn off tracking in OptinMonster.
<?php
add_filter( 'optin_monster_data', 'tgm_om_turn_off_tracking' );
function tgm_om_turn_off_tracking( $data ) {
$data['tracked'] = true;
return $data;
}