<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[21559] trunk/wp-includes: Introduce WP_Post class.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/21559">21559</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2012-08-20 19:47:52 +0000 (Mon, 20 Aug 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>Introduce WP_Post class. Clean up ancestors handling. Props scribu, toppa. fixes <a href="http://core.trac.wordpress.org/ticket/10381">#10381</a> see <a href="http://core.trac.wordpress.org/ticket/21309">#21309</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesloadphp">trunk/wp-includes/load.php</a></li>
<li><a href="#trunkwpincludesnavmenutemplatephp">trunk/wp-includes/nav-menu-template.php</a></li>
<li><a href="#trunkwpincludesposttemplatephp">trunk/wp-includes/post-template.php</a></li>
<li><a href="#trunkwpincludespostphp">trunk/wp-includes/post.php</a></li>
<li><a href="#trunkwpincludesqueryphp">trunk/wp-includes/query.php</a></li>
<li><a href="#trunkwpincludestaxonomyphp">trunk/wp-includes/taxonomy.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesloadphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/load.php (21558 => 21559)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/load.php        2012-08-20 19:43:16 UTC (rev 21558)
+++ trunk/wp-includes/load.php        2012-08-20 19:47:52 UTC (rev 21559)
</span><span class="lines">@@ -410,7 +410,7 @@
</span><span class="cx">
</span><span class="cx">         if ( function_exists( 'wp_cache_add_global_groups' ) ) {
</span><span class="cx">                 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
</span><del>-                wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
</del><ins>+                wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins', 'post_ancestors' ) );
</ins><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpincludesnavmenutemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/nav-menu-template.php (21558 => 21559)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/nav-menu-template.php        2012-08-20 19:43:16 UTC (rev 21558)
+++ trunk/wp-includes/nav-menu-template.php        2012-08-20 19:47:52 UTC (rev 21559)
</span><span class="lines">@@ -286,8 +286,6 @@
</span><span class="cx">                                 }
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><del>-        } elseif ( ! empty( $queried_object->post_type ) && is_post_type_hierarchical( $queried_object->post_type ) ) {
-                _get_post_ancestors( $queried_object );
</del><span class="cx">         } elseif ( ! empty( $queried_object->taxonomy ) && is_taxonomy_hierarchical( $queried_object->taxonomy ) ) {
</span><span class="cx">                 $term_hierarchy = _get_term_hierarchy( $queried_object->taxonomy );
</span><span class="cx">                 $term_to_ancestor = array();
</span></span></pre></div>
<a id="trunkwpincludesposttemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post-template.php (21558 => 21559)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post-template.php        2012-08-20 19:43:16 UTC (rev 21558)
+++ trunk/wp-includes/post-template.php        2012-08-20 19:47:52 UTC (rev 21559)
</span><span class="lines">@@ -1016,8 +1016,7 @@
</span><span class="cx">                 $css_class = array('page_item', 'page-item-'.$page->ID);
</span><span class="cx">                 if ( !empty($current_page) ) {
</span><span class="cx">                         $_current_page = get_page( $current_page );
</span><del>-                        _get_post_ancestors($_current_page);
-                        if ( isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors) )
</del><ins>+                        if ( in_array( $page->ID, $_current_page->ancestors ) )
</ins><span class="cx">                                 $css_class[] = 'current_page_ancestor';
</span><span class="cx">                         if ( $page->ID == $current_page )
</span><span class="cx">                                 $css_class[] = 'current_page_item';
</span></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (21558 => 21559)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2012-08-20 19:43:16 UTC (rev 21558)
+++ trunk/wp-includes/post.php        2012-08-20 19:47:52 UTC (rev 21559)
</span><span class="lines">@@ -375,54 +375,143 @@
</span><span class="cx"> * @param int|object $post Post ID or post object.
</span><span class="cx"> * @param string $output Optional, default is Object. Either OBJECT, ARRAY_A, or ARRAY_N.
</span><span class="cx"> * @param string $filter Optional, default is raw.
</span><del>- * @return mixed Post data
</del><ins>+ * @return mixed Post data or null on failure
</ins><span class="cx"> */
</span><del>-function &get_post(&$post, $output = OBJECT, $filter = 'raw') {
-        global $wpdb;
</del><ins>+function &get_post( &$post, $output = OBJECT, $filter = 'raw' ) {
</ins><span class="cx">         $null = null;
</span><span class="cx">
</span><del>-        if ( empty($post) ) {
-                if ( isset($GLOBALS['post']) )
-                        $_post = & $GLOBALS['post'];
-                else
-                        return $null;
-        } elseif ( is_object($post) && empty($post->filter) ) {
-                _get_post_ancestors($post);
-                $_post = sanitize_post($post, 'raw');
-                wp_cache_add($post->ID, $_post, 'posts');
-        } elseif ( is_object($post) && 'raw' == $post->filter ) {
</del><ins>+        if ( empty( $post ) && isset( $GLOBALS['post'] ) ) {
+                $_post = & $GLOBALS['post'];
+        } elseif ( is_a( $post, 'WP_Post' ) ) {
</ins><span class="cx">                 $_post = $post;
</span><ins>+        } elseif ( is_object( $post ) ) {
+                if ( empty( $post->filter ) ) {
+                        $_post = sanitize_post( $post, 'raw' );
+                        wp_cache_add( $post->ID, $_post, 'posts' );
+                        $_post = new WP_Post( $_post );
+                } elseif ( 'raw' == $post->filter ) {
+                        $_post = new WP_Post( $post );
+                } else {
+                        $_post = WP_Post::get_instance( $post->ID );
+                }
</ins><span class="cx">         } else {
</span><del>-                if ( is_object($post) )
-                        $post_id = $post->ID;
-                else
-                        $post_id = $post;
</del><ins>+                $_post = WP_Post::get_instance( $post );
+        }
</ins><span class="cx">
</span><ins>+        if ( !$_post )
+                return $null;
+
+        $_post = $_post->filter( $filter );
+
+        if ( $output == ARRAY_A ) {
+                $__post = $_post->to_array();
+                return $__post;
+        } elseif ( $output == ARRAY_N ) {
+                $__post = array_values( $_post->to_array() );
+                return $__post;
+        }
+
+        return $_post;
+}
+
+/**
+ * WordPress Post class.
+ *
+ * @since 3.5.0
+ *
+ * @property $ID;
+ * @property $post_author;
+ * @property $post_date;
+ * @property $post_date_gmt;
+ * @property $post_content;
+ * @property $post_title;
+ * @property $post_excerpt;
+ * @property $post_status;
+ * @property $comment_status;
+ * @property $ping_status;
+ * @property $post_password;
+ * @property $post_name;
+ * @property $to_ping;
+ * @property $pinged;
+ * @property $post_modified;
+ * @property $post_modified_gmt;
+ * @property $post_content_filtered;
+ * @property $post_parent;
+ * @property $guid;
+ * @property $menu_order;
+ * @property $post_type;
+ * @property $post_mime_type;
+ * @property $comment_count;
+ * @property $ancestors;
+ */
+final class WP_Post {
+
+        public $filter;
+
+        public static function get_instance( $post_id ) {
+                global $wpdb;
+
</ins><span class="cx">                 $post_id = (int) $post_id;
</span><del>-                if ( ! $_post = wp_cache_get($post_id, 'posts') ) {
-                        $_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id));
</del><ins>+                if ( !$post_id )
+                        return false;
+
+                if ( ! $_post = wp_cache_get( $post_id, 'posts' ) ) {
+                        $_post = $wpdb->get_row( $wpdb->prepare( "
+                                SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1
+                        ", $post_id ) );
+
</ins><span class="cx">                         if ( ! $_post )
</span><del>-                                return $null;
-                        _get_post_ancestors($_post);
-                        $_post = sanitize_post($_post, 'raw');
-                        wp_cache_add($_post->ID, $_post, 'posts');
</del><ins>+                                return false;
+
+                        $_post = sanitize_post( $_post, 'raw' );
+                        wp_cache_add( $_post->ID, $_post, 'posts' );
</ins><span class="cx">                 }
</span><ins>+
+                return new WP_Post( $_post );
</ins><span class="cx">         }
</span><span class="cx">
</span><del>-        if ($filter != 'raw')
-                $_post = sanitize_post($_post, $filter);
</del><ins>+        public function __construct( $post ) {
+                foreach ( get_object_vars( $post ) as $key => $value )
+                        $this->$key = $value;
+        }
</ins><span class="cx">
</span><del>-        if ( $output == OBJECT ) {
-                return $_post;
-        } elseif ( $output == ARRAY_A ) {
-                $__post = get_object_vars($_post);
-                return $__post;
-        } elseif ( $output == ARRAY_N ) {
-                $__post = array_values(get_object_vars($_post));
-                return $__post;
-        } else {
-                return $_post;
</del><ins>+        public function __isset( $key ) {
+                if ( 'ancestors' == $key )
+                        return true;
+
+                return metadata_exists( 'post', $this->ID, $key );
</ins><span class="cx">         }
</span><ins>+
+        public function &__get( $key ) {
+                if ( 'ancestors' == $key ) {
+                        $value = get_post_ancestors( $this );
+                } else {
+                        $value = get_post_meta( $this->ID, $key, true );
+                }
+
+                if ( $this->filter ) {
+                        $value = sanitize_post_field( $key, $value, $this->ID, $this->filter );
+                }
+
+                return $value;
+        }
+
+        public function filter( $filter ) {
+                if ( $this->filter == $filter )
+                        return $this;
+
+                if ( $filter == 'raw' )
+                        return self::get_instance( $this->ID );
+
+                return sanitize_post( $this, $filter );
+        }
+
+        public function to_array() {
+                $post = get_object_vars( $this );
+                $post['ancestors'] = array();
+
+                return $post;
+        }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -433,16 +522,31 @@
</span><span class="cx"> * @param int|object $post Post ID or post object
</span><span class="cx"> * @return array Ancestor IDs or empty array if none are found.
</span><span class="cx"> */
</span><del>-function get_post_ancestors($post) {
-        $post = get_post($post);
</del><ins>+function get_post_ancestors( $post ) {
+        if ( ! $post )
+                return false;
</ins><span class="cx">
</span><del>-        if ( ! isset( $post->ancestors ) )
-                _get_post_ancestors( $post );
</del><ins>+        $post = get_post( $post );
</ins><span class="cx">
</span><del>-        if ( ! empty( $post->ancestors ) )
-                return $post->ancestors;
</del><ins>+        if ( ! $ancestors = wp_cache_get( $post->ID, 'post_ancestors' ) ) {
+                $ancestors = array();
</ins><span class="cx">
</span><del>-        return array();
</del><ins>+                if ( !empty( $post->post_parent ) && $post->ID != $post->post_parent ) {
+                        $id = $ancestors[] = $post->post_parent;
+
+                        while ( $ancestor = get_post( $id ) ) {
+                                // Loop detection: If the ancestor has been seen before, break.
+                                if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) )
+                                        break;
+
+                                $id = $ancestors[] = $ancestor->post_parent;
+                        }
+                }
+
+                wp_cache_add( $post->ID, $ancestors, 'post_ancestors' );
+        }
+
+        return $ancestors;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -460,16 +564,12 @@
</span><span class="cx"> * @param string $field Post field name
</span><span class="cx"> * @param id $post Post ID
</span><span class="cx"> * @param string $context Optional. How to filter the field. Default is display.
</span><del>- * @return WP_Error|string Value in post field or WP_Error on failure
</del><ins>+ * @return bool|string False on failure or returns the value in post field
</ins><span class="cx"> */
</span><span class="cx"> function get_post_field( $field, $post, $context = 'display' ) {
</span><del>-        $post = (int) $post;
</del><span class="cx">         $post = get_post( $post );
</span><span class="cx">
</span><del>-        if ( is_wp_error($post) )
-                return $post;
-
-        if ( !is_object($post) )
</del><ins>+        if ( !$post )
</ins><span class="cx">                 return '';
</span><span class="cx">
</span><span class="cx">         if ( !isset($post->$field) )
</span><span class="lines">@@ -3363,13 +3463,8 @@
</span><span class="cx">                 $page = get_page($page);
</span><span class="cx">         $uri = $page->post_name;
</span><span class="cx">
</span><del>-        // A page cannot be it's own parent.
-        if ( $page->post_parent == $page->ID )
-                return $uri;
-
-        while ($page->post_parent != 0) {
-                $page = get_page($page->post_parent);
-                $uri = $page->post_name . "/" . $uri;
</del><ins>+        foreach ( $page->ancestors as $parent ) {
+                $uri = get_page($parent)->post_name . "/" . $uri;
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         return $uri;
</span><span class="lines">@@ -3423,8 +3518,10 @@
</span><span class="cx">         $key = md5( serialize( compact(array_keys($defaults)) ) );
</span><span class="cx">         if ( $cache = wp_cache_get( 'get_pages', 'posts' ) ) {
</span><span class="cx">                 if ( is_array($cache) && isset( $cache[ $key ] ) ) {
</span><del>-                        $pages = apply_filters('get_pages', $cache[ $key ], $r );
-                        return $pages;
</del><ins>+                        // Convert to WP_Post instances
+                        $pages = array_map( 'get_post', $cache[ $key ] );
+
+                        return apply_filters( 'get_pages', $pages, $r );
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -3598,6 +3695,9 @@
</span><span class="cx">         $cache[ $key ] = $pages;
</span><span class="cx">         wp_cache_set( 'get_pages', $cache, 'posts' );
</span><span class="cx">
</span><ins>+        // Convert to WP_Post instances
+        $pages = array_map( 'get_post', $pages );
+
</ins><span class="cx">         $pages = apply_filters('get_pages', $pages, $r);
</span><span class="cx">
</span><span class="cx">         return $pages;
</span><span class="lines">@@ -4631,45 +4731,6 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Retrieve post ancestors and append to post ancestors property.
- *
- * Will only retrieve ancestors once, if property is already set, then nothing
- * will be done. If there is not a parent post, or post ID and post parent ID
- * are the same then nothing will be done.
- *
- * The parameter is passed by reference, so nothing needs to be returned. The
- * property will be updated and can be referenced after the function is
- * complete. The post parent will be an ancestor and the parent of the post
- * parent will be an ancestor. There will only be two ancestors at the most.
- *
- * @since 2.5.0
- * @access private
- * @uses $wpdb
- *
- * @param object $_post Post data.
- * @return null When nothing needs to be done.
- */
-function _get_post_ancestors(&$_post) {
-        global $wpdb;
-
-        if ( isset($_post->ancestors) )
-                return;
-
-        $_post->ancestors = array();
-
-        if ( empty($_post->post_parent) || $_post->ID == $_post->post_parent )
-                return;
-
-        $id = $_post->ancestors[] = (int) $_post->post_parent;
-        while ( $ancestor = $wpdb->get_var( $wpdb->prepare("SELECT `post_parent` FROM $wpdb->posts WHERE ID = %d LIMIT 1", $id) ) ) {
-                // Loop detection: If the ancestor has been seen before, break.
-                if ( ( $ancestor == $_post->ID ) || in_array($ancestor, $_post->ancestors) )
-                        break;
-                $id = $_post->ancestors[] = (int) $ancestor;
-        }
-}
-
-/**
</del><span class="cx"> * Determines which fields of posts are to be saved in revisions.
</span><span class="cx"> *
</span><span class="cx"> * Does two things. If passed a post *array*, it will return a post array ready
</span></span></pre></div>
<a id="trunkwpincludesqueryphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/query.php (21558 => 21559)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/query.php        2012-08-20 19:43:16 UTC (rev 21558)
+++ trunk/wp-includes/query.php        2012-08-20 19:47:52 UTC (rev 21559)
</span><span class="lines">@@ -2643,19 +2643,20 @@
</span><span class="cx">
</span><span class="cx">                         if ( $ids ) {
</span><span class="cx">                                 $this->set_found_posts( $q, $limits );
</span><del>-
</del><span class="cx">                                 _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
</span><del>-
-                                $this->posts = array_map( 'get_post', $ids );
</del><ins>+                                $this->posts = $ids;
</ins><span class="cx">                         } else {
</span><ins>+                                $this->posts = array();
</ins><span class="cx">                                 $this->found_posts = $this->max_num_pages = 0;
</span><del>-                                $this->posts = array();
</del><span class="cx">                         }
</span><span class="cx">                 } else {
</span><span class="cx">                         $this->posts = $wpdb->get_results( $this->request );
</span><span class="cx">                         $this->set_found_posts( $q, $limits );
</span><span class="cx">                 }
</span><span class="cx">
</span><ins>+                // Convert to WP_Post objects
+                $this->posts = array_map( 'get_post', $this->posts );
+
</ins><span class="cx">                 // Raw results filter. Prior to status checks.
</span><span class="cx">                 if ( !$q['suppress_filters'] )
</span><span class="cx">                         $this->posts = apply_filters_ref_array('posts_results', array( $this->posts, &$this ) );
</span></span></pre></div>
<a id="trunkwpincludestaxonomyphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/taxonomy.php (21558 => 21559)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/taxonomy.php        2012-08-20 19:43:16 UTC (rev 21558)
+++ trunk/wp-includes/taxonomy.php        2012-08-20 19:47:52 UTC (rev 21559)
</span><span class="lines">@@ -3221,16 +3221,8 @@
</span><span class="cx">                         $ancestors[] = (int) $term->parent;
</span><span class="cx">                         $term = get_term($term->parent, $object_type);
</span><span class="cx">                 }
</span><del>-        } elseif ( null !== get_post_type_object( $object_type ) ) {
-                $object = get_post($object_id);
-                if ( ! is_wp_error( $object ) && isset( $object->ancestors ) && is_array( $object->ancestors ) )
-                        $ancestors = $object->ancestors;
-                else {
-                        while ( ! is_wp_error($object) && ! empty( $object->post_parent ) && ! in_array( $object->post_parent, $ancestors ) ) {
-                                $ancestors[] = (int) $object->post_parent;
-                                $object = get_post($object->post_parent);
-                        }
-                }
</del><ins>+        } elseif ( post_type_exists( $object_type ) ) {
+                $ancestors = get_post_ancestors($object_id);
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         return apply_filters('get_ancestors', $ancestors, $object_id, $object_type);
</span></span></pre>
</div>
</div>
</body>
</html>