2015-09-03 20:17:24 +02:00
|
|
|
<?php
|
2015-09-03 21:58:24 +02:00
|
|
|
/**
|
2015-09-22 15:43:25 +02:00
|
|
|
* Comment API: WP_Comment object 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.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
* @access public
|
2015-09-03 20:17:24 +02:00
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
* @access public
|
2015-09-03 20:17:24 +02:00
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
public $comment_post_ID = 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.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
* @access public
|
|
|
|
* @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
|
|
|
|
* @access public
|
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
|
|
|
|
* @access public
|
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
|
|
|
|
* @access public
|
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
|
|
|
|
* @access public
|
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
|
|
|
|
* @access public
|
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
|
|
|
|
* @access public
|
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.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
* @access public
|
2015-09-03 20:17:24 +02:00
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
* @access public
|
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
|
|
|
|
* @access public
|
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
|
|
|
|
* @access public
|
2015-09-03 20:17:24 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $comment_type = '';
|
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.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
* @access public
|
2015-09-03 20:17:24 +02:00
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
* @access public
|
2015-09-03 20:17:24 +02:00
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
public $user_id = 0;
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
* @access public
|
2015-09-03 21:58:24 +02:00
|
|
|
* @static
|
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;
|
|
|
|
|
|
|
|
$comment_id = (int) $id;
|
|
|
|
if ( ! $comment_id ) {
|
|
|
|
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
|
|
|
|
* @access public
|
|
|
|
*
|
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
|
|
|
|
* @access public
|
|
|
|
*
|
|
|
|
* @return array Object as array.
|
|
|
|
*/
|
2015-09-03 20:17:24 +02:00
|
|
|
public function to_array() {
|
|
|
|
return get_object_vars( $this );
|
|
|
|
}
|
|
|
|
}
|