-
-
Notifications
You must be signed in to change notification settings - Fork 14
Added support for generic implementation (very simple) #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LU-386
wants to merge
7
commits into
FriendlyCaptcha:main
Choose a base branch
from
LU-386:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
989c3d6
added fc_generic_integration
LU-386 6c41fa8
added generic_integration, mostly oriented at #167
LU-386 68da323
fixed error when lax_on_failure is true and integration is disabled
LU-386 fb808f4
added generic_integration, mostly oriented at #167
LU-386 b3765b7
Merge branch 'main' into fix
LU-386 3cb3dd0
Update friendly-captcha/modules/generic_integration/generic_integrati…
LU-386 1a69103
Update friendly-captcha/modules/generic_integration/generic_integrati…
LU-386 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
51 changes: 51 additions & 0 deletions
51
friendly-captcha/modules/generic_integration/generic_integration.php
This file contains hidden or 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,51 @@ | ||
| <?php | ||
| /* | ||
| * FriendlyCaptcha Helper to integrate better with custom code. | ||
| */ | ||
|
|
||
| /** Add captcha to forms | ||
| * @param string $html html to append the captcha widget to | ||
| * @return string html with captcha widget appended | ||
| */ | ||
| add_filter("frc_captcha_append_widget", function ($html) { | ||
| $plugin = FriendlyCaptcha_Plugin::$instance; | ||
| if (!$plugin->is_configured()) { | ||
| return $html; | ||
| } | ||
|
|
||
| frcaptcha_enqueue_widget_scripts(); | ||
|
|
||
| $widget = frcaptcha_generate_widget_tag_from_plugin($plugin); | ||
| return $html . $widget; | ||
| }); | ||
|
|
||
| /** Validate captcha on form submission | ||
| * @param string $solution value of $_POST['frc-captcha-solution'] | ||
| * @param bool $lax_on_failure how to decide on network failure: returning false here means a broken network failure or integration in settings is deactivated is treated as a bot. | ||
| * @return bool true = human, false = bot / missing solution | ||
| */ | ||
| add_filter( | ||
| "frc_captcha_validation", | ||
| function ($solution, $lax_on_failure) { | ||
| $plugin = FriendlyCaptcha_Plugin::$instance; | ||
|
|
||
| if (!$plugin->is_configured()) { | ||
| return $lax_on_failure; | ||
| } | ||
|
|
||
| if (empty($solution)) { | ||
| return false; | ||
| } | ||
|
|
||
| $verification = frcaptcha_verify_captcha_solution( | ||
| $solution, | ||
| $plugin->get_sitekey(), | ||
| $plugin->get_api_key(), | ||
| "generic_integration", | ||
| ); | ||
|
|
||
| return $verification["success"]; | ||
| }, | ||
| 10, | ||
| 2, | ||
| ); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess other plugins could also just call
frcaptcha_verify_captcha_solutiondirectly right? I'm not a Wordpress expert so I wonder what the benefit of the additional filter is 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filter name(s) must correspond to the filter name(s) in the FC module file. So in theory, it should be possible to have a generic module with filter names that the actual WP forms use.
However, I remember that I first tried to use the html-forms module for my purposes but it didn't work (may be I did a mistake).
Second:
All supported form plugins are listed in the core.php file like this:
That means there are hardcoded plugin names and paths, anyway (
entry,plugins). So it makes no difference if we have custom filter names or not (I guess) since every single form plugin that we want to support needs it's own module file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really wanted to keep it simple and version agnostic to implement.
If there is something additional to be handled in the future, it can just be added into the filter without affecting anything else by changing
frcaptcha_verify_captcha_solution.