[wp-trac] [WordPress Trac] #22882: get_post_ancestors() now returns false in addition to array()

WordPress Trac noreply at wordpress.org
Wed Dec 12 11:43:49 UTC 2012


#22882: get_post_ancestors() now returns false in addition to array()
-------------------+--------------------------
 Reporter:  dd32   |       Type:  defect (bug)
   Status:  new    |   Priority:  normal
Milestone:  3.5.1  |  Component:  General
  Version:         |   Severity:  normal
 Keywords:         |
-------------------+--------------------------
 Under [http://core.trac.wordpress.org/browser/branches/3.4/wp-
 includes/post.php#L428 3.4, get_post_ancestors()] would always return an
 array, in error conditions, it would return an empty array.[[BR]]
 Under [http://core.trac.wordpress.org/browser/trunk/wp-
 includes/post.php#L675 3.5, get_post_ancestors()] returns an array of
 ancestors, as in 3.4, except, in the case where the $post passed in is
 NULL/FALSE/0/empty, then it now returns false.

 This results in warning such as this: `Warning: Invalid argument supplied
 for foreach() ` when the result of get_post_ancestors() was used directly
 in a loop,

 Admitably, it's bad code which triggers this, calling get_post_ancestors()
 with the global `$post` object before it's set up in this case, but it's
 still a chance in behaviour which I felt needs documenting on trac. This
 is either a instant 'We should just return an array()' or 'wontfix:
 Plugins are doing it wrong and should fix their code' ticket.

 This was found by debugging http://wordpress.org/support/topic/does-
 wordpress-35-still-support-is_tree?

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


More information about the wp-trac mailing list