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
This commit is contained in:
parent
1543fbf91b
commit
706a62a134
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user