[wp-trac] [WordPress Trac] #14162: Introduce WP_Term

WordPress Trac wp-trac at lists.automattic.com
Thu Jul 1 00:21:19 UTC 2010


#14162: Introduce WP_Term
-------------------------+--------------------------------------------------
 Reporter:  scribu       |       Owner:                 
     Type:  enhancement  |      Status:  new            
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Taxonomy     |     Version:                 
 Severity:  normal       |    Keywords:                 
-------------------------+--------------------------------------------------

Old description:

> In the current taxonomy API, you end up having to pass the taxonomy name
> over and over again.
>
> I propose we have a WP_Term class to avoid that.
>
> === Example ===
>
> Current:
>
> `get_term_link( get_term_by( 'name', 'Term Name', 'taxname' ), 'taxname'
> )`
>
> Proposed:
>
> `get_term_by( 'name', 'Term Name', 'taxname' )->get_link()`
>
> get_term_by() would return a WP_Term instance instead of a stdClass
> instance.
>
> Besides get_link(), the WP_Term class could also have an update() method
> that would replace (or complement) wp_update_term().
>
> Inspired by #14156.

New description:

 In the current taxonomy API, you end up having to pass the taxonomy name
 over and over again.

 I propose we have a WP_Term class to avoid that.

 === Example ===

 Current:

 {{{get_term_link( get_term_by( 'name', 'Term Name', 'taxname' ), 'taxname'
 )}}}

 Proposed:

 {{{get_term_by( 'name', 'Term Name', 'taxname' )->get_link()}}}

 get_term_by() would return a WP_Term instance instead of a stdClass
 instance.

 Besides get_link(), the WP_Term class could also have an update() method
 that would replace (or complement) wp_update_term().

 Inspired by #14156.

--

Comment(by scribu):

 Sure, but this enhancement is not dependant on chaining. You could still
 do this:

 {{{
 $term = get_term_by( 'name', 'Term Name', 'taxname' );
 echo $term->get_link();
 }}}

 which would still be better than:

 {{{
 $term = get_term_by( 'name', 'Term Name', 'taxname' );
 echo get_term_link( $term, 'taxname' );
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/14162#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list