Filter
uncanny-automator
automator_get_allowed_attachment_ext
Filters the list of allowed attachment file extensions for use in automations.
add_filter( 'automator_get_allowed_attachment_ext', $callback, 10, 1 );
Description
This filter allows developers to modify the list of allowed file extensions for email attachments. It fires when the plugin retrieves the default common file extensions. Developers can add or remove extensions to customize which file types are permitted for attachments, enhancing security or flexibility for specific use cases.
Usage
add_filter( 'automator_get_allowed_attachment_ext', 'your_function_name', 10, 1 );
Parameters
-
$common_file_extensions(mixed) - This parameter contains a mixed array of common file extensions that are allowed for attachments.
Return Value
The filtered value.
Examples
/**
* Filter to add support for PDF files in email attachments.
*
* By default, the 'automator_get_allowed_attachment_ext' filter might not include PDF.
* This example demonstrates how to add PDF to the list of allowed extensions.
*
* @param array $common_file_extensions The current array of allowed file extensions.
* @return array The modified array of allowed file extensions, now including '.pdf'.
*/
add_filter( 'automator_get_allowed_attachment_ext', function( $common_file_extensions ) {
// Ensure $common_file_extensions is an array before adding to it.
if ( ! is_array( $common_file_extensions ) ) {
$common_file_extensions = array();
}
// Add '.pdf' if it's not already present.
if ( ! in_array( '.pdf', $common_file_extensions, true ) ) {
$common_file_extensions[] = '.pdf';
}
// Return the modified array of allowed extensions.
return $common_file_extensions;
}, 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
src/global-functions.php:1210
function automator_get_allowed_attachment_ext() {
return apply_filters( 'automator_get_allowed_attachment_ext', Extension_Support::$common_file_extensions );
}