[wp-trac] [WordPress Trac] #12267: Upgrade loop objects to provide identical presentational interfaces.

WordPress Trac wp-trac at lists.automattic.com
Thu Feb 18 00:19:25 UTC 2010


#12267: Upgrade loop objects to provide identical presentational interfaces.
-------------------------+--------------------------------------------------
 Reporter:  andy         |       Owner:            
     Type:  enhancement  |      Status:  new       
 Priority:  normal       |   Milestone:  Unassigned
Component:  General      |     Version:            
 Severity:  normal       |    Keywords:            
-------------------------+--------------------------------------------------
 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.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/12267>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list