<?php
/*
Plugin Name: Test Taxonomy
Plugin URI: http://simonwheatley.co.uk/wordpress/test-taxonomy
Description: Some test code for taxonomies. This code works for WordPress 2.7.1.
Author: Simon Wheatley
Version: 1.0
Author URI: http://simonwheatley.co.uk/wordpress/
*/

/*

    Copyright 2009 Simon Wheatley

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

define'TT_TEST_POST_1'); // Change this post ID to match your blog
define'TT_TEST_POST_2'); // Change this post ID to match your blog (diff to the one above)
define'TT_TAXONOMY''test' );

function 
tt_init()
{
    
error_log"tt_init" );
    
// We need to register the taxonomy every page load
    
tt_register_taxonomy();
}

// Plugin activation
function tt_activate()
{
    
// On activation, register the taxonomy and flush the rules (flushing 
    // the rules only needs to be done once per taxonomy registration)
    
tt_register_taxonomy();
    
tt_flush_rewrite_rules();
    
// Then, just for the purposes of this test, we'll add the terms
    
tt_add_terms_to_posts();
}

// This creates the taxonomy
function tt_register_taxonomy()
{
    
$object_type "post";
    
register_taxonomyTT_TAXONOMY$object_type );
}

// Rewrite rules need flushing after the taxonomy is created, or the 
// fancy URLs won't work
function tt_flush_rewrite_rules()
{
    global 
$wp_rewrite;
    
$wp_rewrite->flush_rules();
}

// Add a couple of terms to the taxonomy, and link to the text post
function tt_add_terms_to_posts()
{
    
$terms = array( 'whatever''stuff' );
    
wp_set_object_termsTT_TEST_POST_1$termsTT_TAXONOMY );
    
$terms = array( 'stuff''things' );
    
wp_set_object_termsTT_TEST_POST_2$termsTT_TAXONOMY );
}

function 
tt_the_test_terms$before 'Test terms: '$sep ', '$after '' ) {
    global 
$the_post;
    return 
the_terms0TT_TAXONOMY$before$sep$after );
}

add_action'init''tt_init' );
add_action'activate_' plugin_basename(__FILE__), 'tt_activate' );

?>