Skip to content
Home » Documentation » Contact Form 7 – Dynamic Text Extension » Filter: Sanitizing Values

Filter: Sanitizing Values

To keep our users safe, Contact Form 7 – Dynamic Text Extension (DTX) sanitizes and escapes all data before inserting them as the value or placeholder of a contact form.

When sanitizing data, DTX attempts to identify the type of the value and will use sanitize_email(), sanitize_url(), sanitize_key(), and sanitize_title() where applicable.

Advanced users may want to extend this functionality by adding their own custom sanitization. The filter sends three (3) parameters:

  1. $value (string—the value to be sanitized)
  2. $type (string—the type of sanitation to return, the default is auto where automatic identification will be used to attempt to identify URLs and email addresses vs text)
  3. $protocols (array|string|false—specify protocols to allow either as an array of string values or a string value of comma separated protocols, the default is boolean false where DTX’s default uses only http and https protocols)

Example of Custom Sanitizing

/**
 * Custom DTX Sanitize Filter
 *
 * @param string $value value to be sanitized
 * @param string $type Optional. The type of sanitation to return. Default is `auto` where automatic identification will be used to attempt to identify URLs and email addresses vs text.
 * @param array|string $protocols Optional. Specify protocols to allow either as an array of string values or a string value of comma separated protocols.
 *
 * @return string the modified value
 */
function custom_dtx_sanitize($value = '', $type = 'auto', $protocols = false)
{
    // Do something cool to $value
    return $value;
}
add_filter('wpcf7dtx_sanitize', 'custom_dtx_sanitize', 10, 3);

Disable DTX Sanitizing Filter

While it’s highly discouraged as this could put your website, database, or users at risk to allow unfiltered data, you can disable the filter using this code snippet:

remove_filter('wpcf7dtx_sanitize', 'wpcf7dtx_sanitize', 10);

View Source Code

View the current source code. This feature was introduced in version 3.3.0 of the Contact Form 7 – Dynamic Text Extension WordPress plugin.

Related Post Module Attributes Before

array(29) {
  ["post_type"]=>
  string(4) "post"
  ["post_id"]=>
  string(1) "0"
  ["exclude"]=>
  string(1) "0"
  ["title"]=>
  string(32) "Related Articles & Tutorials"
  ["description"]=>
  string(0) ""
  ["max"]=>
  string(1) "3"
  ["post_ids"]=>
  string(0) ""
  ["exclude_ids"]=>
  string(0) ""
  ["is_series"]=>
  string(0) ""
  ["featured_term"]=>
  string(3) "307"
  ["exclude_terms"]=>
  string(0) ""
  ["exclusive"]=>
  string(1) "1"
  ["order"]=>
  string(4) "DESC"
  ["show_image"]=>
  string(2) "on"
  ["image_size"]=>
  string(6) "medium"
  ["menu_order_label"]=>
  string(0) ""
  ["show_order_label"]=>
  string(2) "on"
  ["show_date"]=>
  string(2) "on"
  ["show_meta_keys"]=>
  string(2) "on"
  ["show_modified"]=>
  string(0) ""
  ["show_author"]=>
  string(0) ""
  ["show_categories"]=>
  string(0) ""
  ["show_primary_category"]=>
  string(0) ""
  ["show_description"]=>
  string(0) ""
  ["show_reading_time"]=>
  string(2) "on"
  ["show_cta"]=>
  string(2) "on"
  ["cta"]=>
  string(9) "Read more"
  ["autoplay"]=>
  string(0) ""
  ["allow_sticky"]=>
  string(0) ""
}

Related Post Module Attributes

array(29) {
  ["post_type"]=>
  string(4) "post"
  ["post_id"]=>
  string(1) "0"
  ["exclude"]=>
  string(1) "0"
  ["title"]=>
  string(32) "Related Articles & Tutorials"
  ["description"]=>
  string(0) ""
  ["max"]=>
  string(1) "3"
  ["post_ids"]=>
  string(0) ""
  ["exclude_ids"]=>
  string(0) ""
  ["is_series"]=>
  string(0) ""
  ["featured_term"]=>
  string(3) "307"
  ["exclude_terms"]=>
  string(0) ""
  ["exclusive"]=>
  string(1) "1"
  ["order"]=>
  string(4) "DESC"
  ["show_image"]=>
  string(2) "on"
  ["image_size"]=>
  string(6) "medium"
  ["menu_order_label"]=>
  string(0) ""
  ["show_order_label"]=>
  string(2) "on"
  ["show_date"]=>
  string(2) "on"
  ["show_meta_keys"]=>
  string(2) "on"
  ["show_modified"]=>
  string(0) ""
  ["show_author"]=>
  string(0) ""
  ["show_categories"]=>
  string(0) ""
  ["show_primary_category"]=>
  string(0) ""
  ["show_description"]=>
  string(0) ""
  ["show_reading_time"]=>
  string(2) "on"
  ["show_cta"]=>
  string(2) "on"
  ["cta"]=>
  string(9) "Read more"
  ["autoplay"]=>
  string(0) ""
  ["allow_sticky"]=>
  string(0) ""
}