<?php

class WP_Term {

	function WP_Term( $term ) {
		foreach ( get_object_vars( $term ) as $key => $value )
			$this->$key = $value;

		$this->term_id = (int) $this->term_id;
	}

	function get_link() {
		return get_term_link( $this, $this->taxonomy );
	}

	function get_children() {
		return get_term_children( $this->term_id, $this->taxonomy );
	}

	function update( $args ) {
		return wp_update_term( $this->term_id, $this->taxonomy, $args );
	}
}

function _enhance_term_objects( $data ) {
	if ( is_object( $data ) )
		return new WP_Term( $data );

	if ( is_array( $data ) && is_object( reset( $data ) ) )
		foreach ( $data as $i => $term )
			$data[ $i ] = new WP_Term( $term );

	return $data;
}
add_filter( 'get_term', '_enhance_term_objects' );
add_filter( 'get_terms', '_enhance_term_objects' );

