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 JOINing 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
This commit is contained in:
Scott Taylor 2015-09-26 06:41:26 +00:00
parent 0d8a80b14c
commit 4389962eb8
2 changed files with 40 additions and 1 deletions

View File

@ -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;
}
}
}

View File

@ -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.