2015-09-03 20:17:24 +02:00
|
|
|
<?php
|
2015-09-03 21:58:24 +02:00
|
|
|
/**
|
2015-09-26 09:04:28 +02:00
|
|
|
* Comment API: WP_Comment class
|
2015-09-03 21:58:24 +02:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Comments
|
|
|
|
* @since 4.4.0
|
|
|
|
*/
|
2015-09-03 20:17:24 +02:00
|
|
|
|
2015-09-03 21:58:24 +02:00
|
|
|
/**
|
|
|
|
* Core class used to organize comments as instantiated objects with defined members.
|
2015-09-03 20:17:24 +02:00
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
*/
|
|
|
|
final class WP_Comment {
|
2015-09-03 21:58:24 +02:00
|
|
|
|
2015-09-03 20:17:24 +02:00
|
|
|
/**
|
2015-09-03 21:58:24 +02:00
|
|
|
* Comment ID.
|
|
|
|
*
|
2020-09-04 22:41:07 +02:00
|
|
|
* A numeric string, for compatibility reasons.
|
|
|
|
*
|
2015-09-03 21:58:24 +02:00
|
|
|
* @since 4.4.0
|
2020-09-04 22:41:07 +02:00
|
|
|
* @var string
|
2015-09-03 20:17:24 +02:00
|
|
|
*/
|
|
|
|
public $comment_ID;
|
2015-09-03 21:58:24 +02:00
|
|
|
|
2015-09-03 20:17:24 +02:00
|
|
|
/**
|
2015-09-03 21:58:24 +02:00
|
|
|
* ID of the post the comment is associated with.
|
|
|
|
*
|
2020-09-04 22:41:07 +02:00
|
|
|
* A numeric string, for compatibility reasons.
|
|
|
|
*
|
2015-09-03 21:58:24 +02:00
|
|
|
* @since 4.4.0
|
2020-09-04 22:41:07 +02:00
|
|
|
* @var string
|
2015-09-03 20:17:24 +02:00
|
|
|
*/
|
|
|
|
public $comment_post_ID = 0;
|
2015-09-03 21:58:24 +02:00
|
|
|
|
2015-09-03 20:17:24 +02:00
|
|
|
/**
|
2016-01-17 16:00:27 +01:00
|
|
|
* Comment author name.
|
2015-09-03 21:58:24 +02:00
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
* @var string
|
2015-09-03 20:17:24 +02:00
|
|
|
*/
|
2015-09-03 21:58:24 +02:00
|
|
|
public $comment_author = '';
|
|
|
|
|
2015-09-03 20:17:24 +02:00
|
|
|
/**
|
2015-09-03 21:58:24 +02:00
|
|
|
* Comment author email address.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
2015-09-03 20:17:24 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $comment_author_email = '';
|
2015-09-03 21:58:24 +02:00
|
|
|
|
2015-09-03 20:17:24 +02:00
|
|
|
/**
|
2015-09-03 21:58:24 +02:00
|
|
|
* Comment author URL.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
2015-09-03 20:17:24 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $comment_author_url = '';
|
2015-09-03 21:58:24 +02:00
|
|
|
|
2015-09-03 20:17:24 +02:00
|
|
|
/**
|
2015-09-03 21:58:24 +02:00
|
|
|
* Comment author IP address (IPv4 format).
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
2015-09-03 20:17:24 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $comment_author_IP = '';
|
2015-09-03 21:58:24 +02:00
|
|
|
|
2015-09-03 20:17:24 +02:00
|
|
|
/**
|
2015-09-03 21:58:24 +02:00
|
|
|
* Comment date in YYYY-MM-DD HH:MM:SS format.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
2015-09-03 20:17:24 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $comment_date = '0000-00-00 00:00:00';
|
2015-09-03 21:58:24 +02:00
|
|
|
|
2015-09-03 20:17:24 +02:00
|
|
|
/**
|
2015-09-03 21:58:24 +02:00
|
|
|
* Comment GMT date in YYYY-MM-DD HH::MM:SS format.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
2015-09-03 20:17:24 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $comment_date_gmt = '0000-00-00 00:00:00';
|
2015-09-03 21:58:24 +02:00
|
|
|
|
2015-09-03 20:17:24 +02:00
|
|
|
/**
|
2015-09-03 21:58:24 +02:00
|
|
|
* Comment content.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
2015-09-03 20:17:24 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $comment_content;
|
2015-09-03 21:58:24 +02:00
|
|
|
|
2015-09-03 20:17:24 +02:00
|
|
|
/**
|
2015-09-03 21:58:24 +02:00
|
|
|
* Comment karma count.
|
|
|
|
*
|
2020-09-04 22:41:07 +02:00
|
|
|
* A numeric string, for compatibility reasons.
|
|
|
|
*
|
2015-09-03 21:58:24 +02:00
|
|
|
* @since 4.4.0
|
2020-09-04 22:41:07 +02:00
|
|
|
* @var string
|
2015-09-03 20:17:24 +02:00
|
|
|
*/
|
|
|
|
public $comment_karma = 0;
|
2015-09-03 21:58:24 +02:00
|
|
|
|
2015-09-03 20:17:24 +02:00
|
|
|
/**
|
2015-09-03 21:58:24 +02:00
|
|
|
* Comment approval status.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
2015-09-03 20:17:24 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $comment_approved = '1';
|
2015-09-03 21:58:24 +02:00
|
|
|
|
2015-09-03 20:17:24 +02:00
|
|
|
/**
|
2015-09-03 21:58:24 +02:00
|
|
|
* Comment author HTTP user agent.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
2015-09-03 20:17:24 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $comment_agent = '';
|
2015-09-03 21:58:24 +02:00
|
|
|
|
2015-09-03 20:17:24 +02:00
|
|
|
/**
|
2015-09-03 21:58:24 +02:00
|
|
|
* Comment type.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
2020-04-17 21:35:06 +02:00
|
|
|
* @since 5.5.0 Default value changed to `comment`.
|
2015-09-03 20:17:24 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
2020-04-17 21:35:06 +02:00
|
|
|
public $comment_type = 'comment';
|
2015-09-03 21:58:24 +02:00
|
|
|
|
2015-09-03 20:17:24 +02:00
|
|
|
/**
|
2015-09-03 21:58:24 +02:00
|
|
|
* Parent comment ID.
|
|
|
|
*
|
2020-09-04 22:41:07 +02:00
|
|
|
* A numeric string, for compatibility reasons.
|
|
|
|
*
|
2015-09-03 21:58:24 +02:00
|
|
|
* @since 4.4.0
|
2020-09-04 22:41:07 +02:00
|
|
|
* @var string
|
2015-09-03 20:17:24 +02:00
|
|
|
*/
|
|
|
|
public $comment_parent = 0;
|
2015-09-03 21:58:24 +02:00
|
|
|
|
2015-09-03 20:17:24 +02:00
|
|
|
/**
|
2015-09-03 21:58:24 +02:00
|
|
|
* Comment author ID.
|
|
|
|
*
|
2020-09-04 22:41:07 +02:00
|
|
|
* A numeric string, for compatibility reasons.
|
|
|
|
*
|
2015-09-03 21:58:24 +02:00
|
|
|
* @since 4.4.0
|
2020-09-04 22:41:07 +02:00
|
|
|
* @var string
|
2015-09-03 20:17:24 +02:00
|
|
|
*/
|
|
|
|
public $user_id = 0;
|
|
|
|
|
2015-09-25 17:13:24 +02:00
|
|
|
/**
|
|
|
|
* Comment children.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $children;
|
|
|
|
|
2015-10-01 05:58:23 +02:00
|
|
|
/**
|
|
|
|
* Whether children have been populated for this comment object.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $populated_children = false;
|
|
|
|
|
2015-09-26 18:02:25 +02:00
|
|
|
/**
|
|
|
|
* Post fields.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $post_fields = array( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_content_filtered', 'post_parent', 'guid', 'menu_order', 'post_type', 'post_mime_type', 'comment_count' );
|
|
|
|
|
2015-09-03 20:17:24 +02:00
|
|
|
/**
|
2015-09-03 21:58:24 +02:00
|
|
|
* Retrieves a WP_Comment instance.
|
2015-09-03 20:17:24 +02:00
|
|
|
*
|
2015-09-03 21:58:24 +02:00
|
|
|
* @since 4.4.0
|
2015-09-03 20:17:24 +02:00
|
|
|
*
|
2015-09-03 21:58:24 +02:00
|
|
|
* @global wpdb $wpdb WordPress database abstraction object.
|
2015-09-03 20:17:24 +02:00
|
|
|
*
|
|
|
|
* @param int $id Comment ID.
|
2015-09-03 21:58:24 +02:00
|
|
|
* @return WP_Comment|false Comment object, otherwise false.
|
2015-09-03 20:17:24 +02:00
|
|
|
*/
|
|
|
|
public static function get_instance( $id ) {
|
|
|
|
global $wpdb;
|
|
|
|
|
2017-01-26 17:53:41 +01:00
|
|
|
$comment_id = (int) $id;
|
|
|
|
if ( ! $comment_id ) {
|
2015-09-03 20:17:24 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$_comment = wp_cache_get( $comment_id, 'comment' );
|
|
|
|
|
|
|
|
if ( ! $_comment ) {
|
|
|
|
$_comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id ) );
|
|
|
|
|
|
|
|
if ( ! $_comment ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
wp_cache_add( $_comment->comment_ID, $_comment, 'comment' );
|
|
|
|
}
|
|
|
|
|
|
|
|
return new WP_Comment( $_comment );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
2015-09-03 21:58:24 +02:00
|
|
|
* Populates properties with object vars.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
*
|
2015-09-03 20:17:24 +02:00
|
|
|
* @param WP_Comment $comment Comment object.
|
|
|
|
*/
|
|
|
|
public function __construct( $comment ) {
|
|
|
|
foreach ( get_object_vars( $comment ) as $key => $value ) {
|
|
|
|
$this->$key = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-03 21:58:24 +02:00
|
|
|
/**
|
|
|
|
* Convert object to array.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
*
|
|
|
|
* @return array Object as array.
|
|
|
|
*/
|
2015-09-03 20:17:24 +02:00
|
|
|
public function to_array() {
|
|
|
|
return get_object_vars( $this );
|
|
|
|
}
|
2015-09-25 17:13:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the children of a comment.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
*
|
2015-09-26 04:25:26 +02:00
|
|
|
* @param array $args {
|
|
|
|
* Array of arguments used to pass to get_comments() and determine format.
|
|
|
|
*
|
|
|
|
* @type string $format Return value format. 'tree' for a hierarchical tree, 'flat' for a flattened array.
|
|
|
|
* Default 'tree'.
|
|
|
|
* @type string $status Comment status to limit results by. Accepts 'hold' (`comment_status=0`),
|
|
|
|
* 'approve' (`comment_status=1`), 'all', or a custom comment status.
|
|
|
|
* Default 'all'.
|
|
|
|
* @type string $hierarchical Whether to include comment descendants in the results.
|
|
|
|
* 'threaded' returns a tree, with each comment's children
|
|
|
|
* stored in a `children` property on the `WP_Comment` object.
|
|
|
|
* 'flat' returns a flat array of found comments plus their children.
|
|
|
|
* Pass `false` to leave out descendants.
|
|
|
|
* The parameter is ignored (forced to `false`) when `$fields` is 'ids' or 'counts'.
|
|
|
|
* Accepts 'threaded', 'flat', or false. Default: 'threaded'.
|
|
|
|
* @type string|array $orderby Comment status or array of statuses. To use 'meta_value'
|
|
|
|
* or 'meta_value_num', `$meta_key` must also be defined.
|
|
|
|
* To sort by a specific `$meta_query` clause, use that
|
|
|
|
* clause's array key. Accepts 'comment_agent',
|
|
|
|
* 'comment_approved', 'comment_author',
|
|
|
|
* 'comment_author_email', 'comment_author_IP',
|
|
|
|
* 'comment_author_url', 'comment_content', 'comment_date',
|
|
|
|
* 'comment_date_gmt', 'comment_ID', 'comment_karma',
|
|
|
|
* 'comment_parent', 'comment_post_ID', 'comment_type',
|
|
|
|
* 'user_id', 'comment__in', 'meta_value', 'meta_value_num',
|
|
|
|
* the value of $meta_key, and the array keys of
|
|
|
|
* `$meta_query`. Also accepts false, an empty array, or
|
|
|
|
* 'none' to disable `ORDER BY` clause.
|
|
|
|
* }
|
2019-11-05 22:27:02 +01:00
|
|
|
* @return WP_Comment[] Array of `WP_Comment` objects.
|
2015-09-25 17:13:24 +02:00
|
|
|
*/
|
2015-09-26 04:25:26 +02:00
|
|
|
public function get_children( $args = array() ) {
|
|
|
|
$defaults = array(
|
2017-12-01 00:11:00 +01:00
|
|
|
'format' => 'tree',
|
|
|
|
'status' => 'all',
|
2015-09-26 04:25:26 +02:00
|
|
|
'hierarchical' => 'threaded',
|
2017-12-01 00:11:00 +01:00
|
|
|
'orderby' => '',
|
2015-09-26 04:25:26 +02:00
|
|
|
);
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$_args = wp_parse_args( $args, $defaults );
|
2015-09-26 04:25:26 +02:00
|
|
|
$_args['parent'] = $this->comment_ID;
|
|
|
|
|
2015-09-25 17:13:24 +02:00
|
|
|
if ( is_null( $this->children ) ) {
|
2015-10-01 05:58:23 +02:00
|
|
|
if ( $this->populated_children ) {
|
|
|
|
$this->children = array();
|
|
|
|
} else {
|
|
|
|
$this->children = get_comments( $_args );
|
|
|
|
}
|
2015-09-25 17:13:24 +02:00
|
|
|
}
|
|
|
|
|
2015-09-26 04:25:26 +02:00
|
|
|
if ( 'flat' === $_args['format'] ) {
|
Force comment pagination on single posts.
Previously, the 'page_comments' toggle allowed users to disable comment
pagination. This toggle was only superficial, however. Even with
'page_comments' turned on, `comments_template()` loaded all of a post's
comments into memory, and passed them to `wp_list_comments()` and
`Walker_Comment`, the latter of which produced markup for only the
current page of comments. In other words, it was possible to enable
'page_comments', thereby showing only a subset of a post's comments on a given
page, but all comments continued to be loaded in the background. This technique
scaled poorly. Posts with hundreds or thousands of comments would load slowly,
or not at all, even when the 'comments_per_page' setting was set to a
reasonable number.
Recent changesets have addressed this problem through more efficient tree-
walking, better descendant caching, and more selective queries for top-level
post comments. The current changeset completes the project by addressing the
root issue: that loading a post causes all of its comments to be loaded too.
Here's the breakdown:
* Comment pagination is now forced. Setting 'page_comments' to false leads to evil things when you have many comments. If you want to avoid pagination, set 'comments_per_page' to something high.
* The 'page_comments' setting has been expunged from options-discussion.php, and from places in the codebase where it was referenced. For plugins relying on 'page_comments', we now force the value to `true` with a `pre_option` filter.
* `comments_template()` now queries for an appropriately small number of comments. Usually, this means the `comments_per_page` value.
* To preserve the current (odd) behavior for comment pagination links, some unholy hacks have been inserted into `comments_template()`. The ugliness is insulated in this function for backward compatibility and to minimize collateral damage. A side-effect is that, for certain settings of 'default_comments_page', up to 2x the value of `comments_per_page` might be fetched at a time.
* In support of these changes, a `$format` parameter has been added to `WP_Comment::get_children()`. This param allows you to request a flattened array of comment children, suitable for feeding into `Walker_Comment`.
* `WP_Query` loops are now informed about total available comment counts and comment pages by the `WP_Comment_Query` (`found_comments`, `max_num_pages`), instead of by `Walker_Comment`.
Aside from radical performance improvements in the case of a post with many
comments, this changeset fixes a bug that caused the first page of comments to
be partial (`found_comments` % `comments_per_page`), rather than the last, as
you'd expect.
Props boonebgorges, wonderboymusic.
Fixes #8071.
Built from https://develop.svn.wordpress.org/trunk@34561
git-svn-id: http://core.svn.wordpress.org/trunk@34525 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-25 22:40:25 +02:00
|
|
|
$children = array();
|
|
|
|
foreach ( $this->children as $child ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$child_args = $_args;
|
2015-09-26 04:25:26 +02:00
|
|
|
$child_args['format'] = 'flat';
|
|
|
|
// get_children() resets this value automatically.
|
|
|
|
unset( $child_args['parent'] );
|
|
|
|
|
|
|
|
$children = array_merge( $children, array( $child ), $child->get_children( $child_args ) );
|
Force comment pagination on single posts.
Previously, the 'page_comments' toggle allowed users to disable comment
pagination. This toggle was only superficial, however. Even with
'page_comments' turned on, `comments_template()` loaded all of a post's
comments into memory, and passed them to `wp_list_comments()` and
`Walker_Comment`, the latter of which produced markup for only the
current page of comments. In other words, it was possible to enable
'page_comments', thereby showing only a subset of a post's comments on a given
page, but all comments continued to be loaded in the background. This technique
scaled poorly. Posts with hundreds or thousands of comments would load slowly,
or not at all, even when the 'comments_per_page' setting was set to a
reasonable number.
Recent changesets have addressed this problem through more efficient tree-
walking, better descendant caching, and more selective queries for top-level
post comments. The current changeset completes the project by addressing the
root issue: that loading a post causes all of its comments to be loaded too.
Here's the breakdown:
* Comment pagination is now forced. Setting 'page_comments' to false leads to evil things when you have many comments. If you want to avoid pagination, set 'comments_per_page' to something high.
* The 'page_comments' setting has been expunged from options-discussion.php, and from places in the codebase where it was referenced. For plugins relying on 'page_comments', we now force the value to `true` with a `pre_option` filter.
* `comments_template()` now queries for an appropriately small number of comments. Usually, this means the `comments_per_page` value.
* To preserve the current (odd) behavior for comment pagination links, some unholy hacks have been inserted into `comments_template()`. The ugliness is insulated in this function for backward compatibility and to minimize collateral damage. A side-effect is that, for certain settings of 'default_comments_page', up to 2x the value of `comments_per_page` might be fetched at a time.
* In support of these changes, a `$format` parameter has been added to `WP_Comment::get_children()`. This param allows you to request a flattened array of comment children, suitable for feeding into `Walker_Comment`.
* `WP_Query` loops are now informed about total available comment counts and comment pages by the `WP_Comment_Query` (`found_comments`, `max_num_pages`), instead of by `Walker_Comment`.
Aside from radical performance improvements in the case of a post with many
comments, this changeset fixes a bug that caused the first page of comments to
be partial (`found_comments` % `comments_per_page`), rather than the last, as
you'd expect.
Props boonebgorges, wonderboymusic.
Fixes #8071.
Built from https://develop.svn.wordpress.org/trunk@34561
git-svn-id: http://core.svn.wordpress.org/trunk@34525 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-25 22:40:25 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$children = $this->children;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $children;
|
2015-09-25 17:13:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a child to the comment.
|
|
|
|
*
|
|
|
|
* Used by `WP_Comment_Query` when bulk-filling descendants.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
*
|
|
|
|
* @param WP_Comment $child Child comment.
|
|
|
|
*/
|
|
|
|
public function add_child( WP_Comment $child ) {
|
2015-09-26 16:41:24 +02:00
|
|
|
$this->children[ $child->comment_ID ] = $child;
|
2015-09-25 17:13:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a child comment by ID.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
*
|
|
|
|
* @param int $child_id ID of the child.
|
|
|
|
* @return WP_Comment|bool Returns the comment object if found, otherwise false.
|
|
|
|
*/
|
|
|
|
public function get_child( $child_id ) {
|
2015-09-26 16:41:24 +02:00
|
|
|
if ( isset( $this->children[ $child_id ] ) ) {
|
|
|
|
return $this->children[ $child_id ];
|
2015-09-25 17:13:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-26 08:41:26 +02:00
|
|
|
|
2015-10-01 05:58:23 +02:00
|
|
|
/**
|
|
|
|
* Set the 'populated_children' flag.
|
|
|
|
*
|
|
|
|
* This flag is important for ensuring that calling `get_children()` on a childless comment will not trigger
|
|
|
|
* unneeded database queries.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
2016-01-10 02:26:25 +01:00
|
|
|
*
|
|
|
|
* @param bool $set Whether the comment's children have already been populated.
|
2015-10-01 05:58:23 +02:00
|
|
|
*/
|
|
|
|
public function populated_children( $set ) {
|
|
|
|
$this->populated_children = (bool) $set;
|
|
|
|
}
|
|
|
|
|
2015-09-26 08:41:26 +02:00
|
|
|
/**
|
2015-09-26 18:02:25 +02:00
|
|
|
* Check whether a non-public property is set.
|
|
|
|
*
|
|
|
|
* If `$name` matches a post field, the comment post will be loaded and the post's value checked.
|
2015-09-26 08:41:26 +02:00
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
*
|
2015-09-26 18:02:25 +02:00
|
|
|
* @param string $name Property name.
|
2015-09-26 08:41:26 +02:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function __isset( $name ) {
|
2020-04-05 05:02:11 +02:00
|
|
|
if ( in_array( $name, $this->post_fields, true ) && 0 !== (int) $this->comment_post_ID ) {
|
2015-09-26 18:02:25 +02:00
|
|
|
$post = get_post( $this->comment_post_ID );
|
2015-09-26 08:41:26 +02:00
|
|
|
return property_exists( $post, $name );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-26 18:02:25 +02:00
|
|
|
* Magic getter.
|
|
|
|
*
|
|
|
|
* If `$name` matches a post field, the comment post will be loaded and the post's value returned.
|
2015-09-26 08:41:26 +02:00
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function __get( $name ) {
|
2020-04-05 05:02:11 +02:00
|
|
|
if ( in_array( $name, $this->post_fields, true ) ) {
|
2015-09-26 18:02:25 +02:00
|
|
|
$post = get_post( $this->comment_post_ID );
|
2015-09-26 08:41:26 +02:00
|
|
|
return $post->$name;
|
|
|
|
}
|
|
|
|
}
|
2015-09-03 20:17:24 +02:00
|
|
|
}
|