[wp-trac] [WordPress Trac] #14302: Object Property getters and setters

WordPress Trac wp-trac at lists.automattic.com
Sun Jul 18 01:28:27 UTC 2010


#14302: Object Property getters and setters
-------------------------+--------------------------------------------------
 Reporter:  filosofo     |       Owner:  filosofo 
     Type:  enhancement  |      Status:  accepted 
 Priority:  normal       |   Milestone:  3.1      
Component:  Post Types   |     Version:  3.0      
 Severity:  normal       |    Keywords:  has-patch
-------------------------+--------------------------------------------------

Old description:

> Currently, if you want to get or set a post object's property:
>  * You have to know which database table it's located in
>  * If that property is in the posts table, you have to set all properties
> to set any, via `wp_update_post` or `wp_insert_post`.
>  * If that property is in the postmeta table, you have to specify that it
> be returned as a singular value (instead of an array of values)
>
> My patch lets WP figure out where a particular value is stored, so you
> don't have to, with two new functions:
>
> mixed '''get_object_property''' ( int ''$object_id'', string
> ''$prop_name'' [, bool ''$force_single'' ] )
>
> bool '''set_object_property''' ( int ''$object_id'', string
> ''$prop_name'', mixed ''$prop_value'' )

New description:

 Currently, if you want to get or set a post object's property:
  * You have to know which database table it's located in
  * If that property is in the posts table, you have to set all properties
 to set any, via `wp_update_post` or `wp_insert_post`.
  * If that property is in the postmeta table, you have to specify that it
 be returned as a singular value (instead of an array of values)

 My patch lets WP figure out where a particular value is stored, so you
 don't have to, with two new functions:

 mixed '''get_post_property''' ( int ''$object_id'', string ''$prop_name''
 [, bool ''$force_single'' ] )

 bool '''set_post_property''' ( int ''$object_id'', string ''$prop_name'',
 mixed ''$prop_value'' )

--

Comment(by filosofo):

 I think you're right that it makes more sense to call them
 `get_post_property` and `set_post_property`, in light of the other objects
 throughout WP (in the PHP sense of "object"), such as the taxonomy and
 user objects.

 Since the advent of the current taxonomy system I've preferred thinking of
 `posts` in general as objects, but the naming conventions introduced in
 3.0 suggest that I need to stop worrying and love the "post."

 Second patch uses *`_post_`* instead of *`_object_`*

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


More information about the wp-trac mailing list