A New Post Type… New Problems

escherlego
Standard

Today’s been busy enough that I haven’t had the opportunity to put up some new work on it, but over the weekend, I was able to whip up the code to put together the custom post type I’d like to use for podcasts. (My original post on the project is here.)

My guides for this were the well-exampled Codex entry, Justin Tadlock’s posts on the matter, and Konstantin Kovshenin’s excellent posts as well. My code is structured after the example in the Codex with a little bit of experimentation:

# Let's get things started and fire up the custom post type for Podcasts.
add_action('init', 'simple_podcast_init');
function simple_podcast_init()
{
	$labels = array(
		'name' => _x('Podcasts', 'post type general name'),
		'singular_name' => _x('Podcast', 'post type singular name'),
		'add_new' => _x('Add New', 'podcast'),
		'add_new_item' => __('Add New Podcast'),
		'edit_item' => __('Edit Podcast'),
		'new_item' => __('New Podcast'),
		'view_item' => __('View Podcast'),
		'search_items' => __('Search Podcasts'),
		'not_found' => __('No podcasts found'),
		'not_found_in_trash' => __('No podcasts found in Trash'),
		'parent_item_colon' => ''
	);
	$args = array(
		'labels' => $labels,
		'public' => true,
		'publicly_queryable' => true,
		'show_ui' => true,
		'query_var' => true,
		'capability_type' => 'post',
		'taxonomies' => array('post_tag', 'category'),
		'hierarchical' => false,
		'menu_position' => 5,
		'supports' => array('title','editor','author','thumbnail','excerpt','comments','revisions')
	);
	register_post_type('podcast',$args);
}

This successfully registers the custom post type and its behaviors (though I’m not certain I like the taxonomies and may need to move to something else in the future), but there remains a problem: upon activating the plugin, any attempt to view a podcast results in a 404 from the permalink.

I’ve seen references elsewhere to flushing the rewrite rules, but it’s not clear to me where in the process this should go or how it’s supposed to be called. My understanding is that I don’t want to do that every time the plugin initializes, because that’s not being a good steward of server resources. (Of course, if I visit the panel at Settings > Permalinks, everything works just like it should.)

Unfortunately, I’ve not yet seen an example of code that would properly reset the rewrite rules when this is turned on. Here’s what I tried and failed with:

# Because we're adding a rewrite, we need to flush the rules on activation.
	function simple_podcast_flush_rules()
{
		global $wp_rewrite;
		$wp_rewrite->flush_rules();
}
register_activation_hook( __FILE__ , 'simple_podcast_flush_rules' );

Does anyone reading this have a suggestion for where I might be going wrong? I eventually had to step back from it and won’t get a chance to try again until later.

Playing more with custom post types has also revealed a small flaw in my designs: the podcasts won’t “mesh” with the regular posts on the blog. Their taxonomies (as far as I can tell) can’t be shared, and the podcasts won’t display in the main feed of the blog, either.

Then again, this may or may not be a concern, depending on how one would structure the site.

A New Frontier: Breaking WordPress

training
Standard

I’ve been using WordPress for a very long time, and I’ve squeezed a lot out of it over those years. I’ve learned how to build entire sites using it, I’ve learned how to make it do little tricks, and I’ve learned how to work with themes to bend it slightly to my will. There’s one aspect of WordPress tinkering that I’ve avoided that whole time because it’s just been too intimidating, but I’ve decided that I need to push myself to learn some new stuff, and there’s no better way than to just dive in and see what I can do.

So it’s time for me to try writing a plugin. This is a frightening thing for me, but I have a plugin that I’d like to create. The plan is mostly-formed in my mind, and I know what I want to do; now I just need to figure out how to get those things to happen by writing it.

I’ve been working with podcasting and WordPress for a good while now. There are a lot of options for podcasting plugins for self-hosted WordPress. Unfortunately, I feel that most of them are trying to do too much and have too many options. They’ve become more difficult to use. Old ones have disappeared into development history, others have changed developer hands over time, and still others have claimed to be the biggest, baddest podcasting plugin on the block.

The goal here is simplicity. It doesn’t have to be a very complicated addition to a WordPress installation, and new tools are available with the upcoming release of WordPress 3.0 that can be leveraged to build something that’s even easier to use. I’ll be posting source as I work with it here. If you have feedback or can teach me a better way to do things, I welcome it, as I think I will need the help.

Let’s start with some goals for the plugin:

  1. It will use custom post types to separate podcasts from regular posts.
  2. It will allow podcast enclosures to be manually specified—only one per post, as iTunes ignores subsequent enclosures.
  3. It will provide an administrative panel for specifying iTunes feed metadata.
  4. It will alter and/or create RSS feeds and autodiscovery to make subscribing to it easy, either directly or through iTunes.
  5. It will look, feel, and act like it’s been part of WordPress all along—a consistent user experience.

That’s the basic set of needs for a podcasting plugin; leave a comment if you think I missed something.

I’ll admit that I may not have the skills I need to pull this off. It’s definitely going to mean a lot of reading, a lot of tinkering, and a lot of making mistakes and backing up to try again.