Filter uncanny-automator

automator_outgoing_webhook_array_key_in_token_separator

Filters the separator used within outgoing webhook tokens when keys are combined.

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

Description

Filters the separator used to join array keys when generating webhook tokens. This allows developers to customize how nested array keys are represented in tokens, such as changing '|' to a different character. Use this to control the format of your webhook token generation.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Example of using the 'automator_outgoing_webhook_array_key_in_token_separator' filter.
 *
 * This filter allows you to change the separator used when joining array keys
 * to form a unique token for webhook data.
 *
 * @param string $separator The default separator character.
 *
 * @return string The modified separator character.
 */
add_filter( 'automator_outgoing_webhook_array_key_in_token_separator', function( $separator ) {
	// Change the separator from the default '|' to '::'
	return '::';
}, 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/core/lib/webhooks/class-automator-send-webhook.php:1060

public static function get_leafs( $array, $add_data = false ) {
		$leafs = array();

		if ( ! is_array( $array ) ) {
			return $leafs;
		}

		$array_iterator    = new RecursiveArrayIterator( $array );
		$iterator_iterator = new RecursiveIteratorIterator( $array_iterator, RecursiveIteratorIterator::LEAVES_ONLY );
		foreach ( $iterator_iterator as $key => $value ) {
			$keys = array();
			for ( $i = 0; $i < $iterator_iterator->getDepth(); $i++ ) { // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
				$keys[] = $iterator_iterator->getSubIterator( $i )->key();
			}
			$keys[]   = $key;
			$leaf_key = implode( apply_filters( 'automator_outgoing_webhook_array_key_in_token_separator', '|' ), $keys );

			//$leafs[ $leaf_key ] = $value;
			$leafs[] = array(
				'key'  => $leaf_key,
				'type' => self::value_maybe_of_type( $leaf_key, $value ),
				'data' => true === $add_data ? $value : '',
			);
		}

		return $leafs;
	}


Scroll to Top