Filter uncanny-automator

automator_send_webhook_get_fields_should_strip_qoutes

Allows users to strip the quotes. Filters webhook field values before sending, allowing customization of quote stripping.

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

Description

This filter allows developers to control whether quotes are stripped from webhook text field values before sending. By default, quotes are not stripped. Returning `true` will enable quote stripping for these fields.


Usage

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

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to use the automator_send_webhook_get_fields_should_strip_qoutes filter.
 *
 * This filter allows you to programmatically decide whether quotes should be stripped
 * from text values when sending data in a webhook. In this example, we'll conditionally
 * strip quotes if a specific WordPress option is set to true.
 */
add_filter(
	'automator_send_webhook_get_fields_should_strip_qoutes',
	function ( $should_strip_quotes ) {
		// Check if a custom option in WordPress settings indicates to strip quotes.
		// Replace 'my_plugin_strip_quotes_option' with your actual option name.
		$strip_quotes_enabled = get_option( 'my_plugin_strip_quotes_option', 'no' );

		if ( 'yes' === $strip_quotes_enabled ) {
			return true; // Enable stripping of quotes.
		}

		// Otherwise, return the original value (which is false by default).
		return $should_strip_quotes;
	},
	10, // Priority: 10 is the default.
	1  // Accepted args: The filter passes one argument ($should_strip_quotes).
);
?>

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

public function get_fields( $data, $legacy = false, $data_type = '', $parsing_args = array(), $is_check_sample = false ) {

		$prepared_data = array();

		if ( $legacy ) {
			return $this->prepare_legacy_fields( $data, $parsing_args );
		}

		if ( ! isset( $data['WEBHOOK_FIELDS'] ) ) {
			return $prepared_data;
		}

		$fields = ! is_array( $data['WEBHOOK_FIELDS'] ) ? json_decode( $data['WEBHOOK_FIELDS'], true ) : $data['WEBHOOK_FIELDS'];

		if ( empty( $fields ) ) {
			return $prepared_data;
		}

		foreach ( $fields as $field ) {

			$key   = isset( $field['KEY'] ) ? $this->maybe_parse_tokens( $field['KEY'], $parsing_args ) : null;
			$type  = isset( $field['VALUE_TYPE'] ) ? $this->maybe_parse_tokens( $field['VALUE_TYPE'], $parsing_args ) : 'text';
			$value = isset( $field['VALUE'] ) ? $this->maybe_parse_tokens( $field['VALUE'], $parsing_args ) : null;

			// Do not allow empty key.
			if ( '' !== $key && ! is_null( $key ) && ! is_null( $value ) ) {
				switch ( $type ) {
					case 'null':
					case 'undefined':
						$value = null;
						break;
					case 'int':
						$value = absint( $value );
						break;
					case 'float':
						$value = floatval( $value );
						break;
					case 'bool':
						$value = str_replace( array( '"', ''' ), '', html_entity_decode( $value ) );
						if ( 'true' === strtolower( $value ) || 'false' === strtolower( $value ) ) {
							$value = 'true' === strtolower( $value ) ? true : false;
						} elseif ( is_numeric( $value ) && ( 0 === absint( $value ) || 1 === absint( $value ) ) ) {
							$value = boolval( $value );
						} else {
							$value = (string) $value;
						}
						break;
					case 'text':
					default:
						/**
						 * Allows users to strip the quotes.
						 *
						 * @see <https://secure.helpscout.net/conversation/2067343003/45133?folderId=2122433>
						 */
						$should_strip_qoutes = apply_filters( 'automator_send_webhook_get_fields_should_strip_qoutes', false );

						if ( $should_strip_qoutes ) {
							// Decode HTML entities and replace " and '
							$value = str_replace( array( '"', ''' ), '', html_entity_decode( $value ) );
						}

						$value = apply_filters( 'automator_outgoing_webhook_default_data_value', (string) $value, $key, $type, $this );

						break;

				}

				$prepared_data[ $key ] = apply_filters( 'automator_outgoing_webhook_value', $value, $key, $type, $this );
			}
		}

		$prepared_data = $this->create_tree( $prepared_data, $data_type );

		return $this->format_outgoing_data( $prepared_data, $data_type, $is_check_sample );
	}


Scroll to Top