|
/ Documentation /Developer Hooks & Events/ suredonation_email_field_char_limits Filter Hook

suredonation_email_field_char_limits Filter Hook

Overview

The suredonation_email_field_char_limits filter allows developers to customize the maximum character limits applied to values entered in the SureDonation Email field.

The filter controls the maximum length of:

  • The local part, which appears before @.
  • The domain part, which appears after @.

By default, SureDonation follows the commonly used RFC 5321 limits.

When to Use This Filter

Use this filter when you need to:

  • Apply stricter email length limits for your website.
  • Adjust the local-part limit for a specific business requirement.
  • Customize email validation rules for an integration.
  • Prevent unusually long email addresses from being submitted.

Filter Signature

apply_filters( 'suredonation_email_field_char_limits', $defaults );

Parameters

ParameterTypeDescription
$limitsarrayThe maximum character limits for the email local and domain parts.

The array contains:

[

'local'  => 64,

'domain' => 255,

]

Parameters in Detail

KeyTypeDescriptionDefault
localintMaximum characters allowed before @.64
domainintMaximum characters allowed after @.255

Default Value

[

'local'  => 64,

'domain' => 255,

]

Return Value

Return an array containing the local and domain limits.

return $limits;

Each value must be a positive integer.

If a key is missing or its value is zero or negative, SureDonation falls back to the default value for that key.

Basic Usage

add_filter( 'suredonation_email_field_char_limits', 'your_custom_function', 10, 1 );

function your_custom_function( $limits ) {

// Adjust email character limits here.

return $limits;

}

Example: Set a Stricter Local-Part Limit

The following example reduces the maximum local-part length from 64 to 32 characters.

add_filter( 'suredonation_email_field_char_limits', 'mysite_email_limits', 10, 1 );

function mysite_email_limits( $limits ) {

$limits['local'] = 32;

return $limits;

}

With this configuration:

  • Local part: maximum 32 characters.
  • Domain part: maximum 255 characters.

Example: Change Both Limits

You can modify both limits when required.

add_filter( 'suredonation_email_field_char_limits', 'mysite_custom_email_limits', 10, 1);

function mysite_custom_email_limits( $limits ) {

$limits['local']  = 50;

$limits['domain'] = 200;

return $limits;

}

Important: Total Email Length Limit

SureDonation also applies a defensive total length limit of 254 characters.

This limit is applied regardless of the values returned by this filter.

For example, increasing the local and domain limits does not allow an email address longer than the database-supported total length.

Validation Flow

The filter is used during server-side email validation:

Email field submitted

        â†“

Email length validation

        â†“

suredonation_email_field_char_limits

        â†“

Local and domain limits applied

        â†“

254-character total cap applied

        â†“

Email passes or fails validation

This filter is applied in:

Field_Validation::validate_email_length()

The filter controls the individual local-part and domain-part limits, while SureDonation continues to enforce the defensive 254-character total limit.

When modifying these values, make sure the limits are compatible with the requirements of your email provider and other systems that process the submitted email address.

Related Hooks

  • Suredonation_default_validation_messages: Filters the default validation error messages.
  • Suredonation_validate_field: Allows custom validation of individual SureDonation form fields.
Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
Table of Contents
Scroll to Top