Allow `setup_postdata()` to accept a post ID.

Previously, it accepted only a full post object.

Props sc0ttclark, mordauk, wonderboymusic.
Fixes #30970.
Built from https://develop.svn.wordpress.org/trunk@34089


git-svn-id: http://core.svn.wordpress.org/trunk@34057 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2015-09-12 20:58:23 +00:00
parent e0b1340461
commit fc884dc7ec
2 changed files with 14 additions and 4 deletions

View File

@ -4616,6 +4616,7 @@ class WP_Query {
* Set up global post data. * Set up global post data.
* *
* @since 4.1.0 * @since 4.1.0
* @since 4.4.0 Added the ability to pass a post ID to `$post`.
* *
* @global int $id * @global int $id
* @global WP_User $authordata * @global WP_User $authordata
@ -4627,12 +4628,20 @@ class WP_Query {
* @global int $more * @global int $more
* @global int $numpages * @global int $numpages
* *
* @param WP_Post $post Post data. * @param WP_Post|object|int $post WP_Post instance or Post ID/object.
* @return true True when finished. * @return true True when finished.
*/ */
public function setup_postdata( $post ) { public function setup_postdata( $post ) {
global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages; global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages;
if ( ! ( $post instanceof WP_Post ) ) {
$post = get_post( $post );
}
if ( ! $post ) {
return;
}
$id = (int) $post->ID; $id = (int) $post->ID;
$authordata = get_userdata($post->post_author); $authordata = get_userdata($post->post_author);
@ -4701,7 +4710,7 @@ class WP_Query {
public function reset_postdata() { public function reset_postdata() {
if ( ! empty( $this->post ) ) { if ( ! empty( $this->post ) ) {
$GLOBALS['post'] = $this->post; $GLOBALS['post'] = $this->post;
setup_postdata( $this->post ); $this->setup_postdata( $this->post );
} }
} }
} }
@ -4769,10 +4778,11 @@ function wp_old_slug_redirect() {
* Set up global post data. * Set up global post data.
* *
* @since 1.5.0 * @since 1.5.0
* @since 4.4.0 Added the ability to pass a post ID to `$post`.
* *
* @global WP_Query $wp_query * @global WP_Query $wp_query
* *
* @param object $post Post data. * @param WP_Post|object|int $post WP_Post instance or Post ID/object.
* @return bool True when finished. * @return bool True when finished.
*/ */
function setup_postdata( $post ) { function setup_postdata( $post ) {

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.4-alpha-34088'; $wp_version = '4.4-alpha-34089';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.