Fires to check rate limits before creating a comment.
Parameters:
Parameter
Type
Description
$userId
int
User ID attempting to comment
$feedId
int
Feed ID being commented on
Example Usage:
php
add_action('fluent_community/check_rate_limit/create_comment', function($userId, $feedId) { // Check how many comments user made in last hour global $wpdb; $recent_comments = $wpdb->get_var($wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}fcom_comments WHERE user_id = %d AND created_at > DATE_SUB(NOW(), INTERVAL 1 HOUR)", $userId )); if ($recent_comments > 20) { wp_send_json_error([ 'message' => 'You are commenting too frequently. Please wait.' ], 429); }}, 10, 2);// Prevent spam on specific postsadd_action('fluent_community/check_rate_limit/create_comment', function($userId, $feedId) { // Check if user already commented on this post recently global $wpdb; $recent_comment = $wpdb->get_var($wpdb->prepare( "SELECT id FROM {$wpdb->prefix}fcom_comments WHERE user_id = %d AND post_id = %d AND created_at > DATE_SUB(NOW(), INTERVAL 5 MINUTE)", $userId, $feedId )); if ($recent_comment) { wp_send_json_error([ 'message' => 'Please wait before commenting again on this post.' ], 429); }}, 10, 2);
add_action('fluent_community/comment_added', function($comment, $feed) { if ($comment->parent_id) { // This is a reply to another comment $parent_comment = get_comment($comment->parent_id); // Notify parent comment author notify_comment_reply($parent_comment, $comment); }}, 10, 2);
Documentation in progress - some sections may be incomplete or subject to change.
Comments Actions
Comment Lifecycle
fluent_community/before_comment_create
Fires before a comment is created, allowing you to perform validation or preparation.
Parameters:
$data$feedData Array Structure:
Example Usage:
Common Use Cases:
fluent_community/comment_added
Fires immediately after a comment is successfully created and saved.
Parameters:
$comment$feedComment Object Properties:
id(int) - Comment IDuser_id(int) - Commenter user IDpost_id(int) - Parent feed IDparent_id(int|null) - Parent comment ID for repliesmessage(string) - Comment contentmessage_rendered(string) - Rendered HTML contenttype(string) - Comment typestatus(string) - 'published', 'pending', 'spam'meta(array) - Additional metadatacreated_at(string) - Creation timestampupdated_at(string) - Last update timestampExample Usage:
Common Use Cases:
fluent_community/comment_updated
Fires after a comment is updated.
Parameters:
$comment$feed$oldCommentExample Usage:
Common Use Cases:
fluent_community/before_comment_delete
Fires before a comment is deleted from the database.
Parameters:
$comment$feedExample Usage:
Common Use Cases:
fluent_community/comment_deleted
Fires after a comment has been deleted.
Parameters:
$comment$feedExample Usage:
Common Use Cases:
Dynamic Actions
fluent_community/comment_added_
Dynamic Action - Fires when a comment is added, with the feed type appended to the hook name.
Hook Pattern:
fluent_community/comment_added_{type}Dynamic Values:
fluent_community/comment_added_post- Comment on regular feed postfluent_community/comment_added_article- Comment on articlefluent_community/comment_added_video- Comment on videofluent_community/comment_added_course- Comment on coursefluent_community/comment_added_event- Comment on eventfluent_community/comment_added_poll- Comment on pollParameters:
$comment$feedSource Files:
app/Http/Controllers/CommentsController.php:152Example Usage:
Common Use Cases:
fluent_community/comment_updated_
Dynamic Action - Fires when a comment is updated, with the feed type appended to the hook name.
Hook Pattern:
fluent_community/comment_updated_{type}Dynamic Values:
fluent_community/comment_updated_post- Comment on regular post updatedfluent_community/comment_updated_article- Comment on article updatedfluent_community/comment_updated_video- Comment on video updatedfluent_community/comment_updated_course- Comment on course updatedParameters:
$comment$feedSource Files:
app/Http/Controllers/CommentsController.phpExample Usage:
Common Use Cases:
fluent_community/comment_deleted_
Dynamic Action - Fires when a comment is deleted, with the feed type appended to the hook name.
Hook Pattern:
fluent_community/comment_deleted_{type}Dynamic Values:
fluent_community/comment_deleted_post- Comment on regular post deletedfluent_community/comment_deleted_article- Comment on article deletedfluent_community/comment_deleted_video- Comment on video deletedfluent_community/comment_deleted_course- Comment on course deletedParameters:
$commentId$feedSource Files:
app/Http/Controllers/CommentsController.phpExample Usage:
Common Use Cases:
fluent_community/comment/new_comment_
Dynamic Action - Fires when a comment is created, with the comment status appended to the hook name.
Hook Pattern:
fluent_community/comment/new_comment_{status}Dynamic Values:
fluent_community/comment/new_comment_published- Published commentfluent_community/comment/new_comment_pending- Pending moderationfluent_community/comment/new_comment_spam- Marked as spamfluent_community/comment/new_comment_draft- Draft commentParameters:
$comment$feedSource Files:
app/Http/Controllers/CommentsController.php:145Example Usage:
Common Use Cases:
Media Actions
fluent_community/comment/media_deleted
Fires when media is deleted from a comment.
Parameters:
$media$commentExample Usage:
Rate Limiting
fluent_community/check_rate_limit/create_comment
Fires to check rate limits before creating a comment.
Parameters:
$userId$feedIdExample Usage:
Common Use Cases:
Best Practices
1. Always Check Data Exists
2. Handle Nested Comments
3. Avoid Infinite Loops
4. Use Appropriate Hooks
See Also