On this page
WP_Comment::get_instance( int $id ): WP_Comment|false
Retrieves a WP_Comment instance.
Parameters
$idint Required-
Comment ID.
Return
WP_Comment|false Comment object, otherwise false.
Source
File: wp-includes/class-wp-comment.php. View all references
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 );
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Comment::__construct() wp-includes/class-wp-comment.php | Constructor. |
| wp_cache_add() wp-includes/cache.php | Adds data to the cache, if the cache key doesn’t already exist. |
| wpdb::get_row() wp-includes/class-wpdb.php | Retrieves one row from the database. |
| wp_cache_get() wp-includes/cache.php | Retrieves the cache contents from the cache by key and group. |
| wpdb::prepare() wp-includes/class-wpdb.php | Prepares a SQL query for safe execution. |
Used By
| Used By | Description |
|---|---|
| get_comment() wp-includes/comment.php | Retrieves comment data given a comment ID or comment object. |
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_comment/get_instance