SkunkCRM Hooks and Filters Reference
SkunkCRM provides a comprehensive set of WordPress action and filter hooks to extend and customize your CRM functionality. This reference provides complete documentation for developers who want to extend SkunkCRM.
Overview
All SkunkCRM hooks use the skunkcrm_ prefix to follow WordPress naming conventions. The hooks are strategically placed throughout the plugin to provide maximum extensibility while maintaining performance and security.
Plugin Lifecycle Hooks
These hooks fire during plugin initialization, activation, and deactivation.
Action Hooks
skunkcrm_before_init
Fires before SkunkCRM initialization begins.
do_action('skunkcrm_before_init');
Parameters: None
Since: 1.8.0
Example:
add_action('skunkcrm_before_init', function() { // Initialize your custom SkunkCRM extensions MyCustomSkunkExtension::init(); });
skunkcrm_after_init
Fires after SkunkCRM initialization is complete.
do_action('skunkcrm_after_init');
Parameters: None
Since: 1.8.0
skunkcrm_before_activation
Fires before plugin activation begins.
do_action('skunkcrm_before_activation');
Parameters: None
Since: 1.8.0
skunkcrm_after_activation
Fires after plugin activation is complete.
do_action('skunkcrm_after_activation');
Parameters: None
Since: 1.8.0
skunkcrm_before_deactivation
Fires before plugin deactivation begins.
do_action('skunkcrm_before_deactivation');
Parameters: None
Since: 1.8.0
skunkcrm_after_deactivation
Fires after plugin deactivation is complete.
do_action('skunkcrm_after_deactivation');
Parameters: None
Since: 1.8.0
Contact Management Hooks
These hooks provide extensibility for contact CRUD operations.
Action Hooks
skunkcrm_before_contact_create
Fires before a contact is created.
do_action('skunkcrm_before_contact_create', $data);
Parameters:
$data(array) The sanitized contact data that will be inserted
Since: 1.8.0
Example:
add_action('skunkcrm_before_contact_create', function($data) { // Log contact creation attempts error_log('Creating contact: ' . $data['name']); // Send notification to admin wp_mail('admin@example.com', 'New Contact', 'Contact ' . $data['name'] . ' is being created'); });
skunkcrm_after_contact_create
Fires after a contact is successfully created.
do_action('skunkcrm_after_contact_create', $contact_id, $data);
Parameters:
$contact_id(int) The ID of the newly created contact$data(array) The contact data that was inserted
Since: 1.8.0
Example:
add_action('skunkcrm_after_contact_create', function($contact_id, $data) { // Automatically assign new contacts to default user update_contact_meta($contact_id, 'assigned_to', 1); // Trigger welcome email automation MyEmailSystem::send_welcome_email($contact_id); });
skunkcrm_before_contact_update
Fires before a contact is updated.
do_action('skunkcrm_before_contact_update', $contact_id, $data, $old_data);
Parameters:
$contact_id(int) The ID of the contact being updated$data(array) The new contact data$old_data(array) The existing contact data before update
Since: 1.8.0
skunkcrm_after_contact_update
Fires after a contact is successfully updated.
do_action('skunkcrm_after_contact_update', $contact_id, $data, $old_data);
Parameters:
$contact_id(int) The ID of the updated contact$data(array) The new contact data$old_data(array) The previous contact data
Since: 1.8.0
skunkcrm_before_contact_delete
Fires before a contact is deleted.
do_action('skunkcrm_before_contact_delete', $contact_id, $contact_data);
Parameters:
$contact_id(int) The ID of the contact being deleted$contact_data(array) The contact data before deletion
Since: 1.8.0
skunkcrm_after_contact_delete
Fires after a contact is successfully deleted.
do_action('skunkcrm_after_contact_delete', $contact_id, $contact_data);
Parameters:
$contact_id(int) The ID of the deleted contact$contact_data(array) The contact data that was deleted
Since: 1.8.0
skunkcrm_before_contact_status_change
Fires before a contact's status is changed.
do_action('skunkcrm_before_contact_status_change', $contact_id, $old_status, $new_status);
Parameters:
$contact_id(int) The ID of the contact$old_status(string) The previous status$new_status(string) The new status
Since: 1.8.0
skunkcrm_after_contact_status_change
Fires after a contact's status is successfully changed.
do_action('skunkcrm_after_contact_status_change', $contact_id, $old_status, $new_status);
Parameters:
$contact_id(int) The ID of the contact$old_status(string) The previous status$new_status(string) The new status
Since: 1.8.0
Filter Hooks
skunkcrm_contact_data_before_save
Filters contact data before saving to database.
$data = apply_filters('skunkcrm_contact_data_before_save', $data, $contact_id);
Parameters:
$data(array) The contact data$contact_id(int|null) The contact ID (null for new contacts)
Return: (array) Modified contact data
Since: 1.8.0
Example:
add_filter('skunkcrm_contact_data_before_save', function($data, $contact_id) { // Auto-capitalize names if (isset($data['name'])) { $data['name'] = ucwords(strtolower($data['name'])); } // Auto-format phone numbers if (isset($data['phone']) && !empty($data['phone'])) { $data['phone'] = format_phone_number($data['phone']); } // Add timestamp for tracking if (is_null($contact_id)) { $data['lead_source'] = 'website_' . date('Y-m-d'); } return $data; }, 10, 2);
skunkcrm_contact_status_options
Filters the available contact status options.
$statuses = apply_filters('skunkcrm_contact_status_options', $statuses);
Parameters:
$statuses(array) Array of status key-value pairs
Return: (array) Modified status options
Since: 1.8.0
Example:
add_filter('skunkcrm_contact_status_options', function($statuses) { // Add custom statuses $statuses['vip'] = 'VIP Customer'; $statuses['partner'] = 'Business Partner'; // Remove unused status unset($statuses['unqualified']); return $statuses; });
skunkcrm_contacts_query_args
Filters query arguments before retrieving contacts.
$args = apply_filters('skunkcrm_contacts_query_args', $args);
Parameters:
$args(array) Query arguments
Return: (array) Modified query arguments
Since: 1.8.0
Example:
add_filter('skunkcrm_contacts_query_args', function($args) { // Only show contacts assigned to current user by default if (!isset($args['assigned_to']) && !current_user_can('manage_options')) { $args['assigned_to'] = get_current_user_id(); } return $args; });
skunkcrm_contacts_search_results
Filters contact search results before returning.
$results = apply_filters('skunkcrm_contacts_search_results', $results, $search_term, $args);
Parameters:
$results(array) Search results$search_term(string) The search term used$args(array) Search arguments
Return: (array) Modified search results
Since: 1.8.0
API Hooks
These hooks provide extensibility for the REST API endpoints.
Action Hooks
skunkcrm_before_api_init
Fires before REST API routes are registered.
do_action('skunkcrm_before_api_init');
Parameters: None
Since: 1.8.0
skunkcrm_before_api_request
Fires before processing any API request.
do_action('skunkcrm_before_api_request', $request, $endpoint);
Parameters:
$request(WP_REST_Request) The REST request object$endpoint(string) The endpoint being accessed
Since: 1.8.0
Example:
add_action('skunkcrm_before_api_request', function($request, $endpoint) { // Log all API requests $user_id = get_current_user_id(); $ip = $request->get_header('X-Forwarded-For') ?: $_SERVER['REMOTE_ADDR']; error_log("SkunkCRM API: User {$user_id} from {$ip} accessing {$endpoint}"); // Rate limiting check if (is_user_over_rate_limit($user_id, $endpoint)) { wp_die('Rate limit exceeded', 429); } }, 10, 2);
skunkcrm_after_api_request
Fires after successful API request processing.
do_action('skunkcrm_after_api_request', $response, $request, $endpoint);
Parameters:
$response(WP_REST_Response) The API response$request(WP_REST_Request) The REST request object$endpoint(string) The endpoint that was accessed
Since: 1.8.0
skunkcrm_api_error
Fires when API request encounters an error.
do_action('skunkcrm_api_error', $error, $request, $endpoint);
Parameters:
$error(WP_Error) The error object$request(WP_REST_Request) The REST request object$endpoint(string) The endpoint that encountered the error
Since: 1.8.0
Filter Hooks
skunkcrm_api_response_data
Filters response data before creating response.
$data = apply_filters('skunkcrm_api_response_data', $data, $request, $endpoint);
Parameters:
$data(mixed) The response data$request(WP_REST_Request) The REST request object$endpoint(string) The endpoint being accessed
Return: (mixed) Modified response data
Since: 1.8.0
Example:
add_filter('skunkcrm_api_response_data', function($data, $request, $endpoint) { if ($endpoint === 'get_contacts') { // Add custom fields to contact data foreach ($data as &$contact) { $contact['custom_score'] = calculate_lead_score($contact['id']); $contact['last_interaction'] = get_last_interaction_date($contact['id']); } } return $data; }, 10, 3);
skunkcrm_api_permission_check
Filters basic API permission result.
$has_permission = apply_filters('skunkcrm_api_permission_check', $has_permission, $request);
Parameters:
$has_permission(bool) Current permission result$request(WP_REST_Request) The REST request object
Return: (bool) Modified permission result
Since: 1.8.0
Database Hooks
These hooks provide extensibility for database operations.
Action Hooks
skunkcrm_before_table_creation
Fires before any database table creation begins.
do_action('skunkcrm_before_table_creation');
Parameters: None
Since: 1.8.0
skunkcrm_after_table_creation
Fires after all database tables are created.
do_action('skunkcrm_after_table_creation');
Parameters: None
Since: 1.8.0
skunkcrm_before_table_creation_individual
Fires before each individual table creation.
do_action('skunkcrm_before_table_creation_individual', $table_name, $sql);
Parameters:
$table_name(string) Name of the table being created$sql(string) SQL statement for table creation
Since: 1.8.0
skunkcrm_after_table_creation_individual
Fires after each individual table creation.
do_action('skunkcrm_after_table_creation_individual', $table_name, $result);
Parameters:
$table_name(string) Name of the table that was created$result(bool|null) Result of the table creation
Since: 1.8.0
Filter Hooks
skunkcrm_table_creation_sql
General filter for any table creation SQL.
$sql = apply_filters('skunkcrm_table_creation_sql', $sql, $table_name);
Parameters:
$sql(string) The SQL statement$table_name(string) Name of the table
Return: (string) Modified SQL statement
Since: 1.8.0
Example:
add_filter('skunkcrm_table_creation_sql', function($sql, $table_name) { if ($table_name === 'skunk_contacts') { // Add custom column to contacts table $sql = str_replace( 'created_at datetime DEFAULT CURRENT_TIMESTAMP,', 'created_at datetime DEFAULT CURRENT_TIMESTAMP, custom_score int(11) DEFAULT 0,', $sql ); } return $sql; }, 10, 2);
skunkcrm_database_charset_collate
Filters charset and collation settings.
$charset_collate = apply_filters('skunkcrm_database_charset_collate', $charset_collate);
Parameters:
$charset_collate(string) Charset and collation string
Return: (string) Modified charset and collation
Since: 1.8.0
Automation Hooks
These hooks provide extensibility for the automation system.
Action Hooks
skunkcrm_before_automation_execute
Fires before an automation is executed.
do_action('skunkcrm_before_automation_execute', $automation_id, $contact_id, $trigger_data);
Parameters:
$automation_id(int) The automation ID$contact_id(int) The contact ID triggering the automation$trigger_data(array) Data about what triggered the automation
Since: 1.8.0
skunkcrm_after_automation_execute
Fires after an automation is executed.
do_action('skunkcrm_after_automation_execute', $automation_id, $contact_id, $result, $trigger_data);
Parameters:
$automation_id(int) The automation ID$contact_id(int) The contact ID that triggered the automation$result(array) The execution result$trigger_data(array) Data about what triggered the automation
Since: 1.8.0
skunkcrm_before_automation_email
Fires before sending an automation email.
do_action('skunkcrm_before_automation_email', $contact_id, $email_config, $automation_id);
Parameters:
$contact_id(int) The contact ID$email_config(array) Email configuration$automation_id(int) The automation ID
Since: 1.8.0
skunkcrm_after_automation_email
Fires after sending an automation email.
do_action('skunkcrm_after_automation_email', $contact_id, $email_result, $email_config, $automation_id);
Parameters:
$contact_id(int) The contact ID$email_result(bool) Whether the email was sent successfully$email_config(array) Email configuration$automation_id(int) The automation ID
Since: 1.8.0
Filter Hooks
skunkcrm_automation_email_content
Filters email content before processing.
$content = apply_filters('skunkcrm_automation_email_content', $content, $contact, $template, $automation_id);
Parameters:
$content(string) Email content$contact(array) Contact data$template(string) Email template$automation_id(int) The automation ID
Return: (string) Modified email content
Since: 1.8.0
Example:
add_filter('skunkcrm_automation_email_content', function($content, $contact, $template, $automation_id) { // Add personalization $content = str_replace('{first_name}', get_first_name($contact['name']), $content); $content = str_replace('{company}', $contact['company'], $content); // Add dynamic content based on contact status if ($contact['status'] === 'customer') { $content .= "\n\nAs a valued customer, here's your special offer: [CUSTOMER_OFFER]"; } return $content; }, 10, 4);
skunkcrm_should_execute_automation
Controls whether an automation should execute.
$should_execute = apply_filters('skunkcrm_should_execute_automation', true, $automation_id, $contact_id, $trigger_data);
Parameters:
$should_execute(bool) Whether to execute the automation$automation_id(int) The automation ID$contact_id(int) The contact ID$trigger_data(array) Trigger data
Return: (bool) Whether the automation should execute
Since: 1.8.0
Examples
Complete Contact Lifecycle Tracking
// Track complete contact lifecycle class ContactLifecycleTracker { public function __construct() { add_action('skunkcrm_after_contact_create', [$this, 'track_contact_created']); add_action('skunkcrm_after_contact_update', [$this, 'track_contact_updated'], 10, 3); add_action('skunkcrm_after_contact_status_change', [$this, 'track_status_change'], 10, 3); add_action('skunkcrm_before_contact_delete', [$this, 'track_contact_deleted'], 10, 2); } public function track_contact_created($contact_id, $data) { $this->log_event('contact_created', $contact_id, [ 'name' => $data['name'], 'email' => $data['email'], 'initial_status' => $data['status'] ]); } public function track_contact_updated($contact_id, $new_data, $old_data) { $changes = array_diff_assoc($new_data, $old_data); if (!empty($changes)) { $this->log_event('contact_updated', $contact_id, [ 'changes' => $changes, 'previous_data' => $old_data ]); } } public function track_status_change($contact_id, $old_status, $new_status) { $this->log_event('status_changed', $contact_id, [ 'from' => $old_status, 'to' => $new_status, 'timestamp' => current_time('mysql') ]); // Trigger different actions based on status if ($new_status === 'customer') { $this->trigger_customer_onboarding($contact_id); } } public function track_contact_deleted($contact_id, $contact_data) { $this->log_event('contact_deleted', $contact_id, [ 'final_data' => $contact_data, 'deleted_by' => get_current_user_id() ]); } private function log_event($event, $contact_id, $data) { // Log to custom table or external service error_log("SkunkCRM Event: {$event} for contact {$contact_id}: " . json_encode($data)); } private function trigger_customer_onboarding($contact_id) { // Custom onboarding logic do_action('company_customer_onboarding', $contact_id); } } new ContactLifecycleTracker();
Custom API Response Enhancement
// Add custom data to all API responses add_filter('skunkcrm_api_response_data', function($data, $request, $endpoint) { // Add metadata to all responses if (is_array($data) && $endpoint === 'get_contacts') { foreach ($data as &$contact) { // Add calculated fields $contact['days_since_created'] = calculate_days_since_created($contact['created_at']); $contact['interaction_count'] = get_contact_interaction_count($contact['id']); $contact['last_activity'] = get_last_activity_date($contact['id']); $contact['lead_score'] = calculate_lead_score($contact); // Add permissions for current user $contact['permissions'] = [ 'can_edit' => current_user_can('edit_contact', $contact['id']), 'can_delete' => current_user_can('delete_contact', $contact['id']) ]; } } return $data; }, 10, 3); function calculate_lead_score($contact) { $score = 0; // Email provided if (!empty($contact['email'])) $score += 20; // Phone provided if (!empty($contact['phone'])) $score += 15; // Company provided if (!empty($contact['company'])) $score += 10; // Status-based scoring $status_scores = [ 'lead' => 50, 'warm-lead' => 30, 'cold-lead' => 10, 'customer' => 100 ]; $score += $status_scores[$contact['status']] ?? 0; return $score; }
Advanced Automation Extension
// Extend automation system with custom actions and conditions class AdvancedAutomationExtensions { public function __construct() { add_filter('skunkcrm_automation_action_types', [$this, 'add_custom_actions']); add_filter('skunkcrm_automation_condition_types', [$this, 'add_custom_conditions']); add_filter('skunkcrm_custom_action_type', [$this, 'handle_custom_action'], 10, 4); add_filter('skunkcrm_custom_condition_type', [$this, 'handle_custom_condition'], 10, 3); add_filter('skunkcrm_automation_email_content', [$this, 'enhance_email_content'], 10, 4); } public function add_custom_actions($actions) { $actions['create_task'] = 'Create Task'; $actions['send_slack'] = 'Send Slack Message'; $actions['webhook_post'] = 'Send Webhook'; return $actions; } public function add_custom_conditions($conditions) { $conditions['lead_score_above'] = 'Lead Score Above'; $conditions['days_since_contact'] = 'Days Since Last Contact'; return $conditions; } public function handle_custom_action($result, $action_type, $config, $contact) { switch ($action_type) { case 'create_task': return $this->create_task_action($config, $contact); case 'send_slack': return $this->send_slack_action($config, $contact); case 'webhook_post': return $this->webhook_post_action($config, $contact); } return $result; } public function handle_custom_condition($result, $condition_type, $config, $contact) { switch ($condition_type) { case 'lead_score_above': return calculate_lead_score($contact) > intval($config['value']); case 'days_since_contact': $last_contact = get_last_contact_date($contact['id']); $days_diff = (time() - strtotime($last_contact)) / DAY_IN_SECONDS; return $days_diff > intval($config['days']); } return $result; } private function create_task_action($config, $contact) { // Create task in your task management system $task_data = [ 'title' => str_replace('{contact_name}', $contact['name'], $config['title']), 'description' => str_replace('{contact_name}', $contact['name'], $config['description']), 'contact_id' => $contact['id'], 'due_date' => date('Y-m-d', strtotime($config['due_in_days'] . ' days')), 'assigned_to' => $config['assigned_to'] ?? get_current_user_id() ]; return wp_insert_post([ 'post_type' => 'task', 'post_title' => $task_data['title'], 'post_content' => $task_data['description'], 'post_status' => 'publish', 'meta_input' => $task_data ]); } private function send_slack_action($config, $contact) { $webhook_url = $config['webhook_url']; $message = str_replace('{contact_name}', $contact['name'], $config['message']); $payload = [ 'text' => $message, 'channel' => $config['channel'] ?? '#general', 'username' => 'SkunkCRM' ]; return wp_remote_post($webhook_url, [ 'body' => json_encode($payload), 'headers' => ['Content-Type' => 'application/json'] ]); } public function enhance_email_content($content, $contact, $template, $automation_id) { // Add dynamic content based on contact data $replacements = [ '{contact_score}' => calculate_lead_score($contact), '{days_as_contact}' => calculate_days_since_created($contact['created_at']), '{last_interaction}' => get_last_interaction_summary($contact['id']), '{recommended_action}' => get_recommended_next_action($contact) ]; return str_replace(array_keys($replacements), array_values($replacements), $content); } } new AdvancedAutomationExtensions();
Hook Reference Quick Links
- Plugin Lifecycle: skunkcrm_before_init | skunkcrm_after_init | skunkcrm_after_activation
- Contacts: skunkcrm_before_contact_create | skunkcrm_contact_data_before_save | skunkcrm_contact_status_options
- API: skunkcrm_before_api_request | skunkcrm_api_response_data | skunkcrm_api_permission_check
- Database: skunkcrm_before_table_creation | skunkcrm_table_creation_sql
- Automation: skunkcrm_before_automation_execute | skunkcrm_automation_email_content
This documentation covers the most commonly used hooks. For a complete list of all available hooks, see the source code documentation in each class file.