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 / gist:bf29119292761239924b
Created February 3, 2015 22:28
Code to run WP Cron at midnight local time
if ( ! wp_next_scheduled( 'tmbr_daily_at_midnight_actions' ) ) {
$local_time_to_run = 'midnight';
$timestamp = strtotime( $local_time_to_run ) - ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
wp_schedule_event(
$timestamp,
'daily',
'tmbr_daily_at_midnight_actions'
);
}
@bigdawggi
bigdawggi / wpconfig.sublime-snippet
Last active August 29, 2015 14:13
wp-config.php template snippet
<snippet>
<content><![CDATA[
<?php
// Should only need to modify this line
define( 'DB_NAME', 'tmbr_${1:install_name}' );
// Rest of these can likely stay the same
define( 'WP_DEBUG', true );
define( 'WP_HOME', 'http://' . \$_SERVER['HTTP_HOST'] );
@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>
@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 / 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 / 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 / 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 / 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 / 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 / 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);
}