From 4389962eb863f9f0dabc22755d6652d575a2eba9 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 26 Sep 2015 06:41:26 +0000 Subject: [PATCH] Comments: add `__get()` and `__set()` to `WP_Comment` to provide BC for plugins that are grabbing post properties from the comment object due to an (unintended?) side effect of `JOIN`ing with the posts table in `WP_Comment_Query`, see [17667]. `'fields'` used to default to `*`, so the `JOIN` would grab every field from both tables. #YOLO Since [34310], these properties no longer exist. We can lazy load them for plugins with the magic methods. Fixes #27571. Built from https://develop.svn.wordpress.org/trunk@34583 git-svn-id: http://core.svn.wordpress.org/trunk@34547 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-comment.php | 39 ++++++++++++++++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/wp-includes/class-wp-comment.php b/wp-includes/class-wp-comment.php index ab6bf14b55..d6336937e2 100644 --- a/wp-includes/class-wp-comment.php +++ b/wp-includes/class-wp-comment.php @@ -320,4 +320,43 @@ final class WP_Comment { return false; } + + /** + * Whether a comment has post from which to retrieve magic properties + * + * @since 4.4.0 + * @access public + * + * @param string $name + * @return bool + */ + public function __isset( $name ) { + if ( + 0 === (int) $this->comment_post_ID + || property_exists( $this, $name ) + ) { + return; + } + + $post = get_post( $this->comment_post_ID ); + if ( $post ) { + return property_exists( $post, $name ); + } + } + + /** + * Magic getter for $post properties + * + * @since 4.4.0 + * @access public + * + * @param string $name + * @return mixed + */ + public function __get( $name ) { + $post = get_post( $this->comment_post_ID ); + if ( $post ) { + return $post->$name; + } + } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 7e398de2c7..f7216eba3d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-34582'; +$wp_version = '4.4-alpha-34583'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.