Edit File by line
/home/barbar84/www/wp-inclu...
File: class-wp-comment.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Comment API: WP_Comment class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Comments
[5] Fix | Delete
* @since 4.4.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Core class used to organize comments as instantiated objects with defined members.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 4.4.0
[12] Fix | Delete
*/
[13] Fix | Delete
final class WP_Comment {
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* Comment ID.
[17] Fix | Delete
*
[18] Fix | Delete
* A numeric string, for compatibility reasons.
[19] Fix | Delete
*
[20] Fix | Delete
* @since 4.4.0
[21] Fix | Delete
* @var string
[22] Fix | Delete
*/
[23] Fix | Delete
public $comment_ID;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* ID of the post the comment is associated with.
[27] Fix | Delete
*
[28] Fix | Delete
* A numeric string, for compatibility reasons.
[29] Fix | Delete
*
[30] Fix | Delete
* @since 4.4.0
[31] Fix | Delete
* @var string
[32] Fix | Delete
*/
[33] Fix | Delete
public $comment_post_ID = 0;
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* Comment author name.
[37] Fix | Delete
*
[38] Fix | Delete
* @since 4.4.0
[39] Fix | Delete
* @var string
[40] Fix | Delete
*/
[41] Fix | Delete
public $comment_author = '';
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Comment author email address.
[45] Fix | Delete
*
[46] Fix | Delete
* @since 4.4.0
[47] Fix | Delete
* @var string
[48] Fix | Delete
*/
[49] Fix | Delete
public $comment_author_email = '';
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* Comment author URL.
[53] Fix | Delete
*
[54] Fix | Delete
* @since 4.4.0
[55] Fix | Delete
* @var string
[56] Fix | Delete
*/
[57] Fix | Delete
public $comment_author_url = '';
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Comment author IP address (IPv4 format).
[61] Fix | Delete
*
[62] Fix | Delete
* @since 4.4.0
[63] Fix | Delete
* @var string
[64] Fix | Delete
*/
[65] Fix | Delete
public $comment_author_IP = '';
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Comment date in YYYY-MM-DD HH:MM:SS format.
[69] Fix | Delete
*
[70] Fix | Delete
* @since 4.4.0
[71] Fix | Delete
* @var string
[72] Fix | Delete
*/
[73] Fix | Delete
public $comment_date = '0000-00-00 00:00:00';
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* Comment GMT date in YYYY-MM-DD HH::MM:SS format.
[77] Fix | Delete
*
[78] Fix | Delete
* @since 4.4.0
[79] Fix | Delete
* @var string
[80] Fix | Delete
*/
[81] Fix | Delete
public $comment_date_gmt = '0000-00-00 00:00:00';
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* Comment content.
[85] Fix | Delete
*
[86] Fix | Delete
* @since 4.4.0
[87] Fix | Delete
* @var string
[88] Fix | Delete
*/
[89] Fix | Delete
public $comment_content;
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Comment karma count.
[93] Fix | Delete
*
[94] Fix | Delete
* A numeric string, for compatibility reasons.
[95] Fix | Delete
*
[96] Fix | Delete
* @since 4.4.0
[97] Fix | Delete
* @var string
[98] Fix | Delete
*/
[99] Fix | Delete
public $comment_karma = 0;
[100] Fix | Delete
[101] Fix | Delete
/**
[102] Fix | Delete
* Comment approval status.
[103] Fix | Delete
*
[104] Fix | Delete
* @since 4.4.0
[105] Fix | Delete
* @var string
[106] Fix | Delete
*/
[107] Fix | Delete
public $comment_approved = '1';
[108] Fix | Delete
[109] Fix | Delete
/**
[110] Fix | Delete
* Comment author HTTP user agent.
[111] Fix | Delete
*
[112] Fix | Delete
* @since 4.4.0
[113] Fix | Delete
* @var string
[114] Fix | Delete
*/
[115] Fix | Delete
public $comment_agent = '';
[116] Fix | Delete
[117] Fix | Delete
/**
[118] Fix | Delete
* Comment type.
[119] Fix | Delete
*
[120] Fix | Delete
* @since 4.4.0
[121] Fix | Delete
* @since 5.5.0 Default value changed to `comment`.
[122] Fix | Delete
* @var string
[123] Fix | Delete
*/
[124] Fix | Delete
public $comment_type = 'comment';
[125] Fix | Delete
[126] Fix | Delete
/**
[127] Fix | Delete
* Parent comment ID.
[128] Fix | Delete
*
[129] Fix | Delete
* A numeric string, for compatibility reasons.
[130] Fix | Delete
*
[131] Fix | Delete
* @since 4.4.0
[132] Fix | Delete
* @var string
[133] Fix | Delete
*/
[134] Fix | Delete
public $comment_parent = 0;
[135] Fix | Delete
[136] Fix | Delete
/**
[137] Fix | Delete
* Comment author ID.
[138] Fix | Delete
*
[139] Fix | Delete
* A numeric string, for compatibility reasons.
[140] Fix | Delete
*
[141] Fix | Delete
* @since 4.4.0
[142] Fix | Delete
* @var string
[143] Fix | Delete
*/
[144] Fix | Delete
public $user_id = 0;
[145] Fix | Delete
[146] Fix | Delete
/**
[147] Fix | Delete
* Comment children.
[148] Fix | Delete
*
[149] Fix | Delete
* @since 4.4.0
[150] Fix | Delete
* @var array
[151] Fix | Delete
*/
[152] Fix | Delete
protected $children;
[153] Fix | Delete
[154] Fix | Delete
/**
[155] Fix | Delete
* Whether children have been populated for this comment object.
[156] Fix | Delete
*
[157] Fix | Delete
* @since 4.4.0
[158] Fix | Delete
* @var bool
[159] Fix | Delete
*/
[160] Fix | Delete
protected $populated_children = false;
[161] Fix | Delete
[162] Fix | Delete
/**
[163] Fix | Delete
* Post fields.
[164] Fix | Delete
*
[165] Fix | Delete
* @since 4.4.0
[166] Fix | Delete
* @var array
[167] Fix | Delete
*/
[168] Fix | Delete
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' );
[169] Fix | Delete
[170] Fix | Delete
/**
[171] Fix | Delete
* Retrieves a WP_Comment instance.
[172] Fix | Delete
*
[173] Fix | Delete
* @since 4.4.0
[174] Fix | Delete
*
[175] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[176] Fix | Delete
*
[177] Fix | Delete
* @param int $id Comment ID.
[178] Fix | Delete
* @return WP_Comment|false Comment object, otherwise false.
[179] Fix | Delete
*/
[180] Fix | Delete
public static function get_instance( $id ) {
[181] Fix | Delete
global $wpdb;
[182] Fix | Delete
[183] Fix | Delete
$comment_id = (int) $id;
[184] Fix | Delete
if ( ! $comment_id ) {
[185] Fix | Delete
return false;
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
$_comment = wp_cache_get( $comment_id, 'comment' );
[189] Fix | Delete
[190] Fix | Delete
if ( ! $_comment ) {
[191] Fix | Delete
$_comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id ) );
[192] Fix | Delete
[193] Fix | Delete
if ( ! $_comment ) {
[194] Fix | Delete
return false;
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
wp_cache_add( $_comment->comment_ID, $_comment, 'comment' );
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
return new WP_Comment( $_comment );
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
/**
[204] Fix | Delete
* Constructor.
[205] Fix | Delete
*
[206] Fix | Delete
* Populates properties with object vars.
[207] Fix | Delete
*
[208] Fix | Delete
* @since 4.4.0
[209] Fix | Delete
*
[210] Fix | Delete
* @param WP_Comment $comment Comment object.
[211] Fix | Delete
*/
[212] Fix | Delete
public function __construct( $comment ) {
[213] Fix | Delete
foreach ( get_object_vars( $comment ) as $key => $value ) {
[214] Fix | Delete
$this->$key = $value;
[215] Fix | Delete
}
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
/**
[219] Fix | Delete
* Convert object to array.
[220] Fix | Delete
*
[221] Fix | Delete
* @since 4.4.0
[222] Fix | Delete
*
[223] Fix | Delete
* @return array Object as array.
[224] Fix | Delete
*/
[225] Fix | Delete
public function to_array() {
[226] Fix | Delete
return get_object_vars( $this );
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
/**
[230] Fix | Delete
* Get the children of a comment.
[231] Fix | Delete
*
[232] Fix | Delete
* @since 4.4.0
[233] Fix | Delete
*
[234] Fix | Delete
* @param array $args {
[235] Fix | Delete
* Array of arguments used to pass to get_comments() and determine format.
[236] Fix | Delete
*
[237] Fix | Delete
* @type string $format Return value format. 'tree' for a hierarchical tree, 'flat' for a flattened array.
[238] Fix | Delete
* Default 'tree'.
[239] Fix | Delete
* @type string $status Comment status to limit results by. Accepts 'hold' (`comment_status=0`),
[240] Fix | Delete
* 'approve' (`comment_status=1`), 'all', or a custom comment status.
[241] Fix | Delete
* Default 'all'.
[242] Fix | Delete
* @type string $hierarchical Whether to include comment descendants in the results.
[243] Fix | Delete
* 'threaded' returns a tree, with each comment's children
[244] Fix | Delete
* stored in a `children` property on the `WP_Comment` object.
[245] Fix | Delete
* 'flat' returns a flat array of found comments plus their children.
[246] Fix | Delete
* Pass `false` to leave out descendants.
[247] Fix | Delete
* The parameter is ignored (forced to `false`) when `$fields` is 'ids' or 'counts'.
[248] Fix | Delete
* Accepts 'threaded', 'flat', or false. Default: 'threaded'.
[249] Fix | Delete
* @type string|array $orderby Comment status or array of statuses. To use 'meta_value'
[250] Fix | Delete
* or 'meta_value_num', `$meta_key` must also be defined.
[251] Fix | Delete
* To sort by a specific `$meta_query` clause, use that
[252] Fix | Delete
* clause's array key. Accepts 'comment_agent',
[253] Fix | Delete
* 'comment_approved', 'comment_author',
[254] Fix | Delete
* 'comment_author_email', 'comment_author_IP',
[255] Fix | Delete
* 'comment_author_url', 'comment_content', 'comment_date',
[256] Fix | Delete
* 'comment_date_gmt', 'comment_ID', 'comment_karma',
[257] Fix | Delete
* 'comment_parent', 'comment_post_ID', 'comment_type',
[258] Fix | Delete
* 'user_id', 'comment__in', 'meta_value', 'meta_value_num',
[259] Fix | Delete
* the value of $meta_key, and the array keys of
[260] Fix | Delete
* `$meta_query`. Also accepts false, an empty array, or
[261] Fix | Delete
* 'none' to disable `ORDER BY` clause.
[262] Fix | Delete
* }
[263] Fix | Delete
* @return WP_Comment[] Array of `WP_Comment` objects.
[264] Fix | Delete
*/
[265] Fix | Delete
public function get_children( $args = array() ) {
[266] Fix | Delete
$defaults = array(
[267] Fix | Delete
'format' => 'tree',
[268] Fix | Delete
'status' => 'all',
[269] Fix | Delete
'hierarchical' => 'threaded',
[270] Fix | Delete
'orderby' => '',
[271] Fix | Delete
);
[272] Fix | Delete
[273] Fix | Delete
$_args = wp_parse_args( $args, $defaults );
[274] Fix | Delete
$_args['parent'] = $this->comment_ID;
[275] Fix | Delete
[276] Fix | Delete
if ( is_null( $this->children ) ) {
[277] Fix | Delete
if ( $this->populated_children ) {
[278] Fix | Delete
$this->children = array();
[279] Fix | Delete
} else {
[280] Fix | Delete
$this->children = get_comments( $_args );
[281] Fix | Delete
}
[282] Fix | Delete
}
[283] Fix | Delete
[284] Fix | Delete
if ( 'flat' === $_args['format'] ) {
[285] Fix | Delete
$children = array();
[286] Fix | Delete
foreach ( $this->children as $child ) {
[287] Fix | Delete
$child_args = $_args;
[288] Fix | Delete
$child_args['format'] = 'flat';
[289] Fix | Delete
// get_children() resets this value automatically.
[290] Fix | Delete
unset( $child_args['parent'] );
[291] Fix | Delete
[292] Fix | Delete
$children = array_merge( $children, array( $child ), $child->get_children( $child_args ) );
[293] Fix | Delete
}
[294] Fix | Delete
} else {
[295] Fix | Delete
$children = $this->children;
[296] Fix | Delete
}
[297] Fix | Delete
[298] Fix | Delete
return $children;
[299] Fix | Delete
}
[300] Fix | Delete
[301] Fix | Delete
/**
[302] Fix | Delete
* Add a child to the comment.
[303] Fix | Delete
*
[304] Fix | Delete
* Used by `WP_Comment_Query` when bulk-filling descendants.
[305] Fix | Delete
*
[306] Fix | Delete
* @since 4.4.0
[307] Fix | Delete
*
[308] Fix | Delete
* @param WP_Comment $child Child comment.
[309] Fix | Delete
*/
[310] Fix | Delete
public function add_child( WP_Comment $child ) {
[311] Fix | Delete
$this->children[ $child->comment_ID ] = $child;
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
/**
[315] Fix | Delete
* Get a child comment by ID.
[316] Fix | Delete
*
[317] Fix | Delete
* @since 4.4.0
[318] Fix | Delete
*
[319] Fix | Delete
* @param int $child_id ID of the child.
[320] Fix | Delete
* @return WP_Comment|false Returns the comment object if found, otherwise false.
[321] Fix | Delete
*/
[322] Fix | Delete
public function get_child( $child_id ) {
[323] Fix | Delete
if ( isset( $this->children[ $child_id ] ) ) {
[324] Fix | Delete
return $this->children[ $child_id ];
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
return false;
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
/**
[331] Fix | Delete
* Set the 'populated_children' flag.
[332] Fix | Delete
*
[333] Fix | Delete
* This flag is important for ensuring that calling `get_children()` on a childless comment will not trigger
[334] Fix | Delete
* unneeded database queries.
[335] Fix | Delete
*
[336] Fix | Delete
* @since 4.4.0
[337] Fix | Delete
*
[338] Fix | Delete
* @param bool $set Whether the comment's children have already been populated.
[339] Fix | Delete
*/
[340] Fix | Delete
public function populated_children( $set ) {
[341] Fix | Delete
$this->populated_children = (bool) $set;
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
/**
[345] Fix | Delete
* Check whether a non-public property is set.
[346] Fix | Delete
*
[347] Fix | Delete
* If `$name` matches a post field, the comment post will be loaded and the post's value checked.
[348] Fix | Delete
*
[349] Fix | Delete
* @since 4.4.0
[350] Fix | Delete
*
[351] Fix | Delete
* @param string $name Property name.
[352] Fix | Delete
* @return bool
[353] Fix | Delete
*/
[354] Fix | Delete
public function __isset( $name ) {
[355] Fix | Delete
if ( in_array( $name, $this->post_fields, true ) && 0 !== (int) $this->comment_post_ID ) {
[356] Fix | Delete
$post = get_post( $this->comment_post_ID );
[357] Fix | Delete
return property_exists( $post, $name );
[358] Fix | Delete
}
[359] Fix | Delete
}
[360] Fix | Delete
[361] Fix | Delete
/**
[362] Fix | Delete
* Magic getter.
[363] Fix | Delete
*
[364] Fix | Delete
* If `$name` matches a post field, the comment post will be loaded and the post's value returned.
[365] Fix | Delete
*
[366] Fix | Delete
* @since 4.4.0
[367] Fix | Delete
*
[368] Fix | Delete
* @param string $name
[369] Fix | Delete
* @return mixed
[370] Fix | Delete
*/
[371] Fix | Delete
public function __get( $name ) {
[372] Fix | Delete
if ( in_array( $name, $this->post_fields, true ) ) {
[373] Fix | Delete
$post = get_post( $this->comment_post_ID );
[374] Fix | Delete
return $post->$name;
[375] Fix | Delete
}
[376] Fix | Delete
}
[377] Fix | Delete
}
[378] Fix | Delete
[379] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function