Skip to content

Instantly share code, notes, and snippets.

View Viper007Bond's full-sized avatar
😎
Writing Code

Alex Mills Viper007Bond

😎
Writing Code
View GitHub Profile
@Viper007Bond
Viper007Bond / gist:2025993
Created March 13, 2012 01:16
Graphing car mileage
<?php
/**
* All of this code is in a big class that implements things like meta boxes and
* tons of other stuff but for now here's the relevant functions.
*
* Note the custom post types and custom taxonomies are just in placeholder form.
* I haven't gone through and properly set the labels, etc. for them like I will
* when I release the plugin.
*/
@Viper007Bond
Viper007Bond / gist:2054188
Created March 17, 2012 01:31
Float Parsing Function Tests
<?php
// floatvalue() ended up working best most of the time, with only a few exceptions
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$floatvals = array(
'1,337.01',
'1,337',
'1337.01',
@Viper007Bond
Viper007Bond / gist:2314628
Created April 5, 2012 22:18
WordPress: Get all posts but only so many at a time
<?php
$query_args = array(
'foo' => 'bar',
'apple' => 'orange',
'posts_per_page' => 50,
'offset' => 0,
);
@Viper007Bond
Viper007Bond / file1.php
Created April 13, 2012 00:00
Multi-File Gist Test
<?php
$this = 'file1';
do_stuff();
?>
@Viper007Bond
Viper007Bond / gist:2417309
Created April 18, 2012 23:20
Spotify, Rdio, and Gist embeds for WordPress
<?php
# Spotify
wp_embed_register_handler( 'spotify', '#https?://open\.spotify\.com/.*#', 'spotify_embed_handler' );
add_shortcode( 'spotify', 'spotify_shortcode' );
if ( get_option('embed_autourls') )
add_filter( 'the_content', 'spotify_embed_ids', 7 );
<?php
/**
* This is a version of
* http://www.viper007bond.com/2011/09/20/code-snippet-add-a-link-to-latest-post-to-wordpress-nav-menu/
* that supports multiple placeholders. In this case, the placeholder fetches
* the latest post from a particular category.
*/
// Front end only, don't hack on the settings page
@Viper007Bond
Viper007Bond / gist:2778130
Created May 23, 2012 22:10
Check to see if an e-mail address has a Gravatar or not
<?php
function sunset_has_gravatar( $email ) {
$hash = md5( strtolower( trim( $email ) ) );
// If not in the cache, check again
if ( false === $has_gravatar = wp_cache_get( $hash, 'sunset_has_gravatar' ) ) {
$request = wp_remote_head( 'http://0.gravatar.com/avatar/' . $hash . '?d=404' );
@Viper007Bond
Viper007Bond / generate-thumbnails.php
Created May 25, 2012 02:33
WordPress: When a thumbnail image is requested of a specific width/height (rather than by name), generate it if it doesn't exist.
<?php /*
**************************************************************************
Plugin Name: Generate Thumbnails On The Fly
Description: When a thumbnail image is requested of a specific width/height (rather than by name), generate it if it doesn't exist.
Version: 1.0.0
Author: Alex Mills (Viper007Bond)
Author URI: http://www.viper007bond.com/
@Viper007Bond
Viper007Bond / gist:3259814
Created August 4, 2012 20:45
Custom Post Password Cookie Expiry Time
<?php /*
**************************************************************************
Plugin Name: Custom Post Password Cookie Expiry Time
Description: WordPress doesn't allow you to customize how long a post password cookie lasts. This plugin allows you to customize that value;
Version: 1.0.0
Author: Alex Mills (Viper007Bond)
Author URI: http://www.viper007bond.com/
@Viper007Bond
Viper007Bond / sticky-custom-post-types.php
Created August 21, 2012 04:30
Bug fixes for Sticky Custom Post Types
<?php
/*
Plugin Name: Sticky Custom Post Types
Plugin URI: http://superann.com/sticky-custom-post-types/
Description: Enables support for sticky custom post types. Set options in Settings &rarr; Reading.
Version: 1.2.2
Author: Ann Oyama
Author URI: http://superann.com
License: GPL2