Make WordPress Core

Ticket #14162: wp-term.php

File wp-term.php, 748 bytes (added by scribu, 16 years ago)

implemented as a plugin: get_link(), get_children()

Line 
1<?php
2
3class WP_Term {
4
5 function WP_Term( $term ) {
6 foreach ( get_object_vars( $term ) as $key => $value )
7 $this->$key = $value;
8
9 $this->term_id = (int) $this->term_id;
10 }
11
12 function get_link() {
13 return get_term_link( $this, $this->taxonomy );
14 }
15
16 function get_children() {
17 return get_term_children( $this->term_id, $this->taxonomy );
18 }
19
20 function update( $args ) {
21 return wp_update_term( $this->term_id, $this->taxonomy, $args );
22 }
23}
24
25function _enhance_term_objects( $data ) {
26 if ( is_object( $data ) )
27 return new WP_Term( $data );
28
29 foreach ( $data as $i => $term )
30 $data[ $i ] = new WP_Term( $term );
31
32 return $data;
33}
34add_filter( 'get_term', '_enhance_term_objects' );
35add_filter( 'get_terms', '_enhance_term_objects' );
36