Permalink
Browse files

init

  • Loading branch information...
Eric Teubert
Eric Teubert committed Feb 9, 2012
0 parents commit 5f0fb28d7c88cbd072dae26964770cd70c3891bd
Showing with 161 additions and 0 deletions.
  1. +1 −0 README.md
  2. +94 −0 podcaster-post-type.php
  3. +66 −0 podcaster.php
@@ -0,0 +1 @@
Work before progress. Feel free to touch but handle with care.
@@ -0,0 +1,94 @@
<?php
/**
* Custom Post Type
*/
class Podcaster_Post_Type {
/**
* Register custom "podcast" post type.
*/
public function __construct() {
$labels = array(
'name' => Podcaster::t( 'Podcast' ),
'singular_name' => Podcaster::t( 'Podcast' ),
'add_new' => Podcaster::t( 'Add New' ),
'add_new_item' => Podcaster::t( 'Add New Episode' ),
'edit_item' => Podcaster::t( 'Edit Episode' ),
'new_item' => Podcaster::t( 'New Episode' ),
'all_items' => Podcaster::t( 'All Episodes' ),
'view_item' => Podcaster::t( 'View Episode' ),
'search_items' => Podcaster::t( 'Search Episodes' ),
'not_found' => Podcaster::t( 'No episodes found' ),
'not_found_in_trash' => Podcaster::t( 'No episodes found in Trash' ),
'parent_item_colon' => '',
'menu_name' => Podcaster::t( 'Podcasts' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'custom-fields', 'trackbacks' ),
'register_meta_box_cb' => array( $this, 'register_post_type_meta_boxes' )
);
$args = apply_filters( 'podcaster_post_type_args', $args );
register_post_type( 'podcast', $args );
add_action( 'save_post', array( $this, 'save_postdata' ) );
}
/**
* Register post meta boxes.
*/
public function register_post_type_meta_boxes() {
add_meta_box(
/* $id */ 'podcaster',
/* $title */ Podcaster::t( 'Podcast Metadata' ),
/* $callback */ array( $this, 'post_type_meta_box_callback' ),
/* $page */ 'podcast'
/* $context */
/* $priority */
/* $callback_args */
);
}
public function post_type_meta_box_callback() {
global $post;
$meta = get_post_meta( $post->ID, 'podcaster_meta', true );
wp_nonce_field( plugin_basename( __FILE__ ), 'podcaster_noncename' );
?>
<input type="text" name="podcaster_meta[duration]" value="<?php echo $meta[ 'duration' ]; ?>" />
<input type="text" name="podcaster_meta[foo]" value="<?php echo $meta[ 'foo' ]; ?>" />
<input type="text" name="podcaster_meta[bar]" value="<?php echo $meta[ 'bar' ]; ?>" />
<?php
}
public function save_postdata( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if ( empty( $_POST[ 'podcaster_noncename' ] ) || ! wp_verify_nonce( $_POST[ 'podcaster_noncename' ], plugin_basename( __FILE__ ) ) )
return;
// Check permissions
if ( 'podcast' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_post', $post_id ) )
return;
} else {
return;
}
update_post_meta( $post_id, 'podcaster_meta', $_POST[ 'podcaster_meta' ] );
}
}
@@ -0,0 +1,66 @@
<?php
/*
Plugin Name: Podcaster
Plugin URI:
Description: The one and only podcast client. Seriously.
Version: 1.0
Author: Eric Teubert
Author URI: ericteubert@googlemail.com
License: MIT
*/
function pdcr_init() {
new Podcaster;
}
add_action( 'plugins_loaded', 'pdcr_init' );
class Podcaster {
function __construct() {
add_action( 'init', array( $this, 'register_post_type' ) );
register_activation_hook( __FILE__, array( $this, 'activate' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
register_uninstall_hook( __FILE__, array( __CLASS__, 'uninstall' ) );
}
/**
* Shorthand translation function.
*
* @param string $text
* @return string
*/
public static function t( $text ) {
return __( $text, 'podcaster' );
}
/**
* Register custom post type "podcast".
*/
public function register_post_type() {
require_once 'podcaster-post-type.php';
new Podcaster_Post_Type();
}
/**
* Callback function when activating the plugin.
*/
public function activate() {
// ...
}
/**
* Callback function when deactivating the plugin.
*/
public function deactivate() {
// ...
}
/**
* Callback function when uninstalling the plugin.
*/
static function uninstall() {
// remove every trace of the existence of this plugin
}
}

0 comments on commit 5f0fb28

Please sign in to comment.