Contact Form 7 Shortcodes

Below, you’ll find a detailed guide on how to add the Contact Form 7 – Dynamic Text Extension Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Contact Form 7 – Dynamic Text Extension Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Contact Form 7 – Dynamic Text Extension Plugin and the shortcodes it provides:

Plugin Icon
Contact Form 7 – Dynamic Text Extension

"Contact Form 7 – Dynamic Text Extension is a powerful WordPress plugin, designed to enhance your website's forms. It dynamically populates fields for personalized user interaction."

★★★★☆ (96) Active Installs: 100000+ Tested with: 6.3.2 PHP Version: 7.4
Included Shortcodes:
  • [CF7_GET]
  • [CF7_POST]
  • [CF7_URL]
  • [CF7_referrer]
  • [CF7_bloginfo]
  • [CF7_get_post_var]
  • [CF7_get_custom_field]
  • [CF7_get_current_var]
  • [CF7_get_current_user]
  • [CF7_get_attachment]
  • [CF7_get_cookie]
  • [CF7_get_taxonomy]
  • [CF7_get_theme_option]
  • [CF7_guid]

Contact Form 7 Dynamic Text Extension [CF7_GET] Shortcode

The Contact Form 7 Dynamic Text Extension shortcode retrieves specific data from a URL. The ‘CF7_GET’ shortcode is used to extract data from the URL parameters. The ‘key’ attribute specifies the parameter to retrieve. The ‘default’ attribute allows you to set a fallback value if the key is not found. The ‘obfuscate’ attribute is used to mask the retrieved value. The shortcode applies filters to sanitize and escape the retrieved data, ensuring it’s safe for use.

Shortcode: [CF7_GET]

Parameters

Here is a list of all possible CF7_GET shortcode parameters and attributes:

  • key – Specifies the GET parameter to retrieve.
  • default – Value returned if the key doesn’t exist.
  • obfuscate – Determines if the value should be obscured.

Examples and Usage

Basic example – A simple usage of the shortcode to retrieve a GET parameter by its key. If the parameter is not found, an empty string will be returned.

[CF7_GET key='parameter1' /]

Advanced examples

Using the shortcode with a default value. If the specified GET parameter is not found, the default value will be returned instead.

[CF7_GET key='parameter1' default='defaultValue' /]

Using the shortcode with obfuscation. If the obfuscate attribute is set to ‘yes’, the value of the GET parameter will be obfuscated.

[CF7_GET key='parameter1' obfuscate='yes' /]

Using the shortcode with all possible attributes. If the GET parameter is not found, the default value is returned, and if obfuscate is set to ‘yes’, the returned value is obfuscated.

[CF7_GET key='parameter1' default='defaultValue' obfuscate='yes' /]

PHP Function Code

In case you have difficulties debugging what causing issues with [CF7_GET] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('CF7_GET', 'wpcf7dtx_get', 10, 1);

Shortcode PHP function:

function wpcf7dtx_get($atts = array())
{
    extract(shortcode_atts(array(
        'key' => 0,
        'default' => '',
        'obfuscate' => ''
    ), array_change_key_case((array)$atts, CASE_LOWER)));
    $value = apply_filters('wpcf7dtx_sanitize', wpcf7dtx_array_has_key($key, $_GET, $default));
    return apply_filters('wpcf7dtx_escape', $value, $obfuscate);
}

Code file location:

contact-form-7-dynamic-text-extension/contact-form-7-dynamic-text-extension/includes/shortcodes.php

Contact Form 7 Dynamic Text Extension [CF7_POST] Shortcode

The Contact Form 7 Dynamic Text Extension’s shortcode ‘CF7_POST’ helps fetch data from form submissions. It extracts key-value pairs from form data, applies filters for sanitization, and returns the sanitized value. If the key doesn’t exist, it returns a default value. The ‘obfuscate’ attribute helps secure sensitive data.

Shortcode: [CF7_POST]

Parameters

Here is a list of all possible CF7_POST shortcode parameters and attributes:

  • key – Specifies the name of the POST variable to retrieve.
  • default – Value returned if the POST variable does not exist.
  • obfuscate – Determines if the returned value should be obfuscated.

Examples and Usage

Basic example – The shortcode ‘CF7_POST’ is used to retrieve a value from the $_POST array using the ‘key’ attribute. If the ‘key’ is not found, the ‘default’ value is returned.

[CF7_POST key="username" default="Guest"]

Advanced examples

Using the shortcode to retrieve a value from the $_POST array with the ‘key’ attribute and obfuscating the returned value if the ‘key’ is not found.

[CF7_POST key="password" default="******" obfuscate="true"]

Utilizing the shortcode to fetch a value from the $_POST array with ‘key’ attribute, providing a ‘default’ value, and no obfuscation.

[CF7_POST key="email" default="no-email@example.com" obfuscate="false"]

PHP Function Code

In case you have difficulties debugging what causing issues with [CF7_POST] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('CF7_POST', 'wpcf7dtx_post', 10, 1);

Shortcode PHP function:

function wpcf7dtx_post($atts = array())
{
    extract(shortcode_atts(array(
        'key' => '',
        'default' => '',
        'obfuscate' => ''
    ), array_change_key_case((array)$atts, CASE_LOWER)));
    $value = apply_filters('wpcf7dtx_sanitize', wpcf7dtx_array_has_key($key, $_POST, $default));
    return apply_filters('wpcf7dtx_escape', $value, $obfuscate);
}

Code file location:

contact-form-7-dynamic-text-extension/contact-form-7-dynamic-text-extension/includes/shortcodes.php

Contact Form 7 Dynamic Text Extension [CF7_URL] Shortcode

The ‘CF7_URL’ shortcode from the Contact Form 7 Dynamic Text Extension plugin retrieves the current URL. It can be customized to return specific parts of the URL or the entire URL. This shortcode is capable of handling multisite and single site installations. It also includes a sanitation process to ensure the URL is safe to use. You can specify URL components like scheme, host, path, or query to be returned.

Shortcode: [CF7_URL]

Parameters

Here is a list of all possible CF7_URL shortcode parameters and attributes:

  • allowed_protocols – specifies the protocols that are allowed for the URL
  • part – specifies the specific part of the URL to be returned
  • obfuscate – if set, it obscures the returned URL or its part

Examples and Usage

Basic example – A shortcode that fetches the current URL with no specific part requested.

[CF7_URL /]

Advanced examples

Using the shortcode to fetch the scheme part of the current URL. This will return the protocol used, such as ‘http’ or ‘https’.

[CF7_URL part="scheme" /]

Using the shortcode to fetch the domain or subdomain of the current website. This will return the host part of the URL.

[CF7_URL part="host" /]

Using the shortcode to fetch the path of the current page. This will return the path part of the URL, such as ‘/path/to/current/page/’.

[CF7_URL part="path" /]

Using the shortcode to fetch the query string of the current URL. This will return the query part of the URL, which is the string after the question mark ‘?’.

[CF7_URL part="query" /]

Using the shortcode with the ‘obfuscate’ attribute. This will return the current URL with the obfuscation applied. The obfuscation method depends on the value provided to the ‘obfuscate’ attribute.

[CF7_URL obfuscate="yes" /]

Using the shortcode with the ‘allowed_protocols’ attribute. This will return the current URL with only the protocols specified in the ‘allowed_protocols’ attribute. The protocols should be provided as a comma-separated list.

[CF7_URL allowed_protocols="http,https" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [CF7_URL] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('CF7_URL', 'wpcf7dtx_url', 10, 1);

Shortcode PHP function:

function wpcf7dtx_url($atts = array())
{
    extract(shortcode_atts(array(
        'allowed_protocols' => '',
        'part' => '',
        'obfuscate' => ''
    ), array_change_key_case((array)$atts, CASE_LOWER)));
    $allowed_protocols = explode(',', sanitize_text_field($allowed_protocols));

    // Get the absolute URL
    if (is_multisite() && !is_subdomain_install()) {
        // Network installs not using subdomains
        $url = apply_filters('wpcf7dtx_sanitize', network_home_url($_SERVER['REQUEST_URI']), 'url', $allowed_protocols);
    } else {
        // Single installs and network installs using subdomains
        $url = apply_filters('wpcf7dtx_sanitize', home_url($_SERVER['REQUEST_URI']), 'url', $allowed_protocols);
    }
    if ($url && !empty($part = sanitize_key(strtolower($part)))) {
        // If an individual part is requested, get that specific value using parse_url()
        $part_constant_map = [
            'scheme' => PHP_URL_SCHEME, // e.g. `http`
            'host'  => PHP_URL_HOST, // the domain (or subdomain) of the current website
            'path'  => PHP_URL_PATH, // e.g. `/path/to/current/page/`
            'query' => PHP_URL_QUERY // after the question mark ?
        ];
        $value = '';
        if (array_key_exists($part, $part_constant_map)) {
            $value = apply_filters('wpcf7dtx_sanitize', strval(wp_parse_url($url, $part_constant_map[$part])), 'text');
        }
        return apply_filters('wpcf7dtx_escape', $value, $obfuscate, 'text');
    }
    // No part requested, return the absolute URL
    return apply_filters('wpcf7dtx_escape', $url, $obfuscate, 'url', $allowed_protocols);
}

Code file location:

contact-form-7-dynamic-text-extension/contact-form-7-dynamic-text-extension/includes/shortcodes.php

Contact Form 7 Dynamic Text Extension [CF7_referrer] Shortcode

The Contact Form 7 Dynamic Text Extension shortcode ‘CF7_referrer’ is designed to fetch the referrer URL. It extracts the HTTP_REFERER from the server array and sanitizes it for use.

Shortcode: [CF7_referrer]

Parameters

Here is a list of all possible CF7_referrer shortcode parameters and attributes:

  • allowed_protocols – Specifies accepted URL protocols
  • obfuscate – Controls visibility of the URL to users

Examples and Usage

Basic example – A simple usage of the ‘CF7_referrer’ shortcode without any additional parameters.

[CF7_referrer /]

Advanced examples

Example 1: Utilizing the ‘allowed_protocols’ parameter. This allows you to specify the protocols that are permitted in the URL. For instance, you might only want to allow ‘https’ and ‘mailto’.

[CF7_referrer allowed_protocols="https, mailto" /]

Example 2: Implementing the ‘obfuscate’ parameter. This can be used to disguise the URL, which can be useful for enhancing security or privacy. You can set the ‘obfuscate’ parameter to ‘true’ to enable this feature.

[CF7_referrer obfuscate="true" /]

Example 3: Using both ‘allowed_protocols’ and ‘obfuscate’ parameters together. This example demonstrates how you can combine multiple parameters in a single shortcode to customize its behavior further.

[CF7_referrer allowed_protocols="https, mailto" obfuscate="true" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [CF7_referrer] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('CF7_referrer', 'wpcf7dtx_referrer', 10, 1);

Shortcode PHP function:

function wpcf7dtx_referrer($atts = array())
{
    extract(shortcode_atts(array(
        'allowed_protocols' => '',
        'obfuscate' => ''
    ), array_change_key_case((array)$atts, CASE_LOWER)));
    if ($value = wpcf7dtx_array_has_key('HTTP_REFERER', $_SERVER)) {
        $value = apply_filters('wpcf7dtx_sanitize', $value, 'url', $allowed_protocols);
        return apply_filters('wpcf7dtx_escape', $value, $obfuscate, 'url');
    }
    return '';
}

Code file location:

contact-form-7-dynamic-text-extension/contact-form-7-dynamic-text-extension/includes/shortcodes.php

Contact Form 7 Dynamic Text Extension [CF7_bloginfo] Shortcode

The CF7_bloginfo shortcode is part of the Contact Form 7 Dynamic Text Extension plugin. It fetches blog information based on a specified key. The function ‘wpcf7dtx_bloginfo’ takes an array of attributes, extracts them, and returns blog information. By default, it retrieves the blog’s ‘name’. It also allows for obfuscation.

Shortcode: [CF7_bloginfo]

Parameters

Here is a list of all possible CF7_bloginfo shortcode parameters and attributes:

  • show – Determines the type of site information to display
  • key – Defines the specific site information to retrieve
  • obfuscate – Controls whether to hide the returned site information or not

Examples and Usage

Basic example – A basic usage of the CF7_bloginfo shortcode. In this example, we are using the default attribute ‘name’ which will display the name of the blog.

[CF7_bloginfo]

Advanced examples

Example 1 – Display the blog’s description using the ‘key’ attribute. This will return the tagline or description set in the WordPress settings.

[CF7_bloginfo key=description]

Example 2 – Use the ‘obfuscate’ attribute to obfuscate the returned value. This might be useful if you want to display sensitive information like the admin email in a way that it’s not easily readable by bots.

[CF7_bloginfo key=admin_email obfuscate=yes]

Example 3 – Display the WordPress URL using the ‘key’ attribute. This will return the WordPress address (URL) set in the WordPress settings.

[CF7_bloginfo key=wpurl]

PHP Function Code

In case you have difficulties debugging what causing issues with [CF7_bloginfo] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('CF7_bloginfo', 'wpcf7dtx_bloginfo', 10, 1);

Shortcode PHP function:

function wpcf7dtx_bloginfo($atts = array())
{
    extract(shortcode_atts(array(
        'show' => 'name', //Backwards compatibility
        'key' => 'name',
        'obfuscate' => ''
    ), array_change_key_case((array)$atts, CASE_LOWER)));
    $key = $show != $key && $show != 'name' ? $show : $key; // Use old value of "show" if not set to default value
    return apply_filters('wpcf7dtx_escape', get_bloginfo($key), $obfuscate);
}

Code file location:

contact-form-7-dynamic-text-extension/contact-form-7-dynamic-text-extension/includes/shortcodes.php

Contact Form 7 Dynamic Text Extension [CF7_get_post_var] Shortcode

The Contact Form 7 Dynamic Text Extension shortcode is a powerful tool that retrieves post variables. This shortcode allows you to extract specific data from a post using the ‘key’ parameter. It supports various keys such as ‘acf_id’, ‘id’, ‘slug’, and ‘title’. The ‘post_id’ parameter lets you specify the post, and ‘obfuscate’ allows for data sanitization.

Shortcode: [CF7_get_post_var]

Parameters

Here is a list of all possible CF7_get_post_var shortcode parameters and attributes:

  • key – Determines which post field to return.
  • post_id – The ID of the post from which to retrieve data.
  • obfuscate – Option to obfuscate the returned post field data.
  • acf_id – Returns the post ID when requesting the handle for ACF.
  • id – Returns the ID of the post.
  • slug – Returns the post’s slug (post_name).
  • title – Returns the title of the post (post_title).

Examples and Usage

Basic example – Utilizes the shortcode to fetch the title of a specific post using its ID.

[CF7_get_post_var key="title" post_id="123" /]

Advanced examples

Fetching the post slug by providing the post ID. If the post with the given ID exists, it will return the slug of the post.

[CF7_get_post_var key="slug" post_id="456" /]

Obfuscating the returned value. If the post with the given ID exists, it will return the obfuscated post title.

[CF7_get_post_var key="title" post_id="789" obfuscate="yes" /]

Fetching the post ID using Advanced Custom Fields (ACF). If the post with the given ID exists, it will return the post ID.

[CF7_get_post_var key="acf_id" post_id="321" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [CF7_get_post_var] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('CF7_get_post_var', 'wpcf7dtx_get_post_var', 10, 1);

Shortcode PHP function:

function wpcf7dtx_get_post_var($atts = array())
{
    extract(shortcode_atts(array(
        'key' => 'post_title',
        'post_id' => '',
        'obfuscate' => ''
    ), array_change_key_case((array)$atts, CASE_LOWER)));
    $key = strtolower(apply_filters('wpcf7dtx_sanitize', $key));
    switch ($key) {
        case 'acf_id': // If requesting the handle for ACF, return the post ID
        case 'id':
            $key = 'ID';
            break;
        case 'slug': // Alias
            $key = 'post_name';
            break;
        case 'title': // Alias
            $key = 'post_title';
            break;
        default:
            break;
    }
    $post_id = wpcf7dtx_get_post_id($post_id);
    if ($post_id) {
        return apply_filters('wpcf7dtx_escape', get_post_field($key, $post_id), $obfuscate);
    }
    return '';
}

Code file location:

contact-form-7-dynamic-text-extension/contact-form-7-dynamic-text-extension/includes/shortcodes.php

Contact Form 7 Dynamic Text Extension [CF7_get_custom_field] Shortcode

The Contact Form 7 Dynamic Text Extension shortcode is designed to retrieve custom field data. It uses the ‘wpcf7dtx_get_custom_field’ function, which extracts attributes like ‘key’, ‘post_id’, and ‘obfuscate’. If a post ID and key are provided, it returns the corresponding post meta data. If not, it returns an empty string.

Shortcode: [CF7_get_custom_field]

Parameters

Here is a list of all possible CF7_get_custom_field shortcode parameters and attributes:

  • key – The custom field’s name for retrieving its value.
  • post_id – The ID of the post to get the custom field from.
  • obfuscate – Option to obscure the returned field value.

Examples and Usage

Basic example – The shortcode retrieves the value of a custom field associated with a post. In this example, the ‘key’ parameter corresponds to the custom field name and ‘post_id’ corresponds to the post’s ID.

[CF7_get_custom_field key="custom_field_name" post_id="123" /]

Advanced examples

In this advanced example, the shortcode retrieves the value of a custom field associated with a post and obfuscates the retrieved value. The ‘obfuscate’ parameter is set to ‘yes’ to enable obfuscation.

[CF7_get_custom_field key="custom_field_name" post_id="123" obfuscate="yes" /]

In another advanced example, the shortcode retrieves the value of a custom field without specifying the post’s ID. The plugin will attempt to fetch the post’s ID from the current page context. The ‘obfuscate’ parameter is set to ‘no’ to disable obfuscation.

[CF7_get_custom_field key="custom_field_name" obfuscate="no" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [CF7_get_custom_field] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('CF7_get_custom_field', 'wpcf7dtx_get_custom_field', 10, 1);

Shortcode PHP function:

function wpcf7dtx_get_custom_field($atts = array())
{
    extract(shortcode_atts(array(
        'key' => '',
        'post_id' => '',
        'obfuscate' => ''
    ), array_change_key_case((array)$atts, CASE_LOWER)));
    $post_id = wpcf7dtx_get_post_id($post_id);
    $key = apply_filters('wpcf7dtx_sanitize', $key, 'text');
    if ($post_id && $key) {
        return apply_filters('wpcf7dtx_escape', get_post_meta($post_id, $key, true), $obfuscate);
    }
    return '';
}

Code file location:

contact-form-7-dynamic-text-extension/contact-form-7-dynamic-text-extension/includes/shortcodes.php

Contact Form 7 Dynamic Text Extension [CF7_get_current_var] Shortcode

The Contact Form 7 Dynamic Text Extension shortcode retrieves various data depending on the current WordPress page. This data can include user, post, term, and archive details. It extracts key-value pairs from the attributes array and applies filters for sanitization. For user pages, it can fetch details like Advanced Custom Fields, profile image, display name, and slug. For post objects, it retrieves the featured image, assigned terms, post variables or post meta data. For taxonomy terms, it can return term ID, ACF handle, term name, or metadata. For archives, it fetches the archive title. The shortcode ensures data safety by escaping values before returning them.

Shortcode: [CF7_get_current_var]

Parameters

Here is a list of all possible CF7_get_current_var shortcode parameters and attributes:

  • key – Specifies the type of information to retrieve.
  • obfuscate – Used to obscure the output for security purposes.
  • url – Retrieves the current URL of the WordPress page.
  • acf_id – Retrieves the Advanced Custom Fields handle.
  • image – Retrieves the featured image or author’s profile picture.
  • title – Retrieves the title of the post, author’s display name, or term name.
  • slug – Retrieves the slug of the author page or the current path.
  • terms – Retrieves the assigned terms of the current post.
  • id – Retrieves the term ID when dealing with a taxonomy.

Examples and Usage

Basic example – The shortcode retrieves the current URL of the WordPress page.

[CF7_get_current_var key="url" /]

Advanced examples

Using the shortcode to retrieve the display name of the author of the current page.

[CF7_get_current_var key="title" /]

Using the shortcode to retrieve the featured image of the current post.

[CF7_get_current_var key="featured_image" /]

Using the shortcode to retrieve the ID of the current term in a taxonomy.

[CF7_get_current_var key="id" /]

Using the shortcode to retrieve the title of the current archive.

[CF7_get_current_var key="title" /]

Using the shortcode to retrieve the slug of the current page, useful for search or 404 pages.

[CF7_get_current_var key="slug" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [CF7_get_current_var] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('CF7_get_current_var', 'wpcf7dtx_get_current_var', 10, 1);

Shortcode PHP function:

function wpcf7dtx_get_current_var($atts = array())
{
    extract(shortcode_atts(array(
        'key' => 'title',
        'obfuscate' => ''
    ), array_change_key_case((array)$atts, CASE_LOWER)));
    $key = apply_filters('wpcf7dtx_sanitize', $key);
    $temp_key = str_replace('-', '_', sanitize_key($key));
    if ($temp_key === 'url') {
        return wpcf7dtx_url($atts); // Getting the current URL is the same for all WordPress pages
    } elseif (!empty($key)) {
        $type = '';
        $obj = null;
        if (!wp_doing_ajax()) {
            $obj = get_queried_object(); // Get the current WordPress queried object
            if (!is_null($obj)) {
                if ($obj instanceof WP_User) {
                    $type = 'user';
                } elseif (property_exists($obj, 'ID')) {
                    $type = 'post';
                } elseif (property_exists($obj, 'term_id')) {
                    $type = 'term';
                }
            } elseif (is_archive()) {
                $type = 'archive';
            }
        }
        switch ($type) {
            case 'user': // This is an author page
                switch ($temp_key) {
                    case 'acf_id': // Get handle for Advanced Custom Fields
                        return apply_filters('wpcf7dtx_escape', 'user_' . $obj->ID, $obfuscate);
                    case 'image':
                    case 'featured_image': // Get the profile picture of the user being displayed on the page
                        return apply_filters('wpcf7dtx_escape', get_avatar_url($obj->ID), $obfuscate, 'url');
                    case 'title': // Get author's display name
                        return apply_filters('wpcf7dtx_escape', $obj->display_name, $obfuscate);
                    case 'slug': // Not all author pages use the `user_login` variable for security reasons, so get what is currently displayed as slug
                        return apply_filters('wpcf7dtx_escape', basename(wpcf7dtx_url(array('part' => 'path'))), $obfuscate);
                    default: // Get user value by key should it exist
                        return apply_filters('wpcf7dtx_escape', $obj->get($key), $obfuscate);
                }
            case 'post': // This is a post object
                switch ($temp_key) {
                    case 'image':
                    case 'featured_image': // Get the current post's featured image
                        return wpcf7dtx_get_attachment(array_merge($atts, array('post_id' => $obj->ID)));
                    case 'terms': // Get the current post's assigned terms
                        return wpcf7dtx_get_taxonomy(array_merge($atts, array('post_id' => $obj->ID)));
                    default:
                        // Use the post object shortcode should it exist as a post variable
                        $value = wpcf7dtx_get_post_var(array_merge($atts, array('post_id' => $obj->ID)));
                        if (empty($value)) {
                            // Try post meta if post object variable failed
                            $value = wpcf7dtx_get_custom_field(array_merge($atts, array('post_id' => $obj->ID)));
                        }
                        return $value;
                }
            case 'term': // This is a taxonomy with a term ID
                switch ($key) {
                    case 'id': // Get term ID
                        return apply_filters('wpcf7dtx_escape', $obj->term_id, $obfuscate);
                    case 'acf_id': // Get handle for Advanced Custom Fields
                        return apply_filters('wpcf7dtx_escape', $obj->taxonomy . '_' . $obj->term_id, $obfuscate);
                    case 'title': // Get term name
                        return apply_filters('wpcf7dtx_escape', $obj->name, $obfuscate);
                    default:
                        if (property_exists($obj, $key)) {
                            // Get any property if it exists
                            return apply_filters('wpcf7dtx_escape', $obj->{$key}, $obfuscate);
                        }
                        // Otherwise, try meta data if the property doesn't exist
                        return apply_filters('wpcf7dtx_escape', get_metadata('term', $obj->ID, $key, true), $obfuscate);
                }
            case 'archive': // Possibly a date or formats archive
                switch ($temp_key) {
                    case 'title': // Get archive title
                        return apply_filters('wpcf7dtx_escape', get_the_archive_title(), $obfuscate);
                    default:
                        break;
                }
            default: // Possibly a search or 404 page at this point
                if ($temp_key == 'slug') {
                    // no idea what else to get except the slug maybe
                    return apply_filters('wpcf7dtx_escape', basename(wpcf7dtx_url(array('part' => 'path'))), $obfuscate);
                }
                break;
        }
    }
    return '';
}

Code file location:

contact-form-7-dynamic-text-extension/contact-form-7-dynamic-text-extension/includes/shortcodes.php

Contact Form 7 Dynamic Text Extension [CF7_get_current_user] Shortcode

The Contact Form 7 Dynamic Text Extension shortcode is a tool that retrieves the current user’s login details. This shortcode uses the ‘wpcf7dtx_get_current_user’ function to extract the user’s login key. If a user is logged in, it returns the user’s login details. If not, it returns an empty string.

Shortcode: [CF7_get_current_user]

Parameters

Here is a list of all possible CF7_get_current_user shortcode parameters and attributes:

  • key – Defines specific user data to retrieve, default is ‘user_login’
  • obfuscate – Optional, used to obscure the returned user data

Examples and Usage

Basic example – A simple usage of the shortcode to fetch the ‘user_login’ of the currently logged in user.

[CF7_get_current_user]

Advanced examples

Using the shortcode to fetch the ‘user_email’ of the currently logged in user.

[CF7_get_current_user key="user_email"]

Using the shortcode to fetch the ‘display_name’ of the currently logged in user and obfuscate it.

[CF7_get_current_user key="display_name" obfuscate="yes"]

Using the shortcode to fetch the ‘ID’ of the currently logged in user.

[CF7_get_current_user key="ID"]

Please note that the ‘key’ parameter corresponds to the user data you want to fetch. The ‘obfuscate’ parameter can be used to hide the user data, and it is optional. If you don’t provide any parameters, the shortcode will fetch the ‘user_login’ by default.

PHP Function Code

In case you have difficulties debugging what causing issues with [CF7_get_current_user] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('CF7_get_current_user', 'wpcf7dtx_get_current_user', 10, 1);

Shortcode PHP function:

function wpcf7dtx_get_current_user($atts = array())
{
    extract(shortcode_atts(array(
        'key' => 'user_login',
        'obfuscate' => ''
    ), array_change_key_case((array)$atts, CASE_LOWER)));
    if (is_user_logged_in()) {
        $user = wp_get_current_user();
        return apply_filters('wpcf7dtx_escape', $user->get($key), $obfuscate);
    }
    return '';
}

Code file location:

contact-form-7-dynamic-text-extension/contact-form-7-dynamic-text-extension/includes/shortcodes.php

Contact Form 7 Dynamic Text Extension [CF7_get_attachment] Shortcode

The CF7_get_attachment shortcode retrieves an attachment’s URL or ID based on the provided parameters. It can fetch attachments using either the attachment ID or post ID. It allows for size customization and has an obfuscate option for enhanced security. If an attachment ID isn’t given, it fetches the featured image from the provided post ID. Shortcode: [CF7_get_attachment id=”” size=”” post_id=”” return=”” obfuscate=””]

Shortcode: [CF7_get_attachment]

Parameters

Here is a list of all possible CF7_get_attachment shortcode parameters and attributes:

  • id – Unique identifier for the required attachment.
  • size – Determines the size of the attachment.
  • post_id – Identifier for the post if attachment ID is not provided.
  • return – Decides whether to return the attachment ID or URL.
  • obfuscate – Optional parameter to obfuscate the return value.

Examples and Usage

Basic example – The following shortcode retrieves the URL of an attachment using its ID.

[CF7_get_attachment id="123" /]

Advanced examples

1. This shortcode retrieves the URL of a featured image from a post using the post’s ID. If the post has no featured image, it will return an empty string.

[CF7_get_attachment post_id="456" /]

2. This shortcode retrieves the ID of an attachment instead of its URL. The ‘return’ attribute is set to ‘id’.

[CF7_get_attachment id="789" return="id" /]

3. This shortcode retrieves the URL of a thumbnail-sized attachment. The ‘size’ attribute is set to ‘thumbnail’.

[CF7_get_attachment id="321" size="thumbnail" /]

4. This shortcode retrieves the URL of a featured image from a post using the post’s ID and returns a medium-sized image. If the post has no featured image, it will return an empty string.

[CF7_get_attachment post_id="654" size="medium" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [CF7_get_attachment] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('CF7_get_attachment', 'wpcf7dtx_get_attachment', 10, 1);

Shortcode PHP function:

function wpcf7dtx_get_attachment($atts = array())
{
    extract(shortcode_atts(array(
        'id' => '', //Get attachment by ID
        'size' => 'full', //Define attachment size
        'post_id' => '', //If attachment ID is empty but post ID is not, get the featured image
        'return' => 'url', //Options are `id` or `url`
        'obfuscate' => ''
    ), array_change_key_case((array)$atts, CASE_LOWER)));

    //No attachment ID was provided, check for post ID to get it's featured image
    if (empty($id)) {
        if ($post_id = wpcf7dtx_get_post_id($post_id)) {
            //If a post ID was provided, get it's featured image
            $id = get_post_thumbnail_id($post_id);
        }
    }

    //Get the value
    if ($id) {
        $id = intval(sanitize_text_field(strval($id)));
        switch ($return) {
            case 'id': //Return the attachment ID
                return apply_filters('wpcf7dtx_escape', $id, $obfuscate);
            default: //Return attachment URL
                $url = wp_get_attachment_image_url(intval($id), sanitize_text_field(strval($size)));
                return apply_filters('wpcf7dtx_escape', $url, $obfuscate, 'url');
        }
    }
    return '';
}

Code file location:

contact-form-7-dynamic-text-extension/contact-form-7-dynamic-text-extension/includes/shortcodes.php

Contact Form 7 Dynamic Text Extension [CF7_get_cookie] Shortcode

The Contact Form 7 Dynamic Text Extension plugin shortcode ‘CF7_get_cookie’ retrieves cookie values. It uses the ‘wpcf7dtx_get_cookie’ function to extract the cookie data. This shortcode accepts three parameters: ‘key’, ‘default’, and ‘obfuscate’. The ‘key’ parameter specifies the cookie name, ‘default’ sets a fallback value if the cookie doesn’t exist, and ‘obfuscate’ can obscure the returned value.

Shortcode: [CF7_get_cookie]

Parameters

Here is a list of all possible CF7_get_cookie shortcode parameters and attributes:

  • key – Specifies the key name of the cookie to retrieve.
  • default – Default value returned if the cookie does not exist.
  • obfuscate – If set, the returned cookie value is obfuscated.

Examples and Usage

Basic Example – A simple usage of the shortcode to retrieve a cookie value by its key.

[CF7_get_cookie key="username"]

Advanced Examples

Using the shortcode to retrieve a cookie value by its key with a default value. If the cookie with the specified key doesn’t exist, it will return the default value.

[CF7_get_cookie key="username" default="Guest"]

Using the shortcode to retrieve a cookie value by its key and obfuscate the returned value. This is useful when you want to hide the actual value of the cookie for security reasons.

[CF7_get_cookie key="password" obfuscate="true"]

Using the shortcode to retrieve a cookie value by its key with a default value and obfuscate the returned value. This is a combination of the two previous examples.

[CF7_get_cookie key="password" default="unknown" obfuscate="true"]

PHP Function Code

In case you have difficulties debugging what causing issues with [CF7_get_cookie] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('CF7_get_cookie', 'wpcf7dtx_get_cookie', 10, 1);

Shortcode PHP function:

function wpcf7dtx_get_cookie($atts = array())
{
    extract(shortcode_atts(array(
        'key' => '',
        'default' => '',
        'obfuscate' => '' // Optionally obfuscate returned value
    ), array_change_key_case((array)$atts, CASE_LOWER)));
    $key = apply_filters('wpcf7dtx_sanitize', $key);
    $value = wpcf7dtx_array_has_key($key, $_COOKIE, $default);
    return apply_filters('wpcf7dtx_escape', $value, $obfuscate);
}

Code file location:

contact-form-7-dynamic-text-extension/contact-form-7-dynamic-text-extension/includes/shortcodes.php

Contact Form 7 Dynamic Text Extension [CF7_get_taxonomy] Shortcode

The Contact Form 7 Dynamic Text Extension plugin shortcode, ‘CF7_get_taxonomy’, retrieves taxonomy terms assigned to a specific post. It allows customization of the taxonomy type and the format of returned data.

Shortcode: [CF7_get_taxonomy]

Parameters

Here is a list of all possible CF7_get_taxonomy shortcode parameters and attributes:

  • post_id – Identifier of the post to get taxonomy from
  • taxonomy – Taxonomy type to retrieve, default is ‘category’
  • fields – What term data to return: ‘names’, ‘slugs’, or ‘ids’
  • obfuscate – Option to obfuscate returned value

Examples and Usage

Basic example – The shortcode retrieves the names of the categories associated with a specific post. Here, the post ID is ‘123’.

[CF7_get_taxonomy post_id=123]

Advanced examples

Retrieving the slugs of the tags associated with a specific post. In this case, the post ID is ‘123’ and the taxonomy is ‘post_tag’.

[CF7_get_taxonomy post_id=123 taxonomy='post_tag' fields='slugs']

Obfuscating the returned value of the shortcode. Here, the post ID is ‘123’, the taxonomy is ‘category’, and the fields are ‘names’.

[CF7_get_taxonomy post_id=123 taxonomy='category' fields='names' obfuscate='yes']

Retrieving the IDs of the categories associated with a specific post. Here, the post ID is ‘123’ and the fields are ‘ids’.

[CF7_get_taxonomy post_id=123 fields='ids']

PHP Function Code

In case you have difficulties debugging what causing issues with [CF7_get_taxonomy] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('CF7_get_taxonomy', 'wpcf7dtx_get_taxonomy', 10, 1);

Shortcode PHP function:

function wpcf7dtx_get_taxonomy($atts = array())
{
    extract(shortcode_atts(array(
        'post_id' => '',
        'taxonomy' => 'category', // Default taxonomy is `category`
        'fields' => 'names', // Return an array of term names
        'obfuscate' => '' // Optionally obfuscate returned value
    ), array_change_key_case((array)$atts, CASE_LOWER)));
    $post_id = wpcf7dtx_get_post_id($post_id);
    $fields = apply_filters('wpcf7dtx_sanitize', $fields, 'key');
    if ($post_id && in_array($fields, array('names', 'slugs', 'ids'))) {
        $terms = wp_get_object_terms(
            $post_id, // Get only the ones assigned to this post
            apply_filters('wpcf7dtx_sanitize', $taxonomy, 'slug'),
            array('fields' => $fields)
        );
        if (is_array($terms) && count($values = array_values($terms)) && (is_string($values[0]) || is_numeric($values[0]))) {
            return apply_filters('wpcf7dtx_escape', implode(', ', $values), $obfuscate, 'text');
        }
    }
    return '';
}

Code file location:

contact-form-7-dynamic-text-extension/contact-form-7-dynamic-text-extension/includes/shortcodes.php

Contact Form 7 Dynamic Text Extension [CF7_get_theme_option] Shortcode

The Contact Form 7 Dynamic Text Extension shortcode, ‘CF7_get_theme_option’, enables you to retrieve the value of a specific theme option. This shortcode takes in a ‘key’ parameter, which refers to the theme option’s name. An optional ‘default’ value can be provided, which is returned when the ‘key’ doesn’t exist. Another optional ‘obfuscate’ parameter allows you to hide the returned value.

Shortcode: [CF7_get_theme_option]

Parameters

Here is a list of all possible CF7_get_theme_option shortcode parameters and attributes:

  • key – The name of the theme option to retrieve.
  • default – Value returned if the theme option doesn’t exist.
  • obfuscate – If set, the returned value will be obfuscated.

Examples and Usage

Basic Example – A shortcode that fetches a theme option using the key parameter. If the key is not found, it returns an empty string.

[CF7_get_theme_option key="color_scheme" /]

Advanced Examples

Using the shortcode to fetch a theme option with a default value. If the key is not found, it will return the default value specified.

[CF7_get_theme_option key="color_scheme" default="blue" /]

Using the shortcode to fetch a theme option with obfuscation. If the key is found, the returned value will be obfuscated.

[CF7_get_theme_option key="color_scheme" obfuscate="yes" /]

Using the shortcode to fetch a theme option with both a default value and obfuscation. If the key is not found, the default value will be returned and obfuscated if the obfuscate parameter is set to “yes”.

[CF7_get_theme_option key="color_scheme" default="blue" obfuscate="yes" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [CF7_get_theme_option] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('CF7_get_theme_option', 'wpcf7dtx_get_theme_option', 10, 1);

Shortcode PHP function:

function wpcf7dtx_get_theme_option($atts = array())
{
    extract(shortcode_atts(array(
        'key' => '',
        'default' => '', // Optional default value
        'obfuscate' => '' // Optionally obfuscate returned value
    ), array_change_key_case((array)$atts, CASE_LOWER)));
    if ($key = apply_filters('wpcf7dtx_sanitize', $key, 'text')) {
        $default = apply_filters('wpcf7dtx_sanitize', $default);
        return apply_filters('wpcf7dtx_escape', get_theme_mod($key, $default), $obfuscate);
    }
    return '';
}

Code file location:

contact-form-7-dynamic-text-extension/contact-form-7-dynamic-text-extension/includes/shortcodes.php

Contact Form 7 Dynamic Text Extension [CF7_guid] Shortcode

The Contact Form 7 Dynamic Text Extension plugin’s shortcode ‘CF7_guid’ is used to generate a globally unique identifier (GUID). This shortcode calls the ‘wpcf7dtx_guid’ function which checks if the ‘com_create_guid’ function exists. If it does, it creates a GUID and returns it after removing curly braces. If the ‘com_create_guid’ function doesn’t exist, it creates a GUID using the ‘mt_rand’ function and returns it.

Shortcode: [CF7_guid]

Examples and Usage

Basic example – A simple implementation of the shortcode without any parameters. This will generate a unique GUID each time it’s called.

[CF7_guid /]

Advanced examples

Even though the ‘CF7_guid’ shortcode does not accept any parameters, we can still use it in conjunction with other shortcodes or within content to create more complex structures. Here are a couple of examples:

Using the ‘CF7_guid’ shortcode to generate a unique identifier within a Contact Form 7 form. This could be useful for tracking submissions or creating unique identifiers for each form submission.

[contact-form-7 id="123" title="Contact form 1" guid="[CF7_guid /]"]

Using the ‘CF7_guid’ shortcode within a post to create a unique identifier. This could be useful for creating unique links or identifiers within your content.

<p>Your unique identifier is: [CF7_guid /]</p>

PHP Function Code

In case you have difficulties debugging what causing issues with [CF7_guid] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('CF7_guid', 'wpcf7dtx_guid', 10, 0);

Shortcode PHP function:

function wpcf7dtx_guid()
{
    if (function_exists('com_create_guid') === true) {
        return esc_attr(trim(com_create_guid(), '{}'));
    }
    return esc_attr(sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535)));
}

Code file location:

contact-form-7-dynamic-text-extension/contact-form-7-dynamic-text-extension/includes/shortcodes.php

Conclusion

Now that you’ve learned how to embed the Contact Form 7 – Dynamic Text Extension Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *