Skip to content

Hooks Overview

Fluent Community provides a comprehensive system of actions and filters that allow developers to extend and customize the plugin's functionality without modifying core files.

What are Hooks?

WordPress hooks are a way for one piece of code to interact with another. They make up the foundation for how plugins and themes interact with WordPress Core.

Actions

Actions allow you to execute custom code at specific points during execution. They don't return anything back to the calling hook.

php
// Example: Send notification when a feed is created
add_action('fluent_community/feed/created', function($feed) {
    // Your custom code here
    error_log('New feed created: ' . $feed->id);
}, 10, 1);

Filters

Filters allow you to modify data before it's used or displayed. They must return a value.

php
// Example: Modify feed data before creation
add_filter('fluent_community/feed/new_feed_data', function($data, $requestData) {
    // Add custom metadata
    $data['meta']['custom_field'] = 'custom_value';
    return $data;
}, 10, 2);

Hook Statistics

Quick Navigation

Hook Categories

Core Features

ModuleActionsFiltersTotalDocumentation
Feeds & Posts181533ActionsFilters
Comments11516ActionsFilters
Spaces141024ActionsFilters
Users & Members121527ActionsFilters

Engagement Features

ModuleActionsFiltersTotalDocumentation
Media41216ActionsFilters
Reactions235ActionsFilters
Notifications8513ActionsFilters

Authentication & Access

ModuleActionsFiltersTotalDocumentation
Authentication81826ActionsFilters

Learning Management

ModuleActionsFiltersTotalDocumentation
Courses181230ActionsFilters

Pro Features

ModuleActionsFiltersTotalDocumentation
Moderation 🔒6410ActionsFilters
Followers 🔒437ActionsFilters

UI & Customization

ModuleActionsFiltersTotalDocumentation
Portal & UI202545ActionsFilters
Activities358ActionsFilters

Administration

ModuleActionsFiltersTotalDocumentation
Managers549ActionsFilters

Quick Start

1. Choose Your Hook

Browse the Quick Reference to find the hook you need, or explore by category:

2. Add Your Code

Add your custom code to your theme's functions.php or a custom plugin:

php
// In your theme's functions.php or custom plugin

// Action example
add_action('fluent_community/feed/created', 'my_custom_feed_handler', 10, 1);

function my_custom_feed_handler($feed) {
    // Your code here
}

// Filter example
add_filter('fluent_community/feed/new_feed_data', 'my_custom_feed_modifier', 10, 2);

function my_custom_feed_modifier($data, $requestData) {
    // Modify data
    return $data;
}

3. Test Your Implementation

Always test your hooks in a development environment first!

Common Use Cases

Integration with Third-Party Services

php
// Send feed data to external API
add_action('fluent_community/feed/created', function($feed) {
    wp_remote_post('https://api.example.com/webhook', [
        'body' => json_encode([
            'feed_id' => $feed->id,
            'title' => $feed->title,
            'author' => $feed->user_id
        ])
    ]);
}, 10, 1);

Custom Validation

php
// Prevent posts with certain words
add_filter('fluent_community/feed/new_feed_data', function($data, $requestData) {
    $bannedWords = ['spam', 'scam'];
    
    foreach ($bannedWords as $word) {
        if (stripos($data['message'], $word) !== false) {
            return new WP_Error('invalid_content', 'Content contains banned words');
        }
    }
    
    return $data;
}, 10, 2);

Award Points System

php
// Award points when user creates a post
add_action('fluent_community/feed/created', function($feed) {
    $points = get_user_meta($feed->user_id, 'community_points', true) ?: 0;
    update_user_meta($feed->user_id, 'community_points', $points + 10);
}, 10, 1);

Custom Notifications

php
// Send custom email when user joins a space
add_action('fluent_community/space/joined', function($space, $userId, $source) {
    $user = get_user_by('id', $userId);
    
    wp_mail(
        $user->user_email,
        'Welcome to ' . $space->title,
        'You have successfully joined ' . $space->title
    );
}, 10, 3);

Best Practices

1. Use Appropriate Priority

The third parameter in add_action() and add_filter() is the priority (default: 10). Lower numbers run earlier.

php
// Run before other hooks
add_action('fluent_community/feed/created', 'my_function', 5, 1);

// Run after other hooks
add_action('fluent_community/feed/created', 'my_function', 20, 1);

2. Specify Number of Parameters

Always specify the correct number of parameters (4th argument):

php
// Hook has 3 parameters
add_action('fluent_community/space/joined', 'my_function', 10, 3);

function my_function($space, $userId, $source) {
    // All 3 parameters available
}

3. Return Values for Filters

Always return a value from filter callbacks:

php
// ✅ Correct
add_filter('fluent_community/feed/new_feed_data', function($data) {
    $data['custom'] = 'value';
    return $data; // Always return!
}, 10, 1);

// ❌ Wrong - Missing return
add_filter('fluent_community/feed/new_feed_data', function($data) {
    $data['custom'] = 'value';
    // Missing return statement!
}, 10, 1);

4. Error Handling

Use WP_Error for validation in filters:

php
add_filter('fluent_community/feed/new_feed_data', function($data) {
    if (empty($data['title'])) {
        return new WP_Error('missing_title', 'Title is required');
    }
    return $data;
}, 10, 1);

5. Check Conditions

Always verify data exists before using it:

php
add_action('fluent_community/feed/created', function($feed) {
    if (!$feed || !isset($feed->id)) {
        return;
    }
    
    // Safe to use $feed->id
}, 10, 1);

Resources

Need Help?

Version Information

  • Free Version: Includes all core hooks
  • Pro Version: Includes additional hooks for premium features (marked with 🔒)

Dynamic Hooks

Some hooks include {placeholder} in their names. These are dynamic hooks that change based on context. For example:

  • fluent_community/feed/new_feed_data_type_{type} becomes fluent_community/feed/new_feed_data_type_article for article posts
  • fluent_community/comment_added_{feed_type} becomes fluent_community/comment_added_feed for feed comments

Important

Always test hooks in a development environment before deploying to production. Some hooks can significantly impact your community's functionality.

Fluent Community developer documentation