Opened 3 years ago
Last modified 6 weeks ago
#14162 new enhancement
Introduce WP_Term class
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Taxonomy | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | kevinB, sirzooro, mikeschinkel@…, andyadamscp@… |
Description (last modified by scribu)
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.
Attachments (2)
Change History (15)
- Description modified (diff)
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' );
Found out that this is pretty easy to implement as a plugin. See wp-term.php
Having a WP_Term object is a great idea.
Instead of an update method that gets an array of arguments, why not have it save the current object's properties to the database?
$term->set_description('my new description');
$term->update(); // now the new description is saved to the database
As suggested above, it would also be nice to have getters and possibly setters for the other salient properties in addition to "link."
Personally, I'm not a big fan of this type of encapsulation working its way into WordPress.
I want to ensure that everything is simple to use and I'm not sure lots of objects like this is the way to go.
Replying to westi:
Personally, I'm not a big fan of this type of encapsulation working its way into WordPress.
I want to ensure that everything is simple to use and I'm not sure lots of objects like this is the way to go.
Could you elaborate your objections? Terms already are objects, so this would extend existing functionality, not diminish it or require people to use a new API.
comment:10
nacin — 3 years ago
- Milestone changed from Awaiting Review to Future Release
comment:11
scribu — 2 years ago
- Summary changed from Introduce WP_Term to Introduce WP_Term class
comment:12
mikeschinkel — 2 years ago
- Cc mikeschinkel@… added
comment:13
andyadams — 6 weeks ago
- Cc andyadamscp@… added

Chaining functions would have to wait until PHP 5.