Skip to content

Instantly share code, notes, and snippets.

View jerclarke's full-sized avatar
🌿

Jer Clarke they/them jerclarke

🌿
View GitHub Profile
@jerclarke
jerclarke / gist:1725905
Created February 2, 2012 21:32
Patch to fix checkbox display in Custom Metadata Manager WordPress Plugin
Index: custom_metadata.php
===================================================================
--- custom_metadata.php (revision 499358)
+++ custom_metadata.php (working copy)
@@ -871,12 +871,22 @@
else $field_id = $field_slug;
$readonly_str = ($field->readonly) ? 'readonly="readonly" ' : '';
+
@jerclarke
jerclarke / google-analyticator.php
Last active December 12, 2015 04:59
Google Analyticator (WordPress Plugin) v6.4.2 main file. Patched to fix saving of array-based settings for roles-that-see-dashboard-widget and roles-excluded-from-tracking. See "Revisions" to see what I changed. NOTE: I edited the plugin version and description to reflect that this is a patched version. You should see the update notice when a ne…
<?php
/*
* Plugin Name: Google Analyticator
* Version: 6.4.2.1.jer
* Plugin URI: http://wordpress.org/extend/plugins/google-analyticator/
* Description: Adds the necessary JavaScript code to enable <a href="http://www.google.com/analytics/">Google's Analytics</a>. After enabling this plugin you need to authenticate with Google, then select your domain and you're set. PATCHED_BY_JEREMY_CLARKE: Fixed issue with array-based options (roles to hide, roles to see dashboard widget) being stomped by overzealous kses filtering.
* Author: Video User Manuals
* Author URI: http://www.videousermanuals.com
* Text Domain: google-analyticator
*/
@jerclarke
jerclarke / Google_OAuth2.php
Last active February 17, 2018 19:40
Google_OAuth2.php from Google Analyticator v.6.4.3 with modifications to fix "Fatal error: Uncaught exception 'Google_AuthException'" See revision history for details on what I changed to fix the error. See this wordpress.org support forum posting about the issue: http://wordpress.org/support/topic/solution-for-fatal-error-uncaught-exception-goo…
<?php
/*
* Copyright 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@jerclarke
jerclarke / gist:576db68a4030a87ed234
Created July 22, 2014 21:47
echor() - Beutified variable/array/object output for debugging
/**
* Beutified variable/array/object output for debugging
*
* Intellegently determines the type of data in $input and
* prints out a pleaseant rendering of its contents.
*
* Distinguishes between arrays, objects, strings, integers and booleans
* Otherwise states its not sure what $input is.
*
* $args is an array of optional parameters:
@jerclarke
jerclarke / gist:213de46aa04c95592d3e
Created April 21, 2015 16:32
WordPress: Enable [shortcode] shortcode (real thing) in core WP image captions
<?php
/**
* Filter Caption shortcode attributes to enable the [shortcode] shortcode inside caption text
*
* WP doesn't run do_shortcode on the 'caption' text value parsed out of [caption], which means
* the [shortcode] shortcode doesn't work.
*
* We want [shortcode] to work but not necessarily any other shortcodes, so we will run do_shortcode()
* only if [shortcode] is present. Running do_shortcode() this way will process all shortcodes
* so beware any captions that for some reason also have a bad shortcode that will break formatting.
@jerclarke
jerclarke / gist:380897120a928862d93e
Created April 30, 2015 20:00
Filter Geo Mashup to include 'inherit' status when querying for 'attachment' posts
<?php
/**
* Filter geo mashup 'where' clause to insert 'inherit' as a valid status when attachments are being queried
*
* By default geo mashup locations queries (i.e. posts queried inside the map) include the 'attachment' post type
* along with posts when post_type=all BUT it only checks for post_status=publish, so attachments are never part
* of the returned results.
*
* This function filters the 'where' clause of the locations query to add 'inherit' as a valid post status when
* attachments are a valid post type. It won't do anything if attachments aren't already part of the query and
@jerclarke
jerclarke / gist:6d5b5bd8179499d12dcc
Created June 15, 2015 12:41
WTF Facebook OG tags that don't work and the meta tags that do
<?php
/**
* Insert site_name meta tag
*/
$site_name = gv_get_site_name();
$site_name_escaped = esc_attr($site_name);
$output .= "<meta property=\"og:site_name\" content=\"$site_name_escaped\" />\n";
// WTF: Also add meta name=cre as site name because NYT uses it and facebook seems to pick it up from them despite it not being in the docs
$output .= "<meta name='cre' content='$site_name_escaped' />\n";
@jerclarke
jerclarke / php-error-test.php
Created March 30, 2016 17:41
Simple PHP script to test display of errors including a fix for displaying inline errors in HHVM
<?php
/*
* Test display of errors in HHVM/PHP
*
* In HHVM and often in normal PHP I want to see notices and errors inline to the
* document. This script tests the ability to make errors visible and has a solution
* that so far works in all the modern PHP and HHVM versions I tried.
*/
echo "<h1>Error test document for PHP</h1>";
<?php
/*
* Simple function to intentionally crash HHVM and trigger our PHP-FPM fallback
*
* For whatever reason having two "default:"" clauses in a switch statement crashes HHVM but not PHP-FPM
* In HHVM error logs it causes: Fatal error: Switch statements may only contain one default: clause in /var/www/sites/monittest/index.php on line XX
*
* This can be used to intentionally trigger a fallback from HHVM to PHP-FPM in our system, which normally happens
* to avoid scripts with rare HHVM bugs from crashing completely to WSOD, and to keep the server mostly working
* if HHVM failed completely, which has happened a couple of times.
@jerclarke
jerclarke / edit-flow-autosave-comments-not-a-real-plugin.php
Created October 6, 2016 20:55
Edit Flow "plugin" (hack) to autosave unsubmitted Editorial Comment text when post is saved
<?php
/**
* EDIT FLOW: wp_insert_post action to autosave "draft" editorial comments in post meta field
*
* Currently (2016-10-06) Edit Flow has no handling of unsubmitted editorial comments in the textarea
* when the post is saved, so saving your post deletes your comment unless you submitted it, which is awful.
*
* This function hooks into wp_insert_post where the value of the textarea is present (but ignored by default)
* and if found, saves the text (and ID of parent comment if it was a specific reply) to a postmeta field
* keyed on the user who saves the post.