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:729405
Created December 5, 2010 19:54
jQuery Post Loader for WordPress Home Page
<?php
/*
Plugin Name: mfields.org - Ajax Append Posts
Plugin URI:
Description:
Version: 0.1
Author: Michael Fields
Author URI: http://mfields.org/
Copyright 2010 Michael Fields michael@mfields.org
License GPLv2
@mfields
mfields / mfields.org-post-loader.php
Created December 6, 2010 16:16
jQuery Post Loader for WordPress Home Page
<?php
/*
Plugin Name: mfields.org - Ajax Append Posts
Plugin URI:
Description:
Version: 0.1.2
Author: Michael Fields
Author URI: http://mfields.org/
Copyright 2010 Michael Fields michael@mfields.org
License GPLv2
@mfields
mfields / mfields-taxonomy-map.php
Created January 8, 2011 01:11
WordPress Taxonomy Map Plugin
<?php
/*
Plugin Name: Taxonomy Map
Plugin URI: http://wordpress.mfields.org/plugins/taxonomy-images/
Description: Use a hierarchical taxonomy system to display Goole map.
Version: 0.1
Author: Michael Fields
Author URI: http://wordpress.mfields.org/
License: GPLv2
/**
* Get a random tag.
* @since 2011-03-26
*/
function mfields_get_random_tag() {
var_dump( get_terms( 'post_tag', array(
'number' => 1,
'orderby' => 'RAND()',
) ) );
}
<?php
// Register the column
function price_column_register( $columns ) {
$columns['price'] = __( 'Price', 'my-plugin' );
return $columns;
}
add_filter( 'manage_edit-post_columns', 'price_column_register' );
<?php
$src = '';
$content = get_the_content();
/* Content contains only a url. */
$src = esc_url( trim( $content ) );
if ( ! empty( $src ) && is_array( @getimagesize( $src ) ) ) {
@mfields
mfields / gist:958312
Created May 6, 2011 01:40
Add classes to images
( function( window, document, undefined ) {
var maybeAddClass = function( e, cn ) {
var c = e.getAttribute( 'class' );
if ( 0 == c.length ) {
e.className += cn;
}
else if ( -1 == c.indexOf( cn ) ) {
e.className += ' ' + cn;
}
@mfields
mfields / gist:964552
Created May 10, 2011 14:17
Hide submit button if it exists.
/* Hide submit button if it exists. */
var button = document.getElementById( 'my_submit_button' );
if ( null !== button && 'style' in button && 'display' in button.style ) {
button.style.display = 'none';
}
@mfields
mfields / gist:965956
Created May 11, 2011 05:19
Wrap WordPress Enbeds in a div
<?php
/**
* Enclose embedded media in a div.
*
* Wrapping all flash embeds in a div allows for easier
* styling with CSS media queries.
*
* @todo Document parameters.
*
* @access private
@mfields
mfields / gist:1006626
Created June 3, 2011 16:21
Making some Objects in PHP
<?php
/*
* Send all required arguments.
*/
$test = new My_Object( array(
'one' => 1,
'two' => 2,
'three' => 3,