Skip to content

Commit

Permalink
Allow typing of comment objects, just like posts
Browse files Browse the repository at this point in the history
  • Loading branch information
menno-ll committed Sep 27, 2022
1 parent f18dda3 commit 0da62ee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/WordPress_Object/Clarkson_Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
* Object oriented wrapper for WP_Comment objects.
*/
class Clarkson_Comment {

/**
* The type of the comment.
*
* @var string
*/
public static $type = 'comment';

/**
* WordPress representation of this comment object.
*
Expand Down Expand Up @@ -41,6 +49,7 @@ public static function get( int $id ): ?Clarkson_Comment {
*/
public static function get_many( array $args = array() ): array {
$args['fields'] = '';
$args['type'] = static::$type;
$comments = get_comments( $args );
return Objects::get_instance()->get_comments( $comments );
}
Expand Down
3 changes: 3 additions & 0 deletions src/WordPress_Object/Clarkson_Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,9 @@ public function has_term( $term ) {

/**
* Get the comments created by this user.
*
* Explicitly does not get comments via the Clarkson_Comment::get_many() function,
* as this would result in only returning comments of type comment.
*/
public function get_comments( array $args = array() ): array {
$args['user_id'] = $this->get_id();
Expand Down
3 changes: 3 additions & 0 deletions src/WordPress_Object/Clarkson_User.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ public function delete_meta( $key, $value = '' ) {

/**
* Get the comments created by this user.
*
* Explicitly does not get comments via the Clarkson_Comment::get_many() function,
* as this would result in only returning comments of type comment.
*/
public function get_comments( array $args = array() ): array {
$args['user_id'] = $this->get_id();
Expand Down

0 comments on commit 0da62ee

Please sign in to comment.