-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit aafc61e
Showing
14 changed files
with
4,177 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# A set of files you probably don't want in your WordPress.org distribution | ||
.babelrc | ||
.deployignore | ||
.distignore | ||
.editorconfig | ||
.eslintignore | ||
.eslintrc | ||
.git | ||
.gitignore | ||
.github | ||
.gitlab-ci.yml | ||
.travis.yml | ||
.DS_Store | ||
.*~ | ||
Thumbs.db | ||
behat.yml | ||
bitbucket-pipelines.yml | ||
bin | ||
.circleci/config.yml | ||
composer.json | ||
composer.lock | ||
dependencies.yml | ||
Gruntfile.js | ||
package.json | ||
package-lock.json | ||
phpunit.xml | ||
phpunit.xml.dist | ||
multisite.xml | ||
multisite.xml.dist | ||
.phpcs.xml | ||
phpcs.xml | ||
.phpcs.xml.dist | ||
phpcs.xml.dist | ||
README.md | ||
webpack.config.js | ||
wp-cli.local.yml | ||
yarn.lock | ||
tests | ||
vendor | ||
node_modules | ||
*.sql | ||
*.tar.gz | ||
*.zip |
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,22 @@ | ||
# This file is for unifying the coding style for different editors and IDEs | ||
# editorconfig.org | ||
|
||
# WordPress Coding Standards | ||
# https://make.wordpress.org/core/handbook/coding-standards/ | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
indent_style = tab | ||
indent_size = 4 | ||
|
||
[{.jshintrc,*.json,*.yml}] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[{*.txt,wp-config-sample.php}] | ||
end_of_line = crlf |
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,9 @@ | ||
.DS_Store | ||
phpcs.xml | ||
phpunit.xml | ||
Thumbs.db | ||
wp-cli.local.yml | ||
node_modules/ | ||
*.sql | ||
*.tar.gz | ||
*.zip |
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,86 @@ | ||
module.exports = function (grunt) { | ||
|
||
'use strict'; | ||
|
||
// Project configuration | ||
grunt.initConfig({ | ||
|
||
pkg: grunt.file.readJSON('package.json'), | ||
|
||
addtextdomain: { | ||
options: { | ||
textdomain: 'cf7-lazy-recaptcha', | ||
}, | ||
update_all_domains: { | ||
options: { | ||
updateDomains: true | ||
}, | ||
src: ['*.php', '**/*.php', '!\.git/**/*', '!bin/**/*', '!node_modules/**/*', '!tests/**/*'] | ||
} | ||
}, | ||
|
||
wp_readme_to_markdown: { | ||
your_target: { | ||
files: { | ||
'README.md': 'readme.txt' | ||
} | ||
}, | ||
}, | ||
|
||
makepot: { | ||
target: { | ||
options: { | ||
domainPath: '/languages', | ||
exclude: ['\.git/*', 'bin/*', 'node_modules/*', 'tests/*'], | ||
mainFile: 'cf7-lazy-recaptcha.php', | ||
potFilename: 'cf7-lazy-recaptcha.pot', | ||
potHeaders: { | ||
poedit: true, | ||
'x-poedit-keywordslist': true | ||
}, | ||
type: 'wp-plugin', | ||
updateTimestamp: true | ||
} | ||
} | ||
}, | ||
|
||
babel: { | ||
options: { | ||
sourceMap: true, | ||
presets: ['@babel/preset-env'] | ||
}, | ||
dist: { | ||
files: { | ||
'dist/index.js': 'src/index.js' | ||
} | ||
} | ||
}, | ||
uglify: { | ||
options: { | ||
sourceMap: { | ||
includeSources: true | ||
}, | ||
sourceMapIn: 'dist/index.js.map', | ||
}, | ||
my_target: { | ||
files: { | ||
'dist/index.min.js': ['dist/index.js'] | ||
} | ||
} | ||
} | ||
}); | ||
|
||
|
||
grunt.loadNpmTasks('grunt-babel'); | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
grunt.loadNpmTasks('grunt-wp-i18n'); | ||
grunt.loadNpmTasks('grunt-wp-readme-to-markdown'); | ||
|
||
grunt.registerTask('default', ['i18n', 'readme', 'babel', 'uglify']); | ||
grunt.registerTask('js', ['babel', 'uglify']); | ||
grunt.registerTask('i18n', ['addtextdomain', 'makepot']); | ||
grunt.registerTask('readme', ['wp_readme_to_markdown']); | ||
|
||
grunt.util.linefeed = '\n'; | ||
|
||
}; |
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,41 @@ | ||
# Cf7 Lazy Recaptcha # | ||
**Contributors:** [(this-should-be-a-list-of-wordpress.org-userid's)](https://profiles.wordpress.org/(this-should-be-a-list-of-wordpress.org-userid's)/) | ||
**Donate link:** https://example.com/ | ||
**Tags:** Contact Form 7, performance, speed optimization | ||
**Requires at least:** 4.5 | ||
**Tested up to:** 6.4.2 | ||
**Requires PHP:** 8.0 | ||
**Stable tag:** 0.1.0 | ||
**License:** GPLv2 or later | ||
**License URI:** https://www.gnu.org/licenses/gpl-2.0.html | ||
|
||
Improves website loading speed by lazy loading reCaptcha for Contact Form 7. | ||
|
||
## Description ## | ||
|
||
Usually, reCaptcha scripts load immediately in Contect Form 7. Regardless of whether | ||
you use the async or defer strategy, reCaptcha script execution requires a significant | ||
amount of device resources, which is very noticeable on mobile devices. | ||
|
||
The idea behind the plugin is simple: load and execute reCaptcha only when the user | ||
starts interacting with the contact form. This results in a significant increase in | ||
loading speed, but it can lead to worse spam detection (see FAQ). | ||
|
||
|
||
|
||
|
||
## Installation ## | ||
|
||
This section describes how to install the plugin and get it working. | ||
|
||
1. Upload `lazy-recaptcha-for-cf7.zip` to the `/wp-content/plugins/` directory and unzip it | ||
1. Activate the plugin through the 'Plugins' menu in WordPress | ||
|
||
## Frequently Asked Questions ## | ||
|
||
### Does it reduce the accuracy of spam detection? ### | ||
|
||
It is likely to [decrease][recaptcha docs]. Therefore, it is advisable to use this method only if there are no other ways to improve the speed. | ||
|
||
|
||
[recaptcha docs]: https://developers.google.com/recaptcha/docs/loading#lazy_loading "Loading reCAPTCHA | Google for Developers" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,62 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Lazy Recaptcha for Contact Form 7 | ||
* Plugin URI: https://wordpress.org/plugins/lazy-recaptcha-for-cf7 | ||
* Description: Improves website loading speed by lazy loading reCaptcha for Contact Form 7. | ||
* Author: Ivan Pazenko | ||
* Text Domain: lazy-recaptcha-for-cf7 | ||
* Domain Path: /languages | ||
* License: GPL v2 or later | ||
* License URI: https://www.gnu.org/licenses/gpl-2.0.html | ||
* Version: 0.1.0 | ||
* | ||
* @package Cf7_Lazy_Recaptcha | ||
*/ | ||
|
||
|
||
class CF7LazyRecaptcha { | ||
public function __construct() { | ||
define( 'CF7_LAZY_VERSION', '0.1.0' ); | ||
define( 'LAZY_RECAPTCHA_DIR', plugin_dir_path( __FILE__ ) ); | ||
define( 'LAZY_RECAPTCHA_URI', plugin_dir_url( __FILE__ ) ); | ||
|
||
add_action( 'init', array( $this, 'lazy_recaptcha_init_setup' ) ); | ||
} | ||
|
||
public function lazy_recaptcha_init_setup(): void { | ||
if ( class_exists( 'WPCF7' ) && class_exists( 'WPCF7_RECAPTCHA' ) ) { | ||
$recaptcha = WPCF7_RECAPTCHA::get_instance(); | ||
if ( ! empty( $recaptcha->is_active() ) ) { | ||
add_action( 'wp_enqueue_scripts', array( $this, 'dequeue_cf7_recaptcha_scripts' ), 21 ); | ||
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_lazy_recaptcha_script' ), 21 ); | ||
} | ||
} | ||
} | ||
|
||
public function dequeue_cf7_recaptcha_scripts(): void { | ||
wp_dequeue_script( 'google-recaptcha' ); | ||
wp_dequeue_script( 'wpcf7-recaptcha' ); | ||
} | ||
|
||
public function enqueue_lazy_recaptcha_script(): void { | ||
$script_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; | ||
|
||
wp_enqueue_script( 'lazy-recaptcha-script', LAZY_RECAPTCHA_URI . "dist/index{$script_suffix}.js", array(), CF7_LAZY_VERSION, true ); | ||
|
||
$recaptcha_instance = WPCF7_RECAPTCHA::get_instance(); | ||
$recaptcha_sitekey = $recaptcha_instance->get_sitekey(); | ||
$recaptcha_parameters = array( | ||
'sitekey' => $recaptcha_sitekey, | ||
'actions' => apply_filters( 'wpcf7_recaptcha_actions', array( | ||
'homepage' => 'homepage', | ||
'contactform' => 'contactform', | ||
) ), | ||
); | ||
wp_localize_script( 'lazy-recaptcha-script', 'recaptcha_params', $recaptcha_parameters ); | ||
} | ||
} | ||
|
||
new CF7LazyRecaptcha(); | ||
|
||
|
||
|
Oops, something went wrong.