Skip to content

Instantly share code, notes, and snippets.

View bigdawggi's full-sized avatar

Matthew Richmond bigdawggi

  • Bigdawggi Co
  • Island Park, ID
View GitHub Profile
@bigdawggi
bigdawggi / README.txt
Created October 24, 2011 19:31 — forked from alexkingorg/wp-switch-to-post.php
switch_to_post() stack implementation (similar to switch_to_blog()) for WordPress
# Switch to Post README
## Overview
switch_to_post() stack implementation (similar to switch_to_blog()) for WordPress
## Questions
1. Do we want to still switch to post if the get_post fails?
2. Have a (bool) return value based on get_post?
## Test Steps
@bigdawggi
bigdawggi / Outbound Link Tracking - Google Analytics.js
Created November 22, 2011 23:02
jQuery-based outbound link tracking with cases for new window as well as same window locations
@bigdawggi
bigdawggi / friendly-exception.php
Created January 10, 2012 01:51
Friendly Exceptions
<?php
class Friendly_Exception extends Exception {
public function __construct($friendly_message, $technical_message = '', $code = 0) {
$this->friendly_message = $friendly_message;
$this->technical_message = $technical_message;
parent::__construct($friendly_message, $code);
}
@bigdawggi
bigdawggi / gist:2474388
Created April 23, 2012 22:53
String Arrays to PHP arrays
<?php
echo '<pre>';
class string_array_parser {
function parse_string($key, $value) {
// no limit, no empty values in returned array
$splits = preg_split('[\[|\]]', $key, -1, PREG_SPLIT_NO_EMPTY);
// Get the first element, that will be the name of the actual meta key
@bigdawggi
bigdawggi / gist:4062892
Created November 12, 2012 23:53
Import featured image on demand
add_filter(
'get_post_metadata',
array($this, 'maybe_grab_simpleview_photo_for_featured_image'),
10,
4
);
/**
* On the request for a post's featured image, it goes and retrieves it from the 3rd party site,
* attaches it to the current post, then sets it as a featured image. This only happens once per post.
@bigdawggi
bigdawggi / basic-og-image-fallback.php
Created January 3, 2013 15:46
Super-simple fall-back open graph image for your WordPress blog. I didn't want/need a whole plugin for this, just wanted a simple og:image fall-back for my site.
<?php
// Add this to your functions.php file
function mgr_og_image_fallback() {
if (!has_post_thumbnail()) {
// Replace the image URL unless you want my mug as your image for Open Graph Image ;)
?>
<meta property="og:image" content="http://i1.wp.com/matthewgrichmond.com/files/2012/03/matt.jpg?resize=310%2C180" />
<?php
}
@bigdawggi
bigdawggi / quick-and-dirty-cache-expire-test.php
Created February 1, 2013 18:52
Quick and dirty cache expiration testing. I placed in functions.php just for a quick place to put it. Refresh the page, and it should change every 10 seconds.
<?php
if (isset($_GET['matt'])) {
$cur_time = time();
$cache = wp_cache_get('matt-time', 'matt');
if ($cache !== false) {
echo '<pre>Found'.print_r($cache, 1).'</pre>';
}
else {
wp_cache_set('matt-time', $cur_time, 'matt', 10);
@bigdawggi
bigdawggi / mailtrap-filter.php
Last active June 3, 2019 19:11
Mailtrap filter for WordPress
/**
* Routes all email from WP installation to specific Mailtrap
* account inbox.
*
* All you need to do is change the "Username" and "Password"
* settings to the appropriate box in Mailtrap. Then all
* mail **should** be routed to that box. Exceptions would
* be other functionality that overwrite the wp_mail() functions
* and may not use this filter, or other filters that change
* this behavior after we set it, or millions of other things.
@bigdawggi
bigdawggi / wp-cli-active-themes-across-network
Last active February 16, 2023 05:54
WP-CLI commands to get the active themes across a WordPress blog network (single site ID with multiple blogs for the site)
# Be sure to change or omit the --network parameter; it defaults to 1.
wp site list --network=4 --field=url | while read line; do wp theme list --status=active --field=name --url=$line >> /tmp/wpcli-themes.txt; done && sort /tmp/wpcli-themes.txt | uniq -c
@bigdawggi
bigdawggi / fast404.sublime-snippet
Created January 8, 2015 19:10
Sublime Text Snippet: fast404
<snippet>
<content><![CDATA[
# Return Fast 404 for assets that don't exist
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .(jpe?g|gif|png|css|js)\$ - [L,R=404]
</IfModule>