Cleantalk Spam Protect Shortcodes

Below, you’ll find a detailed guide on how to add the Cleantalk Spam Protect 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 Cleantalk Spam Protect Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Cleantalk Spam Protect Plugin and the shortcodes it provides:

Plugin Icon
Spam protection, AntiSpam, FireWall by CleanTalk, Anti-Spam

"Spam protection, AntiSpam, FireWall by CleanTalk, Anti-Spam is an essential plugin for WordPress. It offers robust spam protection, firewall capabilities, and anti-spam features to keep your site secure."

★★★★☆ (2742) Active Installs: 200000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [et_pb_contact_form]
  • [cleantalk_affiliate_link]

Cleantalk Spam Protect [et_pb_contact_form] Shortcode

The Cleantalk-spam-protect plugin shortcode is designed to validate contact forms and protect them from spam. It checks for XML-RPC requests, REST API requests, and WooCommerce actions. It skips anti-spam tests for logged-in users and certain system fields for Divi. It also handles various contact form submissions and responses based on the result of the anti-spam check.

Shortcode: [et_pb_contact_form]

Examples and Usage

Basic example – Displaying a contact form using the shortcode

[et_pb_contact_form /]

Advanced examples

Using the shortcode to display a contact form and validate it with the CleanTalk anti-spam plugin. This will ensure that the form is protected against spam submissions.

[et_pb_contact_form ct_contact_form_validate /]

Using the shortcode to display a contact form and validate it with the CleanTalk anti-spam plugin, while also excluding certain requests. This allows for more control over which requests are validated.

[et_pb_contact_form ct_contact_form_validate exclude="XMLRPC_REQUEST, REST_API_REQUEST" /]

Using the shortcode to display a contact form, validate it with the CleanTalk anti-spam plugin, and skip validation for logged in users. This can be useful if you want to allow logged in users to submit the form without validation.

[et_pb_contact_form ct_contact_form_validate skip_for_logged_in_users="true" /]

PHP Function Code

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

Shortcode line:

add_shortcode('et_pb_contact_form', 'ct_contact_form_validate');

Shortcode PHP function:

function ct_contact_form_validate()
{
    global $apbct, $ct_comment;

    // Exclude the XML-RPC requests
    if ( defined('XMLRPC_REQUEST') ) {
        do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
        return null;
    }

    // Exclusios common function
    if ( apbct_exclusions_check(__FUNCTION__) ) {
        do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
        return null;
    }

    $do_skip = skip_for_ct_contact_form_validate();
    if ( $do_skip ) {
        do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__ . ', ON KEY ' . $do_skip, $_POST);
        return null;
    }

    // Skip REST API requests
    if ( Server::isPost() && Server::inUri('rest_route') ) {
        do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);

        return null;
    }

    //Skip woocommerce checkout
    if ( apbct_is_in_uri('wc-ajax=update_order_review') ||
         apbct_is_in_uri('wc-ajax=checkout') ||
         ! empty($_POST['woocommerce_checkout_place_order']) ||
         apbct_is_in_uri('wc-ajax=wc_ppec_start_checkout') ||
         apbct_is_in_referer('wc-ajax=update_order_review')
    ) {
        do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);

        return null;
    }

    //Skip woocommerce add_to_cart
    if ( ! empty($_POST['add-to-cart']) ) {
        do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);

        return null;
    }

    // Do not execute anti-spam test for logged in users.
    if ( defined('LOGGED_IN_COOKIE') && isset($_COOKIE[LOGGED_IN_COOKIE]) && $apbct->settings['data__protect_logged_in'] != 1 ) {
        do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);

        return null;
    }
    //Skip WP Fusion web hooks
    if ( apbct_is_in_uri('wpf_action') && apbct_is_in_uri('access_key') && isset($_GET['access_key']) ) {
        if ( function_exists('wp_fusion') ) {
            $key = wp_fusion()->settings->get('access_key');
            if ( $key === $_GET['access_key'] ) {
                do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);

                return null;
            }
        }
    }
    //Skip system fields for divi
    if ( strpos(Post::get('action'), 'et_pb_contactform_submit') === 0 ) {
        foreach ( array_keys($_POST) as $key ) {
            if ( strpos((string)$key, 'et_pb_contact_email_fields') === 0 ) {
                unset($_POST[$key]);
            }
        }
    }

    if ( apbct_is_skip_request(false) ) {
        do_action(
            'apbct_skipped_request',
            __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__ . '(' . apbct_is_skip_request() . ')',
            $_POST
        );

        return false;
    }

    // Skip CalculatedFieldsForm
    if (
        apbct_is_plugin_active('calculated-fields-form/cp_calculatedfieldsf.php') ||
        apbct_is_plugin_active('calculated-fields-form/cp_calculatedfieldsf_free.php')
    ) {
        foreach ( array_keys($_POST) as $key ) {
            if ( strpos((string)$key, 'calculatedfields') !== false ) {
                do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);

                return null;
            }
        }
    }

    $post_info['comment_type'] = 'feedback_general_contact_form';

    /**
     * Filter for POST
     */
    $input_array = apply_filters('apbct__filter_post', $_POST);

    $ct_temp_msg_data = ct_get_fields_any($input_array);

    $sender_email    = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
    $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
    $subject         = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
    $contact_form    = $ct_temp_msg_data['contact']; // Psalm: Operand of type false is always false
    $message         = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
    if ( $subject != '' ) {
        $message = array_merge(array('subject' => $subject), $message);
    }

    // Skip submission if no data found
    if ( ! $contact_form ) {
        do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);

        return false;
    }

    if ( isset($_POST['TellAFriend_Link']) ) {
        $tmp = Sanitize::cleanTextField(Post::get('TellAFriend_Link'));
        unset($_POST['TellAFriend_Link']);
    }

    $base_call_result = apbct_base_call(
        array(
            'message'         => $message,
            'sender_email'    => $sender_email,
            'sender_nickname' => $sender_nickname,
            'post_info'       => $post_info,
            'sender_info'     => array('sender_email' => urlencode($sender_email)),
        )
    );

    if ( isset($_POST['TellAFriend_Link']) ) {
        $_POST['TellAFriend_Link'] = $tmp;
    }

    $ct_result = $base_call_result['ct_result'];

    // Remove visible fields from POST
    foreach ($_POST as $key => $_value) {
        if (stripos((string)$key, 'apbct_visible_fields') === 0) {
            unset($_POST[$key]);
        }
    }

    if ( $ct_result->allow == 0 ) {
        // Recognize contact form an set it's name to $contact_form to use later
        $contact_form = null;
        foreach ( array_keys($_POST) as $param ) {
            if ( strpos((string)$param, 'et_pb_contactform_submit') === 0 ) {
                $contact_form            = 'contact_form_divi_theme';
                $contact_form_additional = str_replace('et_pb_contactform_submit', '', (string)$param);
            }
            if ( strpos((string)$param, 'avia_generated_form') === 0 ) {
                $contact_form            = 'contact_form_enfold_theme';
                $contact_form_additional = str_replace('avia_generated_form', '', (string)$param);
            }
            if ( ! empty($contact_form) ) {
                break;
            }
        }

        $ajax_call = false;
        if ( (defined('DOING_AJAX') && DOING_AJAX)
        ) {
            $ajax_call = true;
        }
        if ( $ajax_call ) {
            echo wp_kses(
                $ct_result->comment,
                array(
                    'a' => array(
                        'href'  => true,
                        'title' => true,
                    ),
                    'br'     => array(),
                    'p'     => array()
                )
            );
        } else {
            $ct_comment = $ct_result->comment;
            if ( isset($_POST['cma-action']) && $_POST['cma-action'] == 'add' ) {
                $result = array('success' => 0, 'thread_id' => null, 'messages' => array($ct_result->comment));
                header("Content-Type: application/json");
                print json_encode($result);
                die();
            } elseif ( isset($_POST['TellAFriend_email']) ) {
                echo wp_kses(
                    $ct_result->comment,
                    array(
                        'a' => array(
                            'href'  => true,
                            'title' => true,
                        ),
                        'br'     => array(),
                        'p'     => array()
                    )
                );
                die();
            } elseif ( isset($_POST['vfb-submit']) && defined('VFB_VERSION') ) {
                wp_die(
                    "<h1>" . __(
                        'Spam protection by CleanTalk',
                        'cleantalk-spam-protect'
                    ) . "</h1><h2>" . $ct_result->comment . "</h2>",
                    '',
                    array('response' => 403, "back_link" => true, "text_direction" => 'ltr')
                );
                // Caldera Contact Forms
            } elseif ( isset($_POST['action']) && $_POST['action'] == 'cf_process_ajax_submit' ) {
                print "<h3 style='color: red;'><red>" . $ct_result->comment . "</red></h3>";
                die();
                // Mailster
            } elseif ( isset($_POST['_referer'], $_POST['formid'], $_POST['email']) ) {
                $return = array(
                    'success' => false,
                    'html'    => '<p>' . $ct_result->comment . '</p>',
                );
                print json_encode($return);
                die();
                // Divi Theme Contact Form. Using $contact_form
            } elseif ( ! empty($contact_form) && $contact_form == 'contact_form_divi_theme' ) {
                echo wp_kses(
                    "<div id='et_pb_contact_form{$contact_form_additional}'><h1>Your request looks like spam.</h1><div><p>{$ct_result->comment}</p></div></div>",
                    array(
                        'a' => array(
                            'href'  => true,
                            'title' => true,
                        ),
                        'br'     => array(),
                        'p'     => array(),
                        'div' => array(
                            'id' => true,
                        ),
                        'h1' => array(),
                    )
                );
                die();
                // Enfold Theme Contact Form. Using $contact_form
            } elseif ( ! empty($contact_form) && $contact_form == 'contact_form_enfold_theme' ) {
                $echo_string = "<div id='ajaxresponse_1' class='ajaxresponse ajaxresponse_1' style='display: block;'><div id='ajaxresponse_1' class='ajaxresponse ajaxresponse_1'><h3 class='avia-form-success'>' . $apbct->data['wl_brandname'] . ': " . $ct_result->comment . "</h3><a href='.'><-Back</a></div></div>";
                echo wp_kses(
                    $echo_string,
                    array(
                        'a'   => array(
                            'href'  => true,
                            'title' => true,
                        ),
                        'br'  => array(),
                        'p'   => array(),
                        'div' => array(
                            'id'    => true,
                            'class' => true,
                            'style' => true
                        ),
                        'h3'  => array(),
                    )
                );
                die();
            } elseif (
                (int)$apbct->settings['forms__check_internal'] === 1
                && !empty($_POST)
                && apbct_is_ajax()
                && Post::equal('sib_form_action', 'subscribe_form_submit')
                && apbct_is_plugin_active('mailin/sendinblue.php')
            ) {
                wp_send_json(
                    array(
                        'status' => 'failure',
                        'msg' => array(
                            "errorMsg" => wp_kses(
                                $ct_result->comment,
                                array(
                                    'a' => array(
                                        'href'  => true,
                                        'title' => true,
                                    ),
                                    'br'     => array(),
                                    'p'     => array(),
                                    'div' => array(
                                        'id' => true,
                                    ),
                                    'h1' => array(),
                                )
                            )
                        ),
                    )
                );
            } elseif (
                ! empty(Post::get('_mc4wp_form_id')) &&
                apbct_is_plugin_active('mailchimp-for-wp/mailchimp-for-wp.php')
            ) {
                add_filter('mc4wp_form_messages', 'ct_add_mc4wp_error_message');
            } else {
                ct_die(null, null);
            }
        }
        exit;
    }

    return null;
}

Code file location:

cleantalk-spam-protect/cleantalk-spam-protect/inc/cleantalk-public.php

Cleantalk Spam Protect [cleantalk_affiliate_link] Shortcode

The Cleantalk-spam-protect plugin shortcode, ‘cleantalk_affiliate_link’, generates a trusted text HTML within a ‘span’ tag. This shortcode is useful for creating affiliate links in your content.

Shortcode: [cleantalk_affiliate_link]

Examples and Usage

Basic example – The shortcode ‘cleantalk_affiliate_link’ is used to generate trusted text in HTML format. It requires no parameters.

[cleantalk_affiliate_link]

Advanced examples

While the ‘cleantalk_affiliate_link’ shortcode does not natively accept parameters, it is possible to modify the associated function to accept and use parameters. For instance, you could modify the function to accept a ‘class’ parameter, which adds the given class to the generated HTML element.

Here’s how you might modify the function:


function apbct_trusted_text_shortcode_handler($atts)
{
    $atts = shortcode_atts(
        array(
            'class' => 'default-class',
        ), $atts, 'cleantalk_affiliate_link');

    return apbct_generate_trusted_text_html('span', $atts['class']);
}

With this modified function, you can use the ‘cleantalk_affiliate_link’ shortcode with a ‘class’ parameter like this:

[cleantalk_affiliate_link class="custom-class"]

This will generate a ‘span’ element with the class ‘custom-class’ and the trusted text inside.

PHP Function Code

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

Shortcode line:

add_shortcode('cleantalk_affiliate_link', 'apbct_trusted_text_shortcode_handler');

Shortcode PHP function:

function apbct_trusted_text_shortcode_handler()
{
    return apbct_generate_trusted_text_html('span');
}

Code file location:

cleantalk-spam-protect/cleantalk-spam-protect/inc/cleantalk-public.php

Conclusion

Now that you’ve learned how to embed the Cleantalk Spam Protect 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 *