Skip to main content

Actions reference

Who this is for​

This page is for developers who need to extend the plugin using WordPress action hooks. Most users can accomplish everything through WP Enhanced > Free Download Woo without code.

Core actions​

somdn_loaded​

Fires after the plugin is fully loaded.

Priority: -1 (very early)
Parameters: None

Usage:

add_action('somdn_loaded', 'my_custom_init');
function my_custom_init() {
// Plugin is fully loaded
// Initialize custom functionality
}

Use Cases:

  • Initialize custom modules
  • Register custom post types
  • Add custom capabilities

somdn_after_file_loader​

Fires after all core plugin files are included.

Parameters: None

Usage:

add_action('somdn_after_file_loader', 'my_custom_files');
function my_custom_files() {
// Load custom files
require_once 'my-custom-functions.php';
}

Use Cases:

  • Load custom function files
  • Include third-party libraries
  • Register custom classes

somdn_load_modules​

Extension point for loading custom modules.

Parameters: None

Usage:

add_action('somdn_load_modules', 'my_custom_module');
function my_custom_module() {
// Load custom module
MyCustomModule::init();
}

Use Cases:

  • Load custom modules
  • Initialize extensions
  • Register add-ons

Download Actions​

somdn_count_download​

Fires when a download is counted.

Parameters:

  • $product_id (int) - Product ID
  • $user_id (int) - User ID (0 for guests)
  • $variation_id (int) - Variation ID (0 if not applicable)

Usage:

add_action('somdn_count_download', 'my_download_counter', 10, 3);
function my_download_counter($product_id, $user_id, $variation_id) {
// Custom download counting logic
error_log("Download: Product {$product_id} by User {$user_id}");
}

Use Cases:

  • Custom analytics
  • External tracking systems
  • Download notifications
  • Integration with other plugins

somdn_count_download_post_success​

Fires after download log is successfully created (Pro only).

Parameters:

  • $post_id (int) - Download log post ID

Usage:

add_action('somdn_count_download_post_success', 'my_post_download_action');
function my_post_download_action($post_id) {
// Access download log data
$product_id = get_post_meta($post_id, 'somdn_product_id', true);
$user_email = get_post_meta($post_id, 'somdn_user_email', true);

// Custom processing
my_send_notification($user_email, $product_id);
}

Use Cases:

  • Send custom notifications
  • Trigger external webhooks
  • Update CRM systems
  • Award points/credits

Example: Save Custom Field Data

add_action('somdn_count_download_post_success', 'save_custom_field');
function save_custom_field($post_id) {
$custom_value = sanitize_text_field($_POST['custom_field'] ?? '');
if ($custom_value) {
add_post_meta($post_id, 'custom_field', $custom_value);
}
}

Email Capture Actions​

somdn_capture_after_sub_inputs​

Fires after subscription inputs in email capture form (Pro only).

Parameters:

  • $user_id (int) - Current user ID (0 for guests)
  • $email (string) - User's email address

Usage:

add_action('somdn_capture_after_sub_inputs', 'add_custom_form_fields', 10, 2);
function add_custom_form_fields($user_id, $email) {
?>
<div class="somdn-capture-name-input-wrap">
<input
type="text"
name="custom_field"
class="somdn-download-user-name somdn-capture-required"
placeholder="Custom Field..."
>
</div>
<?php
}

Use Cases:

  • Add custom form fields
  • Collect additional data
  • Display custom messages
  • Add consent checkboxes

Example: Add Postcode Field

add_action('somdn_capture_after_sub_inputs', 'add_postcode_field', 10, 2);
function add_postcode_field($user_id, $email) {
?>
<div class="somdn-capture-name-input-wrap">
<input
type="text"
name="user_postcode"
class="somdn-download-user-name somdn-capture-required"
placeholder="Postcode..."
>
</div>
<?php
}

somdn_before_form_inputs_simple​

Fires before form inputs on simple product pages.

Parameters:

  • $product_id (int) - Product ID

Usage:

add_action('somdn_before_form_inputs_simple', 'add_before_simple_form');
function add_before_simple_form($product_id) {
echo '<p>Please complete the form below:</p>';
}

Use Cases:

  • Add instructions
  • Display notices
  • Insert custom content

Example: Auto-Subscribe Registered Users

add_action('somdn_before_form_inputs_simple', 'auto_subscribe_users');
add_action('somdn_before_form_inputs_variation', 'auto_subscribe_users');
function auto_subscribe_users($product_id) {
// Hidden checkbox that's always checked
echo '<input type="checkbox" name="somdn_capture_email_subscribe"
id="somdn_capture_email_subscribe" style="display: none!important;"
value="1" checked>';
}

somdn_before_form_inputs_variation​

Fires before form inputs on variable product pages.

Parameters:

  • $product_id (int) - Product ID

Usage:

add_action('somdn_before_form_inputs_variation', 'add_before_variation_form');
function add_before_variation_form($product_id) {
echo '<p>Select your preferred format:</p>';
}

Display Actions​

somdn_archive_product_page​

Fires to display download UI on archive/shop pages.

Parameters:

  • $args (array) - Display arguments

Usage:

add_action('somdn_archive_product_page', 'custom_archive_display');
function custom_archive_display($args) {
// Custom archive display logic
echo '<div class="custom-download-wrapper">';
somdn_product_page($args);
echo '</div>';
}

Use Cases:

  • Custom archive layouts
  • Wrapper elements
  • Additional content

somdn_before_download_button​

Fires before download button is displayed.

Parameters:

  • $product_id (int) - Product ID
  • $args (array) - Display arguments

Usage:

add_action('somdn_before_download_button', 'add_before_button', 10, 2);
function add_before_button($product_id, $args) {
echo '<div class="download-notice">Free Download Available</div>';
}

Use Cases:

  • Add notices
  • Display badges
  • Insert custom content

somdn_after_download_button​

Fires after download button is displayed.

Parameters:

  • $product_id (int) - Product ID
  • $args (array) - Display arguments

Usage:

add_action('somdn_after_download_button', 'add_after_button', 10, 2);
function add_after_button($product_id, $args) {
echo '<p class="download-info">No account required</p>';
}

Use Cases:

  • Add disclaimers
  • Display file information
  • Insert help text

Statistics Actions​

somdn_stats_export_init​

Fires before statistics export begins (Pro only).

Parameters: None

Usage:

add_action('somdn_stats_export_init', 'before_export');
function before_export() {
// Pre-export processing
error_log('Export started at ' . current_time('mysql'));
}

Use Cases:

  • Log export activity
  • Prepare data
  • Send notifications

somdn_stats_export_complete​

Fires after statistics export completes (Pro only).

Parameters:

  • $file_path (string) - Path to exported file
  • $record_count (int) - Number of records exported

Usage:

add_action('somdn_stats_export_complete', 'after_export', 10, 2);
function after_export($file_path, $record_count) {
// Post-export processing
error_log("Exported {$record_count} records to {$file_path}");
}

Use Cases:

  • Email export file
  • Upload to cloud storage
  • Log export completion
  • Trigger backups

somdn_stats_settings_before_buttons​

Fires before export buttons in statistics settings (Pro only).

Parameters: None

Usage:

add_action('somdn_stats_settings_before_buttons', 'add_custom_export_options');
function add_custom_export_options() {
?>
<div class="som-setting-gen-settings-wrap">
<h4>Custom Export Options</h4>
<select name="custom_export_type">
<option value="all">All Data</option>
<option value="guests">Guest Downloads Only</option>
<option value="subscribers">Subscribers Only</option>
</select>
</div>
<?php
}

Use Cases:

  • Add custom export options
  • Display additional settings
  • Insert custom controls

Download Limit Actions​

somdn_download_limit_reached​

Fires when user reaches download limit (Pro only).

Parameters:

  • $user_id (int) - User ID
  • $limits (array) - Limit configuration

Usage:

add_action('somdn_download_limit_reached', 'notify_limit_reached', 10, 2);
function notify_limit_reached($user_id, $limits) {
$user = get_user_by('id', $user_id);

// Send email notification
wp_mail(
$user->user_email,
'Download Limit Reached',
'You have reached your download limit. Upgrade for more downloads!'
);
}

Use Cases:

  • Send notifications
  • Log limit violations
  • Trigger upgrade prompts
  • Update user meta

Example: Redirect on Limit Reached

add_action('template_redirect', 'redirect_on_limit_reached', 99);
function redirect_on_limit_reached() {
$errors = $_REQUEST['somdn_errors'] ?? '';
if (empty($errors)) {
return;
}

$limit_reached = $errors[0]['download_limit_reached'] ?? '';
if ($limit_reached) {
wp_redirect(home_url('/upgrade/'));
exit;
}
}

MailChimp Actions​

somdn_mailchimp_subscribed​

Fires after successful MailChimp subscription (Pro only).

Parameters:

  • $email (string) - Subscriber email
  • $list_id (string) - MailChimp list ID
  • $tags (array) - Applied tags

Usage:

add_action('somdn_mailchimp_subscribed', 'log_subscription', 10, 3);
function log_subscription($email, $list_id, $tags) {
error_log("Subscribed {$email} to list {$list_id} with tags: " . implode(', ', $tags));
}

Use Cases:

  • Log subscriptions
  • Update user meta
  • Trigger webhooks
  • Award points

somdn_mailchimp_error​

Fires on MailChimp subscription error (Pro only).

Parameters:

  • $error (string) - Error message
  • $email (string) - User email

Usage:

add_action('somdn_mailchimp_error', 'handle_mailchimp_error', 10, 2);
function handle_mailchimp_error($error, $email) {
// Log error
error_log("MailChimp error for {$email}: {$error}");

// Notify admin
wp_mail(
get_option('admin_email'),
'MailChimp Subscription Error',
"Error subscribing {$email}: {$error}"
);
}

Use Cases:

  • Error logging
  • Admin notifications
  • Fallback subscriptions
  • Error tracking

Account History Actions​

somdn_before_account_history​

Fires before account history table (Pro only).

Parameters:

  • $user_id (int) - User ID

Usage:

add_action('somdn_before_account_history', 'add_before_history');
function add_before_history($user_id) {
echo '<p>Your download history:</p>';
}

Use Cases:

  • Add instructions
  • Display notices
  • Insert custom content

somdn_after_account_history​

Fires after account history table (Pro only).

Parameters:

  • $user_id (int) - User ID

Usage:

add_action('somdn_after_account_history', 'add_after_history');
function add_after_history($user_id) {
echo '<p>Need help? <a href="/contact/">Contact us</a></p>';
}

Use Cases:

  • Add help links
  • Display disclaimers
  • Insert custom content

somdn_redownload_success​

Fires after successful re-download (Pro only).

Parameters:

  • $download_id (int) - Download log post ID
  • $user_id (int) - User ID

Usage:

add_action('somdn_redownload_success', 'log_redownload', 10, 2);
function log_redownload($download_id, $user_id) {
error_log("User {$user_id} re-downloaded {$download_id}");
}

Use Cases:

  • Log re-downloads
  • Update statistics
  • Track user behavior

PDF Watermarking Actions​

somdn_before_pdf_watermark​

Fires before PDF watermarking starts (Pro only).

Parameters:

  • $pdf_path (string) - Path to PDF file
  • $product_id (int) - Product ID

Usage:

add_action('somdn_before_pdf_watermark', 'before_watermark', 10, 2);
function before_watermark($pdf_path, $product_id) {
error_log("Watermarking PDF for product {$product_id}");
}

Use Cases:

  • Log watermarking
  • Pre-process PDFs
  • Validate files

somdn_after_pdf_watermark​

Fires after PDF watermarking completes (Pro only).

Parameters:

  • $pdf_path (string) - Path to watermarked PDF
  • $product_id (int) - Product ID
  • $success (bool) - Whether watermarking succeeded

Usage:

add_action('somdn_after_pdf_watermark', 'after_watermark', 10, 3);
function after_watermark($pdf_path, $product_id, $success) {
if ($success) {
error_log("Successfully watermarked PDF for product {$product_id}");
} else {
error_log("Failed to watermark PDF for product {$product_id}");
}
}

Use Cases:

  • Log results
  • Clean up temp files
  • Error handling

Tracked Download Display Actions​

somdn_tracked_download_details_html​

Fires when displaying tracked download details in admin (Pro only).

Parameters:

  • $post_id (int) - Download log post ID

Usage:

add_action('somdn_tracked_download_details_html', 'show_custom_fields');
function show_custom_fields($post_id) {
$custom_value = get_post_meta($post_id, 'custom_field', true);
?>
<div class="somdn-tracked-download-content-wrap">
<div class="somdn-tracked-download-label">Custom Field</div>
<div class="somdn-tracked-download-content">
<?php echo esc_html($custom_value ?: 'N/A'); ?>
</div>
</div>
<?php
}

Use Cases:

  • Display custom fields
  • Show additional data
  • Format output

Best Practices​

Action Priority​

Use appropriate priorities:

  • 10 - Default priority
  • 5 - Run earlier
  • 20 - Run later
  • 99 - Run very late

Parameter Validation​

Always validate parameters:

add_action('somdn_count_download', 'my_action', 10, 3);
function my_action($product_id, $user_id, $variation_id) {
// Validate
$product_id = absint($product_id);
$user_id = absint($user_id);
$variation_id = absint($variation_id);

// Proceed
}

Error Handling​

Handle errors gracefully:

add_action('somdn_count_download_post_success', 'my_action');
function my_action($post_id) {
try {
// Your code
} catch (Exception $e) {
error_log('Error in my_action: ' . $e->getMessage());
}
}

Performance​

Keep actions fast:

  • Avoid heavy processing
  • Use caching when possible
  • Queue long-running tasks
  • Use background processing

What's Next​