Skip to content

Instantly share code, notes, and snippets.

View mfields's full-sized avatar

Michael Fields mfields

  • Portland, Oregon, USA
View GitHub Profile
@mfields
mfields / gist:1026364
Created June 15, 2011 02:29
Taxonomy Images Plugin Custom "get_the_terms" Loop
<?php
/*
* Use Taxonomy Images filter to get all speakers
* associated with the current post.
*/
$speakers = apply_filters( 'taxonomy-images-get-the-terms', '', array(
'taxonomy' => 'category',
) );
@mfields
mfields / bcrypt.php
Created June 23, 2011 17:36 — forked from dzuelke/bcrypt.php
How to use bcrypt in PHP to safely store passwords (PHP 5.3+ only)
<?php
// secure hashing of passwords using bcrypt, needs PHP 5.3+
// see http://codahale.com/how-to-safely-store-a-password/
// salt for bcrypt needs to be 22 base64 characters (but just [./0-9A-Za-z]), see http://php.net/crypt
// just an example; please use something more secure/random than sha1(microtime) :)
$salt = substr(str_replace('+', '.', base64_encode(sha1(microtime(true), true))), 0, 22);
// 2a is the bcrypt algorithm selector, see http://php.net/crypt
@mfields
mfields / gist:1044098
Created June 24, 2011 02:19
CSS Hide Selection
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
@mfields
mfields / gist:1061846
Created July 3, 2011 00:53
Simple Github commit API shortcode for WordPress
<?php
/*
Plugin Name: Mfields Github Shortcode
Plugin URI: null
Description: Display recent commits from a Github repository.
Version: 0.1
Author: Michael Fields
Author URI: http://wordpress.mfields.org/
License: GPLv2 or later
@mfields
mfields / gist:1079539
Created July 13, 2011 01:05
Sticky Posts
<?php
if ( ! have_posts() ) {
/**
* @todo Some kinda 404 stuff here...
*/
}
/*
* Loop for Sticky Posts.
*/
@mfields
mfields / gist:1184759
Created August 31, 2011 21:27
Enqueue css for a custom post_type in edit.php
<?php
add_action( 'load-edit.php', 'myplugin_setup_edit_screen' );
function myplugin_setup_edit_screen() {
$screen = get_current_screen();
if ( 'my_post_type' != $screen->post_type ) {
return;
}
add_action( 'admin_print_styles', 'myplugin_edit_screen_css' );
@mfields
mfields / gist:1203408
Created September 8, 2011 13:38
Get Background Color
<?php
function mytheme_get_background_color() {
$color = get_background_color();
if ( ! ctype_xdigit( $color ) )
return 'transparent';
if ( ! in_array( strlen( $color ), array( 3, 6 ) ) )
return 'transparent';
return '#' . $color;
}
if ( defined('WP_USE_THEMES') && WP_USE_THEMES ) :
$template = false;
if ( is_404() && $template = get_404_template() ) :
elseif ( is_search() && $template = get_search_template() ) :
elseif ( is_tax() && $template = get_taxonomy_template() ) :
elseif ( is_front_page() && $template = get_front_page_template() ) :
elseif ( is_home() && $template = get_home_template() ) :
elseif ( is_attachment() && $template = get_attachment_template() ) :
remove_filter('the_content', 'prepend_attachment');
elseif ( is_single() && $template = get_single_template() ) :
@mfields
mfields / gist:1403263
Created November 29, 2011 03:30
sudfglkusdfglksdfkghj
<?php
/*
Plugin Name: sudfglkusdfglksdfkghj
*/
function sudfglkusdfglksdfkghj( $content ) {
global $wp_version;
$version = '3.3-beta4';
if ( $wp_version == $version )
@mfields
mfields / gist:1456066
Created December 10, 2011 19:34
Is RGB(A)?
function is_rgb( $x ) {
if ( is_int( $x ) )
$x = strval( $x );
if ( ! is_string( $x ) )
return false;
$x = preg_replace( '/\s*/', '', $x );
$x = strtolower( $x );
$x = trim( $x );