WP_REST_Comments_Controller::get_comment()
Get the comment, if the ID is valid.
Метод класса: WP_REST_Comments_Controller{}
Хуков нет.
Возвращает
WP_Comment|WP_Error
. Comment object if ID is valid, WP_Error otherwise.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_comment( $id );
- $id(int) (обязательный)
- Supplied ID.
Список изменений
С версии 4.7.2 | Введена. |
Код WP_REST_Comments_Controller::get_comment() WP REST Comments Controller::get comment WP 6.5.2
protected function get_comment( $id ) { $error = new WP_Error( 'rest_comment_invalid_id', __( 'Invalid comment ID.' ), array( 'status' => 404 ) ); if ( (int) $id <= 0 ) { return $error; } $id = (int) $id; $comment = get_comment( $id ); if ( empty( $comment ) ) { return $error; } if ( ! empty( $comment->comment_post_ID ) ) { $post = get_post( (int) $comment->comment_post_ID ); if ( empty( $post ) ) { return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post ID.' ), array( 'status' => 404 ) ); } } return $comment; }