From 706a62a13429d9e75ca8c5ff47b9b4732a473bb3 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 26 Sep 2015 06:40:39 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@34583 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-comment.php | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/wp-includes/class-wp-comment.php b/src/wp-includes/class-wp-comment.php index ab6bf14b55..d6336937e2 100644 --- a/src/wp-includes/class-wp-comment.php +++ b/src/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; + } + } }