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 (84)
- Keywords early removed
- Milestone changed from Awaiting Triage to Future Release
in reply to:
6 years ago
- Summary changed from Upgrade loop objects to provide identical presentational interfaces. to Introduce WP_Post class
- Summary changed from Introduce WP_Post class to Upgrade loop objects to provide identical presentational interfaces
17 months ago
- Milestone Future Release deleted
- Resolution set to maybelater
- Status changed from new to closed
- Resolution maybelater deleted
- Status changed from closed to reopened