-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #20 Formidable: Add original code from @slimco into modules subfolder Source: slimco/formidable-field-frcaptcha@ebd0971 Permission was granted here: slimco/formidable-field-frcaptcha#2 (comment) * #20 Formidable: Integrate * Remove custom style * Add own configuration option for Formidable * Remove outdated readme
- Loading branch information
Showing
7 changed files
with
228 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
friendly-captcha/modules/formidable/FrcaptchaFieldNewType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
|
||
class FrcaptchaFieldNewType extends FrmFieldType { | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $type = 'frcaptcha'; | ||
|
||
/** | ||
* Set to false if a normal input field should not be displayed. | ||
* @var bool | ||
*/ | ||
protected $has_input = true; | ||
|
||
/** | ||
* Which Formidable settings should be hidden or displayed? | ||
*/ | ||
protected function field_settings_for_type() { | ||
$settings = parent::field_settings_for_type(); | ||
$settings['default'] = true; | ||
|
||
return $settings; | ||
} | ||
|
||
/** | ||
* Need custom options too? Add them here or remove this function. | ||
*/ | ||
protected function extra_field_opts() { | ||
return array( | ||
// name => default, | ||
); | ||
} | ||
|
||
protected function include_form_builder_file() { | ||
return dirname( __FILE__ ) . '/builder-field.php'; | ||
} | ||
|
||
/** | ||
* Get the type of field being displayed. This is required to add a settings | ||
* section just for this field. show_extra_field_choices will not be triggered | ||
* without it. | ||
* | ||
* @return array | ||
*/ | ||
public function displayed_field_type( $field ) { | ||
return array( | ||
$this->type => true, | ||
); | ||
} | ||
|
||
/** | ||
* Add settings in the builder here. | ||
*/ | ||
public function show_extra_field_choices( $args ) { | ||
$field = $args['field']; | ||
include( dirname( __FILE__ ) . '/builder-settings.php' ); | ||
} | ||
|
||
protected function html5_input_type() { | ||
return 'text'; | ||
} | ||
|
||
/** | ||
* @return array|null If there is an error, return an array. | ||
*/ | ||
public function validate( $args ) { | ||
|
||
$plugin = FriendlyCaptcha_Plugin::$instance; | ||
if (!$plugin->is_configured() or !$plugin->get_formidable_active()) { | ||
return array( 'field' . $args['id'] => __('FriendlyCaptcha_Plugin is missing') ); | ||
} | ||
|
||
$errorPrefix = '<strong>' . __( 'Error', 'wp-captcha' ) . '</strong> : '; | ||
$solution = frcaptcha_get_sanitized_frcaptcha_solution_from_post(); | ||
|
||
$errors = array(); | ||
|
||
if ( empty( $solution ) ) { | ||
$errors[ 'field' . $args['id'] ] = $errorPrefix . FriendlyCaptcha_Plugin::default_error_user_message(); | ||
} | ||
|
||
$verification = frcaptcha_verify_captcha_solution($solution, $plugin->get_sitekey(), $plugin->get_api_key()); | ||
|
||
if (!$verification["success"]) { | ||
$errors[ 'field' . $args['id'] ] = $errorPrefix . FriendlyCaptcha_Plugin::default_error_user_message(); | ||
} | ||
|
||
return $errors; | ||
|
||
} | ||
|
||
/** | ||
* If the saved value will be different from the submitted value, | ||
* alter it here. | ||
*/ | ||
public function get_value_to_save( $value, $atts ) { | ||
// Make changes to $value or remove this function. | ||
return $value; | ||
} | ||
|
||
/** | ||
* Customize the way the value is displayed in emails and views. | ||
* | ||
* @return string | ||
*/ | ||
protected function prepare_display_value( $value, $atts ) { | ||
// Make changes to $value here or remove this function. | ||
return $value; | ||
} | ||
|
||
/** | ||
* @return string Whatever shows in the front end goes here. | ||
*/ | ||
public function front_field_input( $args, $shortcode_atts ) { | ||
ob_start(); | ||
include( dirname( __FILE__ ) . '/front-end-field.php' ); | ||
$input_html = ob_get_contents(); | ||
ob_end_clean(); | ||
return $input_html; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>Friendly Captcha is load only on frontend.</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>Settings is in the plugin Friendly Captcha</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/* | ||
Plugin Name: Formidable Forms Field Friendly Captcha | ||
Description: Friendly Captcha field type in Formidable Forms. | ||
Version: 1.0 | ||
Plugin URI: https://formidableforms.com/ | ||
Author URI: https://netsuccess.sk/ | ||
Author: SlimCo | ||
*/ | ||
|
||
|
||
// TODO: replace 'frmfrcaptcha_' and 'Frcaptcha' with your own. | ||
// TODO: replace 'new-type' with the slug for your field. | ||
|
||
/** | ||
* Add the autoloader. | ||
*/ | ||
function frmfrcaptcha_load_formidable_field() { | ||
spl_autoload_register( 'frmfrcaptcha_forms_autoloader' ); | ||
} | ||
add_action( 'plugins_loaded', 'frmfrcaptcha_load_formidable_field' ); | ||
|
||
/** | ||
* @since 3.0 | ||
*/ | ||
function frmfrcaptcha_forms_autoloader( $class_name ) { | ||
// Only load Frcaptcha classes here | ||
if ( ! preg_match( '/^Frcaptcha.+$/', $class_name ) ) { | ||
return; | ||
} | ||
|
||
$filepath = dirname( __FILE__ ); | ||
$filepath .= '/' . $class_name . '.php'; | ||
|
||
if ( file_exists( $filepath ) ) { | ||
require( $filepath ); | ||
} | ||
} | ||
|
||
/** | ||
* Tell Formidable where to find the new field type. | ||
* @return string The name of the new class that extends FrmFieldType. | ||
*/ | ||
function frmfrcaptcha_get_field_type_class( $class, $field_type ) { | ||
if ( $field_type === 'frcaptcha' ) { // Replace 'frcaptcha' with your field slug. | ||
$class = 'FrcaptchaFieldNewType'; // Set your class name here. | ||
} | ||
return $class; | ||
} | ||
add_filter( 'frm_get_field_type_class', 'frmfrcaptcha_get_field_type_class', 10, 2 ); | ||
|
||
function frmfrcaptcha_add_new_field( $fields ) { | ||
$fields['frcaptcha'] = array( | ||
'name' => 'Friendly Captcha', | ||
'icon' => 'frm_icon_font frm_pencil_icon', // Set the class for a custom icon here. | ||
); | ||
return $fields; | ||
} | ||
add_filter( 'frm_available_fields', 'frmfrcaptcha_add_new_field' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
if ( ! defined( 'ABSPATH' ) ) { | ||
die( 'You are not allowed to call this page directly.' ); | ||
} | ||
|
||
$plugin = FriendlyCaptcha_Plugin::$instance; | ||
if (!$plugin->is_configured() or !$plugin->get_formidable_active()) { | ||
return; | ||
} | ||
|
||
echo frcaptcha_generate_widget_tag_from_plugin($plugin); | ||
|
||
frcaptcha_enqueue_widget_scripts(); |