Upgrade loop objects to provide identical presentational interfaces
|Reported by:||andy||Owned by:|
Usually wpdb returns rows as stdClass objects. We are used to getting properties from these objects, e.g. $post->ID or $comment->comment_ID, but this class has no methods. As used, the stdClass object is only a syntactic alternative to the array.
As long as we're already using objects, let's have some more useful classes. I propose post and comment classes that implement common interfaces, and classes that extend these for special post_types and comment_types, and filters to allow plugins to use their own classes at instantiation time.
Without actually using PHP5 interface syntax, the idea is to have identical methods to get things from objects in the loop. For example, one common method would be url(). The same method would work on every kind of compatible object, be it a post, page, attachment, comment, trackback, or pingback, although the underlying logic for getting the URL may differ for each.
<a href="<?php print esc_attr($post->url()); ?>">
It would simplify templates while allowing various object types in loops, not just posts, and give us an opportunity to clean up a lot of the underlying template tag logic (e.g. global $authordata), and give plugins and themes new ways to modify output.
This stemmed from my work on search. I wanted a way to keep the template simple while adding support for different object types in the loop. I figured that it wouldn't hurt anything to upgrade the classes because the way of accessing properties would be unchanged.
Change History (75)
comment:27 @nacin — 5 years ago
- Keywords early removed
- Milestone changed from Awaiting Triage to Future Release
comment:40 in reply to: ↑ 39 @mikeschinkel — 5 years ago
comment:53 @scribu — 3 years ago
- Summary changed from Upgrade loop objects to provide identical presentational interfaces. to Introduce WP_Post class
comment:67 @scribu — 3 years ago
- Summary changed from Introduce WP_Post class to Upgrade loop objects to provide identical presentational interfaces