Skip to content

Instantly share code, notes, and snippets.

View thomasgriffin's full-sized avatar
👋

Thomas Griffin thomasgriffin

👋
View GitHub Profile
@thomasgriffin
thomasgriffin / api-helper.php
Last active September 5, 2024 01:50
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 / 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 / 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.
*/
(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 / database-indexes.txt
Created November 22, 2023 12:30
Helpful indexes and SQL queries to add to make WordPress run faster.
alter table `wp_usermeta` add index `ndx_meta_key_meta_val1` (`meta_key`(40), `meta_value`(191));
alter table `wp_postmeta` add index `ndx_meta_key_meta_val1` (`meta_key`(40), `meta_value`(191));
alter table `wp_termmeta` add index `ndx_meta_key_meta_val1` (`meta_key`(40), `meta_value`(191));
alter table `wp_commentmeta` add index `ndx_meta_key_meta_val1` (`meta_key`(40), `meta_value`(191));
alter table `wp_edd_customermeta` add index `ndx_meta_key_meta_val1` (`meta_key`(40), `meta_value`(191));
alter table `wp_edd_licensemeta` add index `ndx_meta_key_meta_val1` (`meta_key`(40), `meta_value`(191));
alter table `wp_posts` add index `ndx_id_post_status_val1` (`id`, `post_status`);
SELECT 'autoloaded data in KiB' as name, ROUND(SUM(LENGTH(option_value))/ 1024) as value FROM wp_options WHERE autoload='yes'
UNION
@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;
}
@thomasgriffin
thomasgriffin / gist:7308584
Created November 4, 2013 20:17
Blank canvas for styling a Soliloquy slider.
<?php
add_action( 'tgmsp_before_slider_output', 'tgm_custom_slider_theme' );
function tgm_custom_slider_of_madness( $id ) {
// If not the proper slider ID, do nothing. Change to match your slider ID.
if ( '324' !== $id ) return;
// Dequeue the default styles.
wp_dequeue_style( 'soliloquy-style' );
@thomasgriffin
thomasgriffin / gist:4953041
Created February 14, 2013 14:04
My gift to you this Valentine's Day. Rendering custom attachment fields in the new media manager via Backbone.
/**
* The code below renders additional custom attachment fields into the
* new media manager.
*
* I am assuming you are using your own custom media modal frame. By
* extending the default Attachment.Details subview, we can append our
* custom fields to the default fields listed.
*
* In the initialize function, we ensure that our changes are always up
* to date by "listening" to our model's change event and updating the
<?php
function test_unoptimized_query() {
$time_start = microtime( true );
$posts = new WP_Query( array( 'posts_per_page' => -1 ) );
return number_format( microtime( true ) - $time_start, 10 );
}
function test_optimized_query() {
$time_start = microtime( true );
$posts = new WP_Query( array( 'posts_per_page' => -1, 'no_found_rows' => true ) );
@thomasgriffin
thomasgriffin / deletecustomvariable.js
Created December 9, 2015 21:47
OptinMonster Dynamic Text Replacement API - deleteCustomVariable
<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');
};