Filter
uncanny-automator-pro
automator_pro_formatter_extract_email_pattern
Filters the regex pattern used to extract email addresses from text.
add_filter( 'automator_pro_formatter_extract_email_pattern', $callback, 10, 1 );
Description
Filters the regular expression pattern used to extract email addresses from text. Developers can modify this pattern to customize how email addresses are identified and extracted by the text formatter integration. This hook fires before the `preg_match` function is called.
Usage
add_filter( 'automator_pro_formatter_extract_email_pattern', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Example of how to modify the email extraction regex for Uncanny Automator Pro.
* This filter allows developers to customize the regular expression used to find email addresses
* within a given text input, potentially for more specific or broader matching.
*
* @param string $regex The default regular expression for matching email addresses.
* @return string The modified or original regular expression.
*/
add_filter( 'automator_pro_formatter_extract_email_pattern', function( $regex ) {
// Example: Make the email matching case-insensitive by removing the 'i' flag
// and then re-adding it if needed, or adjust the domain part.
// For instance, to allow longer TLDs (e.g., .museum, .travel):
$modified_regex = preg_replace( '/([a-z0-9]{2,4})+$/i', '([a-z0-9]{2,6})+', $regex );
// You could also add specific domain restrictions if necessary.
// Example: Allow only .com, .org, and .net domains
// $modified_regex = '/([a-z0-9_.-])+@(([a-z0-9-])+.)+(com|org|net)+/i';
// In this example, we'll simply return the modified regex that allows longer TLDs.
return $modified_regex;
}, 10, 1 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
uncanny-automator-pro/src/integrations/formatter/actions/text-formatter.php:390
public function format_extract_email( $input ) {
$regexp = apply_filters( 'automator_pro_formatter_extract_email_pattern', '/([a-z0-9_.-])+@(([a-z0-9-])+.)+([a-z0-9]{2,4})+/i' );
preg_match( $regexp, $input, $matches );
if ( isset( $matches[0] ) ) {
return $matches[0];
}
return '';
}