Skip to content

Instantly share code, notes, and snippets.

View thomasgriffin's full-sized avatar
👋

Thomas Griffin thomasgriffin

👋
View GitHub Profile
@thomasgriffin
thomasgriffin / setcustomvariable.js
Last active May 7, 2020 21:47
OptinMonster Dynamic Text Replacement API - setCustomVariable
<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 December 30, 2019 18:27
Add custom post types to search results in WordPress.
<?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 November 21, 2014 20:16
Redirect any non-business email addresses to a custom page.
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();
<?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.
*/
<?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.
@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:4733283
Created February 7, 2013 19:05
Map subdomains to URLs in nginx with WordPress.
server {
listen 80;
listen 443 ssl;
server_name ~^(?<user>[a-zA-Z0-9-]+)\.example\.com$;
location / {
resolver 8.8.8.8;
rewrite ^([^.]*[^/])$ $1/ permanent;
proxy_pass_header Set-Cookie;
proxy_pass $scheme://example.com/user/$user$request_uri;
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '532160876956612',
autoLogAppEvents : true,
xfbml : true,
version : 'v3.2'
});
};
<?php
add_filter( 'jpeg_quality', 'tgm_image_full_quality' );
add_filter( 'wp_editor_set_quality', 'tgm_image_full_quality' );
/**
* Filters the image quality for thumbnails to be at the highest ratio possible.
*
* Supports the new 'wp_editor_set_quality' filter added in WP 3.5.
*
* @since 1.0.0
*
<?php
// If plugins_api isn't available, load the file that holds the function.
if ( ! function_exists( 'plugins_api' ) ) {
require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
}
// Prepare our query.
$api = plugins_api( 'query_plugins',
array(
'user' => 'griffinjt'