[wp-trac] [WordPress Trac] #19012: get_ID and the_ID should accept $id as a parameter

WordPress Trac wp-trac at lists.automattic.com
Thu Oct 20 05:27:29 UTC 2011


#19012: get_ID and the_ID should accept $id as a parameter
-------------------------------------------------+-------------------------
 Reporter:  peterchester                         |       Owner:  ryan
     Type:  enhancement                          |      Status:  reviewing
 Priority:  normal                               |   Milestone:  Future
Component:  Post Types                           |  Release
 Severity:  normal                               |     Version:  3.3
 Keywords:  needs-testing needs-codex needs-     |  Resolution:
  patch 2nd-opinion                              |
-------------------------------------------------+-------------------------
Changes (by markjaquith):

 * keywords:  has-patch needs-testing needs-codex => needs-testing needs-
     codex needs-patch 2nd-opinion
 * owner:  peterchester => ryan
 * status:  new => reviewing
 * milestone:  Awaiting Review => Future Release


Old description:

> I see through out the wordpress code as well as through out many plugins
> and themes that get_ID is often accompanied by a test to see if an ID had
> been passed. It would be a harmless but extremely useful update to simply
> allow get_ID and the_ID to accept an optional $id and pass it through if
> it's numerical.
>
> I've already gone ahead and created the patch (attached)

New description:

 I see throughout the WordPress code as well as throughout many plugins and
 themes that {{{get_ID()}}} is often accompanied by a test to see if an ID
 had been passed. It would be a harmless but extremely useful update to
 simply allow {{{get_ID()}}} and {{{the_ID()}}} to accept an optional $id
 and pass it through if it's numerical.

 I've already gone ahead and created the patch (attached)

--

Comment:

 {{{get_post()}}} does something similar. It takes a post object, a post
 id, or nothing, and gives you a post object.

 I wouldn't use {{{is_numeric()}}} though — too permissive.

 > Numeric strings consist of optional sign, any number of digits, optional
 decimal part and optional exponential part. Thus +0123.45e6 is a valid
 numeric value. Hexadecimal notation (0xFF) is allowed too but only without
 sign, decimal and exponential part.

 Instead I'd say we cast to integer, and check for it being greater than
 zero. I'm also not sure it's useful for {{{the_ID()}}}.

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


More information about the wp-trac mailing list