Created
August 22, 2022 23:34
-
-
Save cr0ybot/57d4d20184e7a2bdac057cdacc73591c to your computer and use it in GitHub Desktop.
This plugin is a Gutenberg compatibility layer for the reCAPTCHA Jetpack plugin v0.2.2: https://wordpress.org/plugins/recaptcha-jetpack/
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
<?php | |
/** | |
* Plugin Name: reCAPTCHA Jetpack Gutenberg Compatibility | |
* Description: Adds reCAPTCHA to Jetpack Gutenberg forms. | |
* Version: 1.0.0 | |
* Author: Cory Hughart | |
* Author URI: https://coryhughart.com | |
* License: GPLv2 or later | |
* | |
* This plugin is a Gutenberg compatibility layer for the reCAPTCHA Jetpack plugin v0.2.2: https://wordpress.org/plugins/recaptcha-jetpack/ | |
*/ | |
namespace coryhughart\recaptcha_jetpack_compat; | |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
function init() { | |
if ( class_exists('Bozdoz_RJP_Plugin') ) { | |
add_filter( 'the_content', __NAMESPACE__ . '\\add_gb_recaptcha', 1 ); | |
add_filter( 'widget_block_content', __NAMESPACE__ . '\\add_gb_recaptcha', 1 ); | |
} | |
} | |
add_action( 'init', __NAMESPACE__ . '\\init' ); | |
function add_gb_recaptcha( $content ) { | |
$form_close = "</div>\n<!-- /wp:jetpack/contact-form -->"; | |
if ( strpos( $content, $form_close ) === false ) return $content; | |
if (get_option(\Bozdoz_RJP_Plugin::$prefix . 'recaptcha_type', 'v2') === 'invisible') { | |
wp_enqueue_script(\Bozdoz_RJP_Plugin::$prefix . 'invisible_recaptcha_script'); | |
} else { | |
wp_enqueue_script(\Bozdoz_RJP_Plugin::$prefix . 'recaptcha_script'); | |
} | |
$content = str_replace( $form_close, '[' . \Bozdoz_RJP_Plugin::$prefix . '-button]' . $form_close, $content ); | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment