Skip to main content

Filters reference

Who this is for

This page is for developers who need to change plugin behavior or data using WordPress filters. Most users can accomplish everything through WP Enhanced > Free Download Woo without code.

Core filters

somdn_product_page_args

Modify arguments passed to product page rendering.

Parameters:

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

Returns: Array of arguments

Usage:

add_filter('somdn_product_page_args', 'modify_display_args', 10, 2);
function modify_display_args($args, $product_id) {
// Modify button text for specific product
if ($product_id == 123) {
$args['button_text'] = 'Get Your Free Copy';
}
return $args;
}

Available Arguments:

  • button_text - Download button text
  • button_classes - CSS classes for button
  • link_classes - CSS classes for links
  • show_files - Whether to show file list
  • archive - Whether displaying on archive page

somdn_product_page_content_woo

Modify WooCommerce hook for download UI placement.

Parameters:

  • $hook (string) - WooCommerce hook name

Returns: String (hook name)

Default: woocommerce_single_product_summary

Usage:

add_filter('somdn_product_page_content_woo', 'custom_product_page_hook');
function custom_product_page_hook($hook) {
return 'woocommerce_simple_add_to_cart';
}

Use Cases:

  • Change download button position
  • Integrate with custom themes
  • Adjust layout

somdn_get_button_classes

Modify download button CSS classes.

Parameters:

  • $classes (string) - CSS classes

Returns: String of CSS classes

Usage:

add_filter('somdn_get_button_classes', 'custom_button_classes');
function custom_button_classes($classes) {
return $classes . ' button custom-class';
}

Example: Remove Default Class

add_filter('somdn_get_button_classes', 'remove_default_class');
function remove_default_class($classes) {
return ' button'; // Only 'button' class
}

Modify download link CSS classes.

Parameters:

  • $classes (string) - CSS classes

Returns: String of CSS classes

Usage:

add_filter('somdn_get_link_classes', 'custom_link_classes');
function custom_link_classes($classes) {
return $classes . ' custom-link-class';
}

Download Filters

somdn_download_path

Modify file path before download.

Parameters:

  • $file_path (string) - Original file path
  • $product_id (int) - Product ID

Returns: String (file path)

Usage:

add_filter('somdn_download_path', 'modify_download_path', 10, 2);
function modify_download_path($file_path, $product_id) {
// Serve from different location
if ($product_id == 123) {
return '/custom/path/to/file.pdf';
}
return $file_path;
}

Use Cases:

  • External file hosting
  • PDF watermarking
  • Dynamic file generation
  • CDN integration

somdn_download_filename

Modify downloaded filename.

Parameters:

  • $filename (string) - Original filename
  • $product_id (int) - Product ID

Returns: String (filename)

Usage:

add_filter('somdn_download_filename', 'custom_filename', 10, 2);
function custom_filename($filename, $product_id) {
$product = wc_get_product($product_id);
return sanitize_file_name($product->get_name()) . '.pdf';
}

somdn_zip_filename

Modify ZIP archive filename.

Parameters:

  • $filename (string) - Original ZIP filename
  • $product_id (int) - Product ID

Returns: String (filename)

Usage:

add_filter('somdn_zip_filename', 'custom_zip_name', 10, 2);
function custom_zip_name($filename, $product_id) {
return 'product-' . $product_id . '-files.zip';
}

Login & Validation Filters

somdn_is_required_login_check

Override login requirement check.

Parameters:

  • $required (bool) - Whether login is required
  • $setting (bool) - Login requirement setting
  • $product_id (int) - Product ID

Returns: Boolean

Usage:

add_filter('somdn_is_required_login_check', 'custom_login_check', 10, 3);
function custom_login_check($required, $setting, $product_id) {
// Allow downloads without login for specific category
if (has_term('free', 'product_cat', $product_id)) {
return false; // No login required
}
return $required;
}

Use Cases:

  • Category-based login rules
  • User role exceptions
  • Time-based access

somdn_is_login_check_valid

Override login validation on download page.

Parameters:

  • $valid (bool) - Whether login check is valid
  • $require_login (bool) - Login requirement setting
  • $product_id (int) - Product ID
  • $product (WC_Product) - Product object
  • $args (array) - Display arguments

Returns: Boolean

Usage:

add_filter('somdn_is_login_check_valid', 'custom_login_valid', 10, 5);
function custom_login_valid($valid, $require_login, $product_id, $product, $args) {
// Allow guests for specific category
if (has_term('free', 'product_cat', $product_id)) {
return true;
}
return $valid;
}

Download Limits Filters (Pro)

somdn_user_limits_excluded

Check if user is excluded from download limits.

Parameters:

  • $excluded (bool) - Whether user is excluded
  • $user_id (int) - User ID

Returns: Boolean

Usage:

add_filter('somdn_user_limits_excluded', 'exclude_vip_users', 10, 2);
function exclude_vip_users($excluded, $user_id) {
$user = get_user_by('id', $user_id);

// Exclude administrators and VIP role
if (in_array('administrator', $user->roles) || in_array('vip', $user->roles)) {
return true;
}

return $excluded;
}

Use Cases:

  • Exclude specific users
  • Exclude user roles
  • Exclude by membership
  • Temporary exclusions

somdn_get_user_custom_limits

Modify user's download limits.

Parameters:

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

Returns: Array of limit configuration

Limit Array Structure:

array(
'type' => 'user', // 'user' or 'ip'
'amount' => 5, // Number of downloads
'freq' => 'Day', // 'Day', 'Week', 'Month', 'Year'
'products' => array(), // Product IDs (empty = all)
'error' => 'Message', // Error message
'login_req' => true // Require login
)

Usage:

add_filter('somdn_get_user_custom_limits', 'custom_user_limits', 10, 3);
function custom_user_limits($limits, $user_id, $product_id) {
// Double limits for premium members
if (user_has_premium_membership($user_id)) {
$limits['amount'] = $limits['amount'] * 2;
}

return $limits;
}

Use Cases:

  • Membership-based limits
  • Role-based limits
  • Product-specific limits
  • Time-based limits

somdn_check_product_in_limit

Control which products are subject to limits.

Parameters:

  • $in_limit (bool) - Whether product is limited
  • $product_id (int) - Product ID
  • $limits (array) - Limit configuration

Returns: Boolean

Usage:

add_filter('somdn_check_product_in_limit', 'exclude_products', 10, 3);
function exclude_products($in_limit, $product_id, $limits) {
// Exclude specific products from limits
$excluded = array(100, 200, 300);
if (in_array($product_id, $excluded)) {
return false;
}
return $in_limit;
}

somdn_are_downloads_tracked

Override whether tracking is enabled.

Parameters:

  • $tracked (bool) - Whether tracking is enabled

Returns: Boolean

Usage:

add_filter('somdn_are_downloads_tracked', 'conditional_tracking');
function conditional_tracking($tracked) {
// Don't track admin downloads
if (current_user_can('administrator')) {
return false;
}
return $tracked;
}

Email Capture Filters (Pro)

capture_emails_active

Override whether email capture is active.

Parameters:

  • $active (bool) - Whether email capture is active

Returns: Boolean

Usage:

add_filter('capture_emails_active', 'conditional_email_capture');
function conditional_email_capture($active) {
// Disable for specific products
if (is_product() && get_the_ID() == 123) {
return false;
}
return $active;
}

somdn_capture_email_invalid

Validate email addresses.

Parameters:

  • $invalid (bool) - Whether email is invalid
  • $email (string) - Email address

Returns: Boolean

Usage:

add_filter('somdn_capture_email_invalid', 'block_disposable_emails', 10, 2);
function block_disposable_emails($invalid, $email) {
$blocked_domains = array('tempmail.com', 'throwaway.email');
$domain = substr(strrchr($email, "@"), 1);

if (in_array($domain, $blocked_domains)) {
return true; // Mark as invalid
}

return $invalid;
}

somdn_capture_email_empty

Customize "email required" error message.

Parameters:

  • $message (string) - Error message

Returns: String

Usage:

add_filter('somdn_capture_email_empty', 'custom_email_error');
function custom_email_error($message) {
return 'Please provide your email address to continue.';
}

somdn_capture_email_label

Customize email field label.

Parameters:

  • $label (string) - Field label

Returns: String

Usage:

add_filter('somdn_capture_email_label', 'custom_email_label');
function custom_email_label($label) {
return 'Enter your email to download:';
}

somdn_capture_fname_label

Customize first name field label.

Parameters:

  • $label (string) - Field label

Returns: String

Usage:

add_filter('somdn_capture_fname_label', 'custom_fname_label');
function custom_fname_label($label) {
return 'Your first name:';
}

Statistics Filters (Pro)

somdn_get_downloads_data_args

Modify statistics export query arguments.

Parameters:

  • $args (array) - WP_Query arguments
  • $original_args (array) - Original arguments

Returns: Array of WP_Query arguments

Usage:

add_filter('somdn_get_downloads_data_args', 'custom_export_query', 10, 2);
function custom_export_query($args, $original_args) {
// Export only guest downloads
$args['meta_query'] = array(
array(
'key' => 'somdn_user_id',
'value' => '0',
'compare' => '='
)
);
return $args;
}

Example: Export Only Subscribers

add_filter('somdn_get_downloads_data_args', 'export_subscribers_only');
function export_subscribers_only($args) {
$args['meta_query'] = array(
array(
'key' => 'somdn_user_subbed',
'value' => '',
'compare' => '!='
)
);
return $args;
}

somdn_stats_get_headers_all

Add custom columns to statistics export.

Parameters:

  • $headers (array) - Export column headers

Returns: Array of headers

Header Structure:

array(
'header_id' => array(
'type' => 'custom', // 'custom' or 'default'
'title' => 'Column Name',
'content' => 'string' // Data type
)
)

Usage:

add_filter('somdn_stats_get_headers_all', 'add_custom_columns');
function add_custom_columns($headers) {
$headers['user_role'] = array(
'type' => 'custom',
'title' => 'User Role',
'content' => 'string'
);
return $headers;
}

somdn_stats_get_custom_field_{header_id}

Populate custom export column data.

Parameters:

  • $value (mixed) - Column value
  • $download_id (int) - Download log post ID

Returns: Mixed (column value)

Usage:

add_filter('somdn_stats_get_custom_field_user_role', 'get_user_role_data', 10, 2);
function get_user_role_data($value, $download_id) {
$user_id = get_post_meta($download_id, 'somdn_user_id', true);
if ($user_id) {
$user = get_user_by('id', $user_id);
return $user ? implode(', ', $user->roles) : 'Guest';
}
return 'Guest';
}

somdn_max_downloads_to_report_xlsx

Change maximum export record count.

Parameters:

  • $max (int) - Maximum records

Returns: Integer

Default: 15000

Usage:

add_filter('somdn_max_downloads_to_report_xlsx', 'increase_export_limit');
function increase_export_limit($max) {
return 20000; // Increase to 20,000
}

Warning: Higher limits require more memory and execution time.

MailChimp Filters (Pro)

somdn_newsletter_sub_tags

Modify MailChimp subscription tags.

Parameters:

  • $tags (array) - Tag array
  • $product_id (int) - Product ID
  • $variation_id (int) - Variation ID

Returns: Array of tags

Usage:

add_filter('somdn_newsletter_sub_tags', 'custom_mailchimp_tags', 10, 3);
function custom_mailchimp_tags($tags, $product_id, $variation_id) {
// Add user role tag
$user = wp_get_current_user();
if ($user->ID) {
$tags[] = 'role-' . $user->roles[0];
}

// Add custom tag
$tags[] = 'source-website';

return $tags;
}

somdn_mailchimp_subscriber_data

Modify subscriber data before sending to MailChimp.

Parameters:

  • $data (array) - Subscriber data
  • $email (string) - Email address

Returns: Array of subscriber data

Usage:

add_filter('somdn_mailchimp_subscriber_data', 'add_merge_fields', 10, 2);
function add_merge_fields($data, $email) {
// Add custom merge fields
$data['merge_fields']['WEBSITE'] = home_url();
$data['merge_fields']['SOURCE'] = 'Free Download';

return $data;
}

somdn_mailchimp_notify_on_error

Enable error notifications.

Parameters:

  • $notify (bool) - Whether to notify on error

Returns: Boolean

Usage:

add_filter('somdn_mailchimp_notify_on_error', '__return_true');

somdn_mailchimp_error_email

Set error notification email address.

Parameters:

  • $email (string) - Email address

Returns: String

Usage:

add_filter('somdn_mailchimp_error_email', 'custom_error_email');
function custom_error_email($email) {
return '[email protected]';
}

PDF Watermarking Filters (Pro)

somdn_enable_pdf_watermark

Control watermarking per download.

Parameters:

  • $enable (bool) - Whether to watermark
  • $product_id (int) - Product ID
  • $user_id (int) - User ID

Returns: Boolean

Usage:

add_filter('somdn_enable_pdf_watermark', 'conditional_watermark', 10, 3);
function conditional_watermark($enable, $product_id, $user_id) {
// Don't watermark for VIP users
$user = get_user_by('id', $user_id);
if ($user && in_array('vip', $user->roles)) {
return false;
}
return $enable;
}

somdn_pdf_watermark_text

Modify watermark text.

Parameters:

  • $text (string) - Watermark text
  • $product_id (int) - Product ID

Returns: String

Usage:

add_filter('somdn_pdf_watermark_text', 'custom_watermark_text', 10, 2);
function custom_watermark_text($text, $product_id) {
if ($product_id == 123) {
return 'Premium Content - Licensed to {user_name}';
}
return $text;
}

somdn_pdf_watermark_style

Customize watermark appearance.

Parameters:

  • $style (array) - Style configuration
  • $product_id (int) - Product ID

Returns: Array of style settings

Style Array:

array(
'font_size' => 12,
'color' => array(0, 0, 0), // RGB
'opacity' => 50,
'rotation' => 0,
'position' => 'bottom-center'
)

Usage:

add_filter('somdn_pdf_watermark_style', 'custom_watermark_style', 10, 2);
function custom_watermark_style($style, $product_id) {
$style['font_size'] = 16;
$style['color'] = array(255, 0, 0); // Red
$style['opacity'] = 75;
$style['rotation'] = 45;
return $style;
}

somdn_pdf_watermark_placeholders

Add custom watermark placeholders.

Parameters:

  • $placeholders (array) - Placeholder array
  • $user_id (int) - User ID
  • $product_id (int) - Product ID

Returns: Array of placeholders

Usage:

add_filter('somdn_pdf_watermark_placeholders', 'add_custom_placeholders', 10, 3);
function add_custom_placeholders($placeholders, $user_id, $product_id) {
$placeholders['{company}'] = get_user_meta($user_id, 'company', true);
$placeholders['{license}'] = get_post_meta($product_id, 'license_key', true);
return $placeholders;
}

Account History Filters (Pro)

somdn_account_tab_title

Change My Account tab title.

Parameters:

  • $title (string) - Tab title

Returns: String

Usage:

add_filter('somdn_account_tab_title', 'custom_tab_title');
function custom_tab_title($title) {
return 'Download History';
}

somdn_history_per_page

Change pagination count.

Parameters:

  • $per_page (int) - Items per page

Returns: Integer

Usage:

add_filter('somdn_history_per_page', 'custom_per_page');
function custom_per_page($per_page) {
return 20;
}

somdn_allow_redownload

Control re-download permission.

Parameters:

  • $allow (bool) - Whether to allow
  • $download_id (int) - Download log post ID

Returns: Boolean

Usage:

add_filter('somdn_allow_redownload', 'time_limit_redownload', 10, 2);
function time_limit_redownload($allow, $download_id) {
// Only allow re-download within 30 days
$download_date = get_post_time('U', false, $download_id);
$days_ago = (time() - $download_date) / DAY_IN_SECONDS;

return $days_ago <= 30;
}

somdn_history_columns

Modify history table columns.

Parameters:

  • $columns (array) - Column array

Returns: Array of columns

Usage:

add_filter('somdn_history_columns', 'custom_history_columns');
function custom_history_columns($columns) {
// Add custom column
$columns['custom'] = 'Custom Column';

// Remove files column
unset($columns['files']);

return $columns;
}

somdn_expire_temp_download_email_hours

Set email download link expiration time.

Parameters:

  • $hours (int) - Hours until expiration

Returns: Integer

Default: 24 hours

Usage:

add_filter('somdn_expire_temp_download_email_hours', 'custom_expire_hours');
function custom_expire_hours($hours) {
return 480; // 20 days
}

somdn_delete_temp_download_email_days

Set email download link deletion time.

Parameters:

  • $days (int) - Days until deletion

Returns: Integer

Default: 30 days

Usage:

add_filter('somdn_delete_temp_download_email_days', 'custom_delete_days');
function custom_delete_days($days) {
return 40; // 40 days
}

Best Practices

Return Values

Always return a value:

add_filter('somdn_product_page_args', 'my_filter', 10, 2);
function my_filter($args, $product_id) {
// Modify $args
return $args; // MUST return
}

Data Validation

Validate and sanitize:

add_filter('somdn_get_user_custom_limits', 'my_limits', 10, 3);
function my_limits($limits, $user_id, $product_id) {
// Validate
$limits['amount'] = absint($limits['amount']);
$limits['freq'] = sanitize_text_field($limits['freq']);

return $limits;
}

Performance

Keep filters fast:

  • Avoid database queries when possible
  • Use caching
  • Return early when possible

Compatibility

Check before modifying:

add_filter('somdn_product_page_args', 'my_filter', 10, 2);
function my_filter($args, $product_id) {
// Check if key exists
if (isset($args['button_text'])) {
$args['button_text'] = 'Custom Text';
}
return $args;
}

What's Next