├── assets └── recaptcha.png ├── fields └── recaptcha │ ├── preview.php │ ├── config.php │ └── field.php ├── caldera-forms-anti-spam.php ├── readme.txt └── classes └── recapatcha.php /assets/recaptcha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrewlimaza/caldera-forms-anti-spam/HEAD/assets/recaptcha.png -------------------------------------------------------------------------------- /fields/recaptcha/preview.php: -------------------------------------------------------------------------------- 1 | {{#if config/public_key}} 2 | {{#if config/private_key}} 3 |
4 | reCaptcha Logo 5 | {{#if config/recapv}} 6 | () 7 | {{else}} 8 | {{#if config/invis}} (){{/if}} 9 | {{/if}} 10 |
11 | 12 | {{#script}} 13 | 14 | jQuery(document).ready( function(){ 15 | if( typeof grecaptcha === 'object' ){ 16 | 17 | var captch = jQuery('#cap{{id}}'); 18 | 19 | grecaptcha.render( captch[0], { 20 | "sitekey" : "{{config/public_key}}", 21 | "theme" : "{{config/theme}}" 22 | }); 23 | } 24 | }); 25 | 26 | {{/script}} 27 | {{else}} 28 |

29 | {{/if}} 30 | {{else}} 31 |

32 | {{/if}} 33 | -------------------------------------------------------------------------------- /caldera-forms-anti-spam.php: -------------------------------------------------------------------------------- 1 | 2 | 3 |

4 | Visit reCAPTCHA 5 |

6 | 7 |
8 | 11 |
12 | 13 |
14 |
15 | 16 | {{#if recapv}} 17 |
18 |

19 | 20 |

21 | {{else}} 22 |
23 | 26 |
27 | 28 | 29 |
30 |
31 | {{/if}} 32 | 33 |
34 | 37 |
38 | 39 |
40 |
41 | 42 |
43 | 46 |
47 | 48 |
49 |
50 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | ** THIS IS NO LONGER SUPPORTED AS CALDERA FORMS NO LONGER IS SUPPORTED - I HIGHLY RECOMMEND SWITCHING FORM WORDPRESS PLUGINS IF YOU WANT A RECAPTCHA SOLUTION ** 2 | 3 | === Caldera Forms Anti Spam === 4 | Contributors: andrewza, yoohooplugins, travislima 5 | Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4GC4JEZH7KSKL 6 | Tags: caldera forms, anti-spam, recaptcha 7 | Requires at least: 4.5 8 | Tested up to: 5.6 9 | Stable tag: 0.4 10 | License: GPLv2 or later 11 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 12 | 13 | Anti-spam for Caldera Forms. reCAPTCHA and more. 14 | == Description == 15 | 16 | Anti-spam for [Caldera Forms](https://calderaforms.com) 17 | 18 | = Adds A Google reCaptcha Field To Caldera Forms = 19 | 20 | * Go to [reCAPTCHA Site](https://www.google.com/recaptcha) and click "Get reCpatcha" button. 21 | * In "Register a new site" choose reCAPTCHA v2,v3 or Invisible reCAPTCHA. 22 | * Add your domains and complete form. 23 | * This will show you your new public and secret key. 24 | * On your WordPress site, go to the Caldera Forms editor for form you wish to add a the captcha to. 25 | * Drag "Add Field" bar into the form layout where you want the captcha to appear. 26 | * In field settings enter public and secret keys. 27 | 28 | 29 | == Installation == 30 | 1. Upload the plugin files to the '/wp-content/plugins' directory, or install the plugin through the WordPress plugins screen directly. 31 | 2. Activate the plugin through the 'Plugins' screen in WordPress. 32 | 3. Go to the Caldera Forms editor for form you wish to add a the captcha to. 33 | 4. Drag "Add Field" bar into the form layout where you want the captcha to appear. 34 | 5. In field settings enter public and secret keys. 35 | 36 | 37 | == Frequently Asked Questions == 38 | = Does This Provide A Google reCAPTCHA v3 Field For Caldera Forms = 39 | Yes, this will add a Google reCAPTCHA-powered captcha to your Caldera Form. 40 | 41 | = Does This Support V2 and Invisible reCAPTCHA = 42 | Yes, this supports 'legacy' versions of reCaptcha for Caldera Forms. 43 | 44 | = How Do I Enable V2 reCAPTCHA = 45 | Add the hidden field to your Caldera Form and do not select V3 or Invisible reCAPTCHA checkboxes. 46 | 47 | = How Do I Enable V3 reCAPTCHA = 48 | Once the hidden field is added to your Caldera Form, select the V3 checkbox. (You do not need to select the Invisible reCaptcha option if you have selected this setting). 49 | 50 | 51 | == Screenshots == 52 | 53 | 54 | == Changelog == 55 | 56 | = 0.4 - 2021-01-19 = 57 | * BUG FIX: Fixed an issue where reCAPTCHA wasn't initialized correctly - fixes issues on WordPress 5.5+. Thanks @jarryd-long 58 | 59 | = 0.3 = 60 | * Fixed JavaScript syntax issues within the V3 reCAPTCHA handler 61 | * Fixed bug where V2 reCAPTCHA field would still be rendered when V3 is enabled 62 | 63 | = 0.2 = 64 | * Added invisible reCAPTCHA support and option 65 | * Added reCAPTCHA v3 support and option 66 | * Changed script loader to support both V2 and V3 reCAPTCHA 67 | * Improved JavaScript to better support V2 and V3 reCAPTCHA 68 | * Removed reCAPTCHA field output from email summary 69 | 70 | = 0.1.1 = 71 | * Allow more than one recaptcha per page. 72 | 73 | = 0.1.0 = 74 | * First release 75 | 76 | == Upgrade Notice == 77 | 78 | = 0.4 = 79 | * Please upgrade to get compatibility changes for WordPress 5.5+ 80 | 81 | = 0.2 = 82 | * Please upgrade to support V3 recaptcha and more. 83 | 84 | = 0.1.1 = 85 | * Please upgrade for enhancements. 86 | 87 | = 0.1.0 = 88 | *First Release 89 | -------------------------------------------------------------------------------- /fields/recaptcha/field.php: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | '; 16 | echo $field_caption; 17 | echo ''; 18 | } 19 | 20 | if( empty( $field['config']['public_key'] ) ){ 21 | $field['config']['public_key'] = null; 22 | } 23 | 24 | /** 25 | We have moved the enqueue here as this allows us to alter the URL on the fly 26 | */ 27 | $language = get_locale(); 28 | $script_url = "https://www.google.com/recaptcha/api.js?onload=cf_recaptcha_is_ready&render=explicit&hl=" . $language; 29 | if (!empty($field['config']['recapv']) && $field['config']['recapv'] === 1 ) { 30 | $script_url = "https://www.google.com/recaptcha/api.js?onload=cf_recaptcha_is_ready&render=" . trim($field['config']['public_key']) . "&hl=" . $language; 31 | } 32 | // wp_enqueue_script('cf-anti-spam-recapthca-lib', $script_url); 33 | 34 | ?> 35 | 36 | 37 | 38 | 39 | 40 | 41 |
42 | 43 |
data-size="invisible" >
44 | 45 | 46 | 54 | 55 | 56 | 57 | 58 | 59 | 63 | 64 | 100 | 101 | __( 'reCAPTCHA', 'cf-anti-spam' ), 18 | "description" => __( 'reCAPTCHA anti-spam field', 'cf-anti-spam' ), 19 | "file" => CF_ANTISPAM_PATH . "fields/recaptcha/field.php", 20 | "category" => __( 'Special', 'cf-anti-spam' ), 21 | "handler" => array( $this, 'handler' ), 22 | "capture" => false, 23 | "setup" => array( 24 | "template" => CF_ANTISPAM_PATH . "fields/recaptcha/config.php", 25 | "preview" => CF_ANTISPAM_PATH . "fields/recaptcha/preview.php", 26 | "not_supported" => array( 27 | 'caption', 28 | 'required' 29 | ), 30 | ), 31 | /*"scripts" => array( 'https://www.google.com/recaptcha/api.js?onload=cf_recaptcha_is_ready&render=explicit&hl=' . $language )*/ 32 | ); 33 | 34 | return $fields; 35 | } 36 | 37 | /** 38 | * Remove the recaptcha field type from the summary email using the caldera hook 39 | * 40 | * @since 0.2 41 | * 42 | * @uses "caldera_forms_summary_magic_fields" filter 43 | * 44 | * @param array $fields Fields in form submission 45 | * @param object $form Form object from caldera 46 | * 47 | * @return array 48 | */ 49 | public function remove_from_summary( $fields, $form ){ 50 | if(!empty($fields)){ 51 | foreach($fields as $field_id => $field){ 52 | $type = Caldera_Forms_Field_Util::get_type($field, $form); 53 | if($type === 'recaptcha'){ 54 | unset($fields[$field_id]); 55 | } 56 | } 57 | } 58 | 59 | return $fields; 60 | } 61 | 62 | /** 63 | * Modify field attributes so recpatcha field has type "hidden" not "recpatcha" 64 | * 65 | * @since 0.1.0 66 | * 67 | * @uses "caldera_forms_field_attributes-recaptcha" filter 68 | * 69 | * @param $attrs 70 | * @param $form 71 | * 72 | * @return array 73 | */ 74 | public function field_attrs( $attrs, $form ){ 75 | $attrs[ 'type' ] = 'hidden'; 76 | return $attrs; 77 | } 78 | /** 79 | * Check that the recaptcha response is sent on forms that have a recapthca field. 80 | * 81 | * @since 0.1.0 82 | * 83 | * @uses "caldera_forms_validate_field_recaptcha" 84 | * 85 | * @param $entry 86 | * @param $field 87 | * @param $form 88 | * 89 | * @return WP_Error|boolean 90 | */ 91 | public function check_for_captcha( $entry, $field, $form ){ 92 | if ( ! isset( $_POST[ 'g-recaptcha-response' ] ) || empty( $_POST[ 'g-recaptcha-response' ] ) ) { 93 | return new WP_Error( 'error' ); 94 | } 95 | return true; 96 | } 97 | /** 98 | * Field handler -- checks for recaptcha and verifies it if possible 99 | * 100 | * @since 0.1.0 101 | * 102 | * @param string $value Field value, should be empty 103 | * @param array $field Field config 104 | * @param array $form Form config 105 | * 106 | * @return WP_Error|boolean 107 | */ 108 | public function handler( $value, $field, $form ){ 109 | 110 | //JS didn't load to generate a token for the recaptcha. Let the form submit without error. 111 | if( $_POST[ 'g-recaptcha-response' ] === 'ready' ){ 112 | //Workaround for JS issues in Caldera. We know JS has loaded, but reCAPTCHA faile. 113 | return true; 114 | } 115 | 116 | /** 117 | * Check if this is V3, then we grab the dynamically generated field value 118 | */ 119 | if (!empty($field['config']['recapv']) && $field['config']['recapv'] === 1 ) { 120 | if(!empty($_POST['cf-recapv-token'])){ 121 | $_POST[ 'g-recaptcha-response' ] = $_POST['cf-recapv-token']; 122 | } 123 | } 124 | 125 | if ( ! isset( $_POST[ 'g-recaptcha-response' ] ) || empty( $_POST[ 'g-recaptcha-response' ] ) ) { 126 | return new WP_Error( 'error' ); 127 | } 128 | $args = array( 129 | 'secret' => $field[ 'config' ][ 'private_key' ], 130 | 'response' => sanitize_text_field( $_POST[ 'g-recaptcha-response' ] ) 131 | ); 132 | $request = wp_remote_get( add_query_arg( $args, 'https://www.google.com/recaptcha/api/siteverify' ) ); 133 | $result = json_decode( wp_remote_retrieve_body( $request ) ); 134 | if ( empty( $result->success ) ) { 135 | return new WP_Error( 'error', 136 | __( "The captcha wasn't entered correctly.", 'cf-anti-spam' ) . ' ' . __( 'Reset', 'cf-anti-spam' ) . '.' 137 | ); 138 | } 139 | return true; 140 | } 141 | } --------------------------------------------------------------------------------