Skip to content

Instantly share code, notes, and snippets.

@jchristopher
jchristopher / ITI_Widget_Image_OTM.php
Created February 4, 2012 17:29
Basic instantiation of an "Image of the Month" WordPress Widget
<?php
// we can only use this Widget if the plugin is active
if( class_exists( 'WidgetImageField' ) )
add_action( 'widgets_init', create_function( '', "register_widget( 'ITI_Widget_Image_OTM' );" ) );
class ITI_Widget_Image_OTM extends WP_Widget
{
var $image_field = 'image'; // the image field ID
@jchristopher
jchristopher / gist:1739100
Created February 4, 2012 17:33
The form() for our Image of the Month Widget
<?php
function form( $instance )
{
$headline = esc_attr( isset( $instance['headline'] ) ? $instance['headline'] : '' );
$image_id = esc_attr( isset( $instance[$this->image_field] ) ? $instance[$this->image_field] : 0 );
$blurb = esc_attr( isset( $instance['blurb'] ) ? $instance['blurb'] : '' );
$image = new WidgetImageField( $this, $image_id );
?>
@jchristopher
jchristopher / gist:1739167
Created February 4, 2012 17:49
The update() for our Image of the Month Widget
<?php
function update( $new_instance, $old_instance )
{
$instance = $old_instance;
$instance['headline'] = strip_tags( $new_instance['headline'] );
$instance[$this->image_field] = intval( strip_tags( $new_instance[$this->image_field] ) );
$instance['blurb'] = strip_tags( $new_instance['blurb'] );
@jchristopher
jchristopher / gist:1739179
Created February 4, 2012 17:52
The widget() function for our Image of the Month Widget
<?php
function widget( $args, $instance )
{
extract($args);
$headline = $instance['headline'];
$image_id = $instance[$this->image_field];
$blurb = $instance['blurb'];
@jchristopher
jchristopher / gist:1739212
Created February 4, 2012 17:57
Our final Image of the Month WordPress Widget
<?php
// we can only use this Widget if the plugin is active
if( class_exists( 'WidgetImageField' ) )
add_action( 'widgets_init', create_function( '', "register_widget( 'ITI_Widget_Image_OTM' );" ) );
class ITI_Widget_Image_OTM extends WP_Widget
{
var $image_field = 'image'; // the image field ID
@jchristopher
jchristopher / home.php
Created February 27, 2012 12:05
Handlebars.js & WordPress Templates - Home
<?php
/* Template Name: Home */
global $post;
global $handlebars;
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'handlebars',
get_bloginfo( 'stylesheet_directory' ) . '/js/handlebars.js',
@jchristopher
jchristopher / team-member-spotlight.php
Created February 27, 2012 12:06
Handlebars.js & WordPress Templates - Team Member Spotlight
<?php global $handlebars; ?>
<?php if( !$handlebars && has_post_thumbnail() ) : ?>
<?php $headshot = wp_get_attachment_image_src( get_post_thumbnail_id(), 'thumbnail' ); ?>
<img src="<?php echo $headshot[0]; ?>" alt="Headshot" class="alignleft" />
<?php elseif( $handlebars ) : ?>
{{#if headshot}}
@jchristopher
jchristopher / gist:1923303
Created February 27, 2012 12:08
Handlebars.js & WordPress Templates - Handlebars Template
<script id="team-member-spotlight-template" type="text/x-handlebars-template">
{{#if headshot}}
<img src="{{headshot}}" alt="Headshot of {{name}}" class="alignleft" />
{{/if}}
<h3>{{name}}</h3>
<p><a href="{{permalink}}">View more details</a></p>
</script>
@jchristopher
jchristopher / team.php
Created February 27, 2012 12:09
Handlebars.js & WordPress Templates - Team Page Template
<?php
/* Template Name: Team */
global $post;
// if it's an ajax request, return our JSON
if( isset( $_POST['ajax'] ) )
{
$args = array(
@jchristopher
jchristopher / class-iti-cap-limiter.php
Created March 7, 2012 23:34
[WordPress] Prevents the creation of full Administrators by client accounts
<?php
/**
* Prevents the creation of full Administrators by client accounts
* Forked from JPB_User_Caps (unable to locate origin)
*
* @return void
* @author Jonathan Christopher
*/
if( is_admin() )