PHPackages                             arraypress/wp-comment-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. arraypress/wp-comment-utils

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

arraypress/wp-comment-utils
===========================

A lean WordPress library for working with comments and comment meta

00PHP

Since Jul 2Pushed 1y agoCompare

[ Source](https://github.com/arraypress/wp-comment-utils)[ Packagist](https://packagist.org/packages/arraypress/wp-comment-utils)[ RSS](/packages/arraypress-wp-comment-utils/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

WordPress Comment Utilities
===========================

[](#wordpress-comment-utilities)

A lightweight WordPress library for working with comments and comment metadata. Provides clean APIs for comment operations, search functionality, and value/label formatting perfect for forms and admin interfaces.

Features
--------

[](#features)

- 🎯 **Clean API**: WordPress-style snake\_case methods with consistent interfaces
- 🔍 **Built-in Search**: Comment search with value/label formatting
- 📋 **Form-Ready Options**: Perfect value/label arrays for selects and forms
- 🌳 **Hierarchical Support**: Parent-child comment relationships
- 🔗 **Status Management**: Easy comment approval, spam, and trash handling
- 📊 **Meta Operations**: Simple comment meta handling with type safety
- 🚀 **Bulk Operations**: Process multiple comments efficiently

Requirements
------------

[](#requirements)

- PHP 7.4 or later
- WordPress 5.0 or later

Installation
------------

[](#installation)

```
composer require arraypress/wp-comment-utils
```

Basic Usage
-----------

[](#basic-usage)

### Working with Single Comments

[](#working-with-single-comments)

```
use ArrayPress\CommentUtils\Comment;

// Get comment by ID
$comment = Comment::get( 123 );

// Check if comment exists
if ( Comment::exists( 123 ) ) {
	// Comment exists
}

// Get comment content
$content     = Comment::get_content( 123 );
$raw_content = Comment::get_content( 123, true );

// Check comment status
$status      = Comment::get_status( 123 ); // 'approved', 'pending', 'spam', 'trash'
$is_approved = Comment::is_approved( 123 );
$is_spam     = Comment::is_spam( 123 );

// Get author details
$author = Comment::get_author_details( 123 );
// Returns: ['name' => 'John', 'email' => 'john@example.com', 'url' => '...', 'ip' => '...']

$user = Comment::get_author_user( 123 ); // WP_User object if registered user

// Check if by registered user
if ( Comment::is_by_registered_user( 123 ) ) {
	// Comment by logged-in user
}

// Get comment hierarchy
$parent       = Comment::get_parent( 123 );
$children     = Comment::get_children( 123 );
$depth        = Comment::get_depth( 123 );
$has_children = Comment::has_children( 123 );

// Get comment dates
$date      = Comment::get_date( 123, 'Y-m-d' );
$age       = Comment::get_age( 123 ); // Days since comment
$time_diff = Comment::get_time_diff( 123 ); // "2 hours ago"

// Comment meta
$meta_value        = Comment::get_meta( 123, 'featured' );
$meta_with_default = Comment::get_meta_with_default( 123, 'rating', 5 );

// Update meta only if changed
Comment::update_meta_if_changed( 123, 'featured', true );

// Status operations
Comment::approve( 123 );
Comment::mark_as_spam( 123 );
Comment::trash( 123 );
```

### Working with Multiple Comments

[](#working-with-multiple-comments)

```
use ArrayPress\CommentUtils\Comments;

// Get multiple comments
$comments = Comments::get( [ 1, 2, 3 ] );

// Get comments by post
$post_comments = Comments::get_by_post( 456 );

// Get comments by author email
$author_comments = Comments::get_by_author_email( 'user@example.com' );

// Get comments by status
$spam_comments    = Comments::get_by_status( 'spam' );
$pending_comments = Comments::get_by_status( [ 'pending', 'hold' ] );

// Get recent comments
$recent = Comments::get_recent( 10 );

// Search comments and get options
$options = Comments::search_options( 'great post' );
// Returns: [['value' => 1, 'label' => 'This is a great post about...'], ...]

// Search comments
$search_results = Comments::search( 'wordpress' );

// Bulk operations
$results = Comments::approve( [ 1, 2, 3 ] );
$results = Comments::mark_as_spam( [ 4, 5, 6 ] );
$results = Comments::trash( [ 7, 8, 9 ] );
$results = Comments::delete( [ 10, 11, 12 ], true ); // Force delete

// Get comment counts
$counts      = Comments::get_counts(); // Site-wide
$post_counts = Comments::get_counts( 123 ); // For specific post
// Returns: ['total' => 50, 'approved' => 45, 'awaiting_moderation' => 3, 'spam' => 2, 'trash' => 0]

// Get hierarchical comments
$threaded = Comments::get_hierarchical( 456 );

// Sanitize comment IDs
$clean_ids = Comments::sanitize( [ '1', 'invalid', '3' ] );
```

### Search Functionality

[](#search-functionality)

```
// Basic search
$comments = Comments::search( 'excellent article' );

// Search with custom args
$comments = Comments::search( 'wordpress', [
	'status'  => 'approve',
	'number'  => 5,
	'post_id' => 123
] );

// Get search results as options for forms
$options = Comments::search_options( 'helpful' );
```

### Status Management

[](#status-management)

```
// Single comment status changes
Comment::approve( 123 );
Comment::mark_as_spam( 123 );
Comment::trash( 123 );

// Bulk status changes
$results = Comments::approve( [ 1, 2, 3 ] );
$results = Comments::mark_as_spam( [ 4, 5, 6 ] );
$results = Comments::trash( [ 7, 8, 9 ] );

// Check results
foreach ( $results as $comment_id => $success ) {
	if ( $success ) {
		echo "Comment {$comment_id} updated successfully";
	}
}
```

Key Features
------------

[](#key-features)

- **Value/Label Format**: Perfect for forms and selects
- **Hierarchical Support**: Parent-child comment relationships
- **Search Functionality**: Built-in comment content search
- **Status Management**: Easy approval, spam, and trash handling
- **Meta Operations**: Simple comment meta handling
- **Bulk Operations**: Process multiple comments efficiently

Requirements
------------

[](#requirements-1)

- PHP 7.4+
- WordPress 5.0+

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This project is licensed under the GPL-2.0-or-later License.

Support
-------

[](#support)

- [Documentation](https://github.com/arraypress/wp-comment-utils)
- [Issue Tracker](https://github.com/arraypress/wp-comment-utils/issues)

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cd6eb8aff0903d87eb674d1ba3c5f3653899c0d7661504eb0deb7798ed86b643?d=identicon)[arraypress](/maintainers/arraypress)

---

Top Contributors

[![arraypress](https://avatars.githubusercontent.com/u/22668877?v=4)](https://github.com/arraypress "arraypress (1 commits)")

### Embed Badge

![Health badge](/badges/arraypress-wp-comment-utils/health.svg)

```
[![Health](https://phpackages.com/badges/arraypress-wp-comment-utils/health.svg)](https://phpackages.com/packages/arraypress-wp-comment-utils)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
