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. * * Populates properties with object vars. * * @since 4.4.0 * @access public * * @param WP_Comment $comment Comment object. */ public function __construct( $comment ) { foreach ( get_object_vars( $comment ) as $key => $value ) { $this->$key = $value; } } /** * Convert object to array. * * @since 4.4.0 * @access public * * @return array Object as array. */ public function to_array() { return get_object_vars( $this ); } /** * Get the children of a comment. * * @since 4.4.0 * @access public * * @param string $format Return value format. 'tree' for a hierarchical tree, 'flat' for a flattened array. * Default 'tree'. * @return array Array of `WP_Comment` objects. */ public function get_children( $format = 'tree' ) { if ( is_null( $this->children ) ) { $this->children = get_comments( array( 'parent' => $this->comment_ID, 'hierarchical' => 'threaded', ) ); } if ( 'flat' === $format ) { $children = array(); foreach ( $this->children as $child ) { $children = array_merge( $children, array( $child ), $child->get_children( 'flat' ) ); } } else { $children = $this->children; } return $children; } /** * Add a child to the comment. * * Used by `WP_Comment_Query` when bulk-filling descendants. * * @since 4.4.0 * @access public * * @param WP_Comment $child Child comment. */ public function add_child( WP_Comment $child ) { $this->comments[ $child->comment_ID ] = $child; } /** * Get a child comment by ID. * * @since 4.4.0 * @access public * * @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 ) { if ( isset( $this->comments[ $child_id ] ) ) { return $this->comments[ $child_id ]; } return false; } }