Filter uncanny-automator-pro

automator_pro_formatter_extract_url_pattern

Filters the default URL extraction pattern used by the Formatter integration, allowing customization of how URLs are identified.

add_filter( 'automator_pro_formatter_extract_url_pattern', $callback, 10, 1 );

Description

Allows modification of the regular expression used to extract URLs from text. Developers can override the default pattern to customize URL detection for Uncanny Automator's text formatter, enhancing flexibility for various link formats.


Usage

add_filter( 'automator_pro_formatter_extract_url_pattern', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

add_filter( 'automator_pro_formatter_extract_url_pattern', 'my_custom_url_pattern_for_automator', 10, 1 );

/**
 * Changes the default URL extraction pattern for Uncanny Automator Pro's text formatter.
 *
 * This function allows for a more specific or broader extraction of URLs.
 * For example, this might be used to include URLs with specific subdomains
 * or to exclude certain types of links.
 *
 * @param string $default_pattern The default regular expression pattern for extracting URLs.
 *
 * @return string The modified or original regular expression pattern.
 */
function my_custom_url_pattern_for_automator( $default_pattern ) {
    // Example: Let's say we only want to extract URLs that start with 'https://'
    // and ignore 'http://' or 'ftp://'.
    $custom_pattern = '/bhttps://S+/i';

    // In a real-world scenario, you might have more complex logic here,
    // perhaps based on user roles, specific automation triggers, or other settings.
    // For this example, we'll just replace the default pattern.

    return $custom_pattern;

    // Alternatively, if you wanted to *add* to the default pattern, you could do something like:
    // return $default_pattern . '|bcustomprotocol://S+/i';
}

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:406

public function format_extract_url( $input ) {

		$regexp = apply_filters( 'automator_pro_formatter_extract_url_pattern', '/b(?:https?|ftp)://S+/i' );

		preg_match( $regexp, $input, $matches );

		if ( isset( $matches[0] ) ) {
			return $matches[0];
		}

		return '';
	}


Scroll to Top