WP_Comment::get_instance() – Retrieves a WP_Comment instance.

You appear to be a bot. Output may be restricted

Description

Retrieves a WP_Comment instance.

Usage

$WP_Comment|false = WP_Comment::get_instance( $id );

Parameters

$id
( int ) required – Comment ID.

Returns

WP_Comment|false Comment object, otherwise false.

Source

File name: wordpress/wp-includes/class-wp-comment.php
Lines:

1 to 22 of 22
  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 );
  }
 

 View on GitHub View on Trac