1 | <?php |
---|
2 | |
---|
3 | class 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 | |
---|
25 | function _enhance_term_objects( $data ) { |
---|
26 | if ( is_object( $data ) ) |
---|
27 | return new WP_Term( $data ); |
---|
28 | |
---|
29 | if ( is_array( $data ) && is_object( reset( $data ) ) ) |
---|
30 | foreach ( $data as $i => $term ) |
---|
31 | $data[ $i ] = new WP_Term( $term ); |
---|
32 | |
---|
33 | return $data; |
---|
34 | } |
---|
35 | add_filter( 'get_term', '_enhance_term_objects' ); |
---|
36 | add_filter( 'get_terms', '_enhance_term_objects' ); |
---|
37 | |
---|