WP_Comment::get_instance
Retrieves a WP_Comment instance.
Метод класса: WP_Comment{}
Хуков нет.
Возвращает
WP_Comment|false. Comment object, otherwise false.
Использование
$result = WP_Comment::get_instance( $id );
- $id(int) (обязательный)
- Comment ID.
Заметки
Global. wpdb. $wpdb WordPress database abstraction object. |
Список изменений
| С версии 4.4.0 | Введена. |
Код WP_Comment::get_instance() WP Comment::get instance WP 7.1
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 ( ! is_object( $_comment ) ) {
/** @var object{ comment_ID: string, comment_post_ID: string, comment_author: string, comment_author_email: string, comment_author_url: string, comment_author_IP: string, comment_date: string, comment_date_gmt: string, comment_content: string, comment_karma: string, comment_approved: string, comment_agent: string, comment_type: string, comment_parent: string, user_id: string }|null $_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 );
}