Skip to content

Instantly share code, notes, and snippets.

View zanematthew's full-sized avatar

Zane Matthew zanematthew

View GitHub Profile
@zanematthew
zanematthew / stateByAbbreviation
Created July 25, 2012 14:21
You give me state, I give you abbreviation!
<?php
/**
* You give me state, I give you abbreviation!
*/
public function stateByAbbreviation( $abbr=null ){
if ( is_null( $abbr ) )
die('need abbr');
@zanematthew
zanematthew / upload.php
Created July 23, 2012 16:00
Here's how I'm using zm-upload inside of a plugin and resizing images.
<?php
if ( ! empty( $_FILES ) ) {
$media = new MediaUpload;
$uploaded_media = $media->saveUpload( $field_name='Filedata' );
/**
* @todo MediaUpload does NOT handle resizing of images,
* normally its done in WordPress, but for some reason
@zanematthew
zanematthew / gist:3099863
Created July 12, 2012 18:15
Sample auto loader
<?php
/**
* Start auto loading
*
* Everything is based on the presence of a plugin/your-plugin/controller/{$post_type}_controller.php
* file if this file is present it is read and $post_type is paresed out and used for the model, js,
* and css file. If a css or js file isn't present one will be created for you given we can write to
* the dir.
*/
@zanematthew
zanematthew / gist:3001237
Created June 27, 2012 03:41
Separating logic
// Snippet from events/index.html.php
<!-- Track -->
<div class="row">
<h2 class="title"><?= $events->getTrackTitle( $post->ID ); ?></h2>
<div class="image-container">
<img src="<?= $tracks->getMapImage( $events->getTrackId( $post->ID ), 'medium' ); ?>" />
</div>
</div>
<!-- -->
@zanematthew
zanematthew / routes.php
Created June 19, 2012 02:48
Custom routes for using WordPress as an Application
<?php
/**
* This file handles redirecting of our templates to our given views
* dir and anything else.
*
* Check if the themer has made a theme file in their
* theme dir, if not load our default.
*
* @uses template_redirect http://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect
*/
@zanematthew
zanematthew / tracks_controller.php
Created June 16, 2012 16:07
Venue by Region and Local Venues
<?php
/**
* Returns the ID of all Venues in a given Region (full region)
*/
public function getVenueByRegion( $region=null ){
$args = array(
'post_type' => 'tracks',
'posts_per_page' => -1,
'post_status' => 'published',
'meta_query' => array(
@zanematthew
zanematthew / home_controller.php
Created June 16, 2012 15:57
Code from the Home page controller
<?php
public function randomBanner(){
$obj_local_venues = new Tracks;
$local_venues = $obj_local_venues->getLocalVenues();
$venue_ids = array();
foreach( $local_venues as $venue ){
@zanematthew
zanematthew / index.html.php
Created June 16, 2012 15:52
Code from the home page view
<?php if ( $event ) : ?>
<h1><a href="<?= $event['link']; ?>"><?= $event['title']; ?></a></h1>
<p class="date-time"><time class="post-time"><?= $event['date']; ?></time></p>
<div style="float: left;">
<ul class="inline" style="margin: 10px 0 0;">
<li style="margin-top: -12px; float: left;"><?php load_template( VIEWS_DIR . 'shared/facebook-button.html.php' ); ?></li>
<li><?php load_template( VIEWS_DIR . 'shared/twitter-like-button.html.php' ); ?></li>
</ul>
</div>
<?php else : ?>
@zanematthew
zanematthew / bootstrap.php
Created June 11, 2012 20:29
Auto loading files, this is part of my bootstrapping processes
<?php
// more stuff done here
/**
* Start auto loading
*
* Everything is based on the presence of a plugin/your-plugin/controller/{$post_type}_controller.php
* file if this file is present it is read and $post_type is paresed out and used for the model, js,
* and css file. If a css or js file isn't present one will be created for you given we can write to
@zanematthew
zanematthew / gist:2720021
Created May 17, 2012 16:33
Hook into template redirect before it can redirect
<?php
add_action('template_redirect', function() {
$tmp = explode( '/', $_SERVER['REQUEST_URI'] );
$my_slug = 'feeds';
if ( isset( $tmp ) && $tmp[1] == $my_slug ) {
load_template( '/path/to/my/template/' );
// or do what ever you want
exit();