Skip to content

Instantly share code, notes, and snippets.

@zanematthew
Created May 9, 2012 23:12
Show Gist options
  • Save zanematthew/2649619 to your computer and use it in GitHub Desktop.
Save zanematthew/2649619 to your computer and use it in GitHub Desktop.
Sample code from the tracks controller
<?php
// Contents of controllers/tracks_controller.php
Class Tracks extends zMCustomPostTypeBase {
/**
* @todo derive this, based on $this->post_type['type']
*/
public $cpt = 'tracks';
/**
* @todo move this over to the abstract and model? as
* part of the array in tracks.php?
*/
public $has_many = 'events';
static $instance;
public function __construct(){
// late static binding
// allows use to use self::$instance->cpt when invoked
// like Tracks::someMethod();
self::$instance = $this;
/**
* Our parent construct has the init's for register_post_type
* register_taxonomy and many other usefullness.
*/
parent::__construct();
/**
* Set-up postmeta fields for WordPress
*/
add_action( 'add_meta_boxes', array( &$this, 'addressField' ) );
add_action( 'save_post', array( &$this, 'saveTrackMeta' ) );
}
public function addressField(){
add_meta_box(
'track_address',
__( 'Address', 'myplugin_textdomain' ),
array( &$this, 'addressFieldRender'),
$this->cpt . 's' // @todo messed up
);
}
// and so on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment