Changeset 3201748
- Timestamp:
- 12/03/2024 01:45:56 PM (13 months ago)
- Location:
- friendly-captcha
- Files:
-
- 4 deleted
- 10 edited
- 1 copied
-
tags/1.15.6 (copied) (copied from friendly-captcha/trunk)
-
tags/1.15.6/friendly-captcha.php (modified) (2 diffs)
-
tags/1.15.6/includes/core.php (modified) (2 diffs)
-
tags/1.15.6/modules/coblocks/block.json (deleted)
-
tags/1.15.6/modules/coblocks/coblocks.php (modified) (2 diffs)
-
tags/1.15.6/modules/coblocks/script.js (deleted)
-
tags/1.15.6/modules/elementor/elementor.php (modified) (2 diffs)
-
tags/1.15.6/readme.txt (modified) (2 diffs)
-
trunk/friendly-captcha.php (modified) (2 diffs)
-
trunk/includes/core.php (modified) (2 diffs)
-
trunk/modules/coblocks/block.json (deleted)
-
trunk/modules/coblocks/coblocks.php (modified) (2 diffs)
-
trunk/modules/coblocks/script.js (deleted)
-
trunk/modules/elementor/elementor.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
friendly-captcha/tags/1.15.6/friendly-captcha.php
r3198937 r3201748 4 4 * Plugin Name: Friendly Captcha for WordPress 5 5 * Description: Protect WordPress website forms from spam and abuse with Friendly Captcha, a privacy-first anti-bot solution. 6 * Version: 1.15. 56 * Version: 1.15.6 7 7 * Requires at least: 5.0 8 8 * Requires PHP: 7.3 … … 20 20 } 21 21 22 define('FRIENDLY_CAPTCHA_VERSION', '1.15. 5');22 define('FRIENDLY_CAPTCHA_VERSION', '1.15.6'); 23 23 define('FRIENDLY_CAPTCHA_FRIENDLY_CHALLENGE_VERSION', '0.9.18'); 24 24 define('FRIENDLY_CAPTCHA_FRIENDLY_CAPTCHA_SDK_VERSION', '0.1.10'); -
friendly-captcha/tags/1.15.6/includes/core.php
r3161336 r3201748 68 68 "entry" => "coblocks/coblocks.php", 69 69 "plugins" => array("coblocks/class-coblocks.php"), 70 "settings_description" => "Enable Friendly Captcha for <a href=\"https://wordpress.org/plugins/coblocks/\" target=\"_blank\">CoBlocks</a> forms. <br> Please insert the Friendly Captcha block into each form which should be protected. If multiple CoBlocks forms are used on the same page, all of them must use Friendly Captcha.",70 "settings_description" => "Enable Friendly Captcha for <a href=\"https://wordpress.org/plugins/coblocks/\" target=\"_blank\">CoBlocks</a> forms.", 71 71 ), 72 72 array( … … 75 75 "entry" => "fluentform/fluentform.php", 76 76 "plugins" => array("fluentform/fluentform.php"), 77 "settings_description" => "Enable Friendly Captcha for <a href=\"https://wordpress.org/plugins/fluentform/\" target=\"_blank\">Fluentform</a> forms. <br>",77 "settings_description" => "Enable Friendly Captcha for <a href=\"https://wordpress.org/plugins/fluentform/\" target=\"_blank\">Fluentform</a> forms.", 78 78 ), 79 79 array( -
friendly-captcha/tags/1.15.6/modules/coblocks/coblocks.php
r3116869 r3201748 1 1 <?php 2 2 3 add_action('coblocks_register_form_blocks', array('frcaptcha_coblocks_load_addon', 'load'), 5); 4 add_action('coblocks_before_form_submit', array('frcaptcha_coblocks_load_addon', 'before_form_submit'), 5, 2); 3 // Implementation inspired by https://github.com/hCaptcha/hcaptcha-wordpress-plugin/blob/master/src/php/CoBlocks/Form.php 4 5 add_filter('render_block', array('Frcaptcha_Coblocks', 'render_block'), 10, 3); 6 add_filter('render_block_data', array('Frcaptcha_Coblocks', 'render_block_data'), 10, 3); 7 8 class Frcaptcha_Coblocks 9 { 10 private const FRIENDLY_CAPTCHA_DUMMY_TOKEN = 'friendlycaptcha_token'; 11 12 /** 13 * Add Friendly Captcha to CoBlocks form. 14 * 15 * @param string|mixed $block_content The block content. 16 * @param array $block The full block, including name and attributes. 17 * @param WP_Block $instance The block instance. 18 * 19 * @return string 20 * @noinspection PhpUnusedParameterInspection 21 */ 22 public static function render_block($block_content, array $block, WP_Block $instance): string 23 { 24 $block_content = (string) $block_content; 25 if ('coblocks/form' !== $block['blockName']) { 26 return $block_content; 27 } 28 29 $plugin = FriendlyCaptcha_Plugin::$instance; 30 if (!$plugin->is_configured()) { 31 return $block_content; 32 } 5 33 6 34 7 class frcaptcha_coblocks_load_addon 8 { 9 public static function load() 35 frcaptcha_enqueue_widget_scripts(); 36 37 $elements = frcaptcha_generate_widget_tag_from_plugin($plugin); 38 return str_replace('<button type="submit"', $elements . '<button type="submit"', $block_content); 39 } 40 41 /** 42 * Render block context filter. 43 * CoBlocks has no filters in form processing. So, we need to do some tricks. 44 * 45 * @since WP 5.1.0 46 * 47 * @param array|mixed $parsed_block The block being rendered. 48 * @param array $source_block An unmodified copy of $parsed_block, as it appeared in the source content. 49 * 50 * @return array 51 * @noinspection PhpUnusedParameterInspection 52 */ 53 public static function render_block_data($parsed_block, array $source_block): array 54 { 55 static $filters_added; 56 if ($filters_added) { 57 return $parsed_block; 58 } 59 60 $parsed_block = (array) $parsed_block; 61 $block_name = $parsed_block['blockName'] ?? ''; 62 if ('coblocks/form' !== $block_name) { 63 return $parsed_block; 64 } 65 66 $form_submission = isset($_POST['action']) ? sanitize_text_field(wp_unslash($_POST['action'])) : ''; 67 if ('coblocks-form-submit' !== $form_submission) { 68 return $parsed_block; 69 } 70 71 // We cannot add filters right here. 72 // In this case, the calculation of form hash in the coblocks_render_coblocks_form_block() will fail. 73 add_action('coblocks_before_form_submit', ['Frcaptcha_Coblocks', 'before_form_submit'], 10, 2); 74 75 $filters_added = true; 76 77 return $parsed_block; 78 } 79 80 public static function before_form_submit(array $post, array $atts): void 81 { 82 add_filter('pre_option_coblocks_google_recaptcha_site_key', '__return_true'); 83 add_filter('pre_option_coblocks_google_recaptcha_secret_key', '__return_true'); 84 85 $_POST['g-recaptcha-token'] = self::FRIENDLY_CAPTCHA_DUMMY_TOKEN; 86 87 add_filter('pre_http_request', ['Frcaptcha_Coblocks', 'verify'], 10, 3); 88 } 89 90 public static function verify($response, array $parsed_args, string $url) 10 91 { 11 92 $plugin = FriendlyCaptcha_Plugin::$instance; … … 14 95 } 15 96 16 $instance = new frcaptcha_coblocks_load_addon(); 17 18 register_block_type( 19 __DIR__, 20 array( 21 'render_callback' => array($instance, 'render_field_friendly_captcha'), 22 ) 23 ); 24 25 add_action('enqueue_block_editor_assets', array($instance, 'frcaptcha_coblocks_enqueue_block_editor_assets')); 26 } 27 28 public function render_field_friendly_captcha($is_preview) 29 { 30 frcaptcha_enqueue_widget_scripts(); 31 return frcaptcha_generate_widget_tag_from_plugin(FriendlyCaptcha_Plugin::$instance); 32 } 33 34 public function frcaptcha_coblocks_enqueue_block_editor_assets() 35 { 36 wp_enqueue_script( 37 'frcaptcha_coblocks_load_addon', 38 plugin_dir_url(__FILE__) . '/script.js', 39 array('wp-blocks', 'wp-editor', 'wp-element', 'wp-i18n'), 40 filemtime(plugin_dir_path(__FILE__) . 'script.js') 41 ); 42 wp_localize_script('frcaptcha_coblocks_load_addon', 'frcaptcha_coblocks_settings', ['preview' => plugin_dir_url(dirname(dirname(__FILE__))) . 'assets/preview.png']); 43 } 44 45 public static function before_form_submit($postData, $atts) 46 { 47 $plugin = FriendlyCaptcha_Plugin::$instance; 48 49 if (!$plugin->is_configured()) { 50 return; 97 if ( 98 CoBlocks_Form::GCAPTCHA_VERIFY_URL !== $url || 99 self::FRIENDLY_CAPTCHA_DUMMY_TOKEN !== $parsed_args['body']['response'] 100 ) { 101 return $response; 51 102 } 52 103 53 // if the current page has any friendly captcha widget, the check will be enforced 54 // that means if there are two forms, they both need to use the widget 55 // checking the existing widget for the current form seems not practical 56 // most pages are expected to have only one form though 57 if (!has_block('frcaptcha/field-friendly-captcha')) { 58 return; 59 } 104 remove_filter('pre_http_request', ['Frcaptcha_Coblocks', 'verify']); 60 105 61 $errorPrefix = '<strong>' . __('Error', 'wp-captcha') . '</strong> : ';62 106 $solution = frcaptcha_get_sanitized_frcaptcha_solution_from_post(); 63 64 107 if (empty($solution)) { 65 wp_die($errorPrefix . FriendlyCaptcha_Plugin::default_error_user_message() . __(" (captcha missing)", "frcaptcha")); 108 return [ 109 'body' => '{"success":false}', 110 'response' => 111 [ 112 'code' => 200, 113 'message' => 'OK', 114 ], 115 ]; 66 116 } 67 117 68 118 $verification = frcaptcha_verify_captcha_solution($solution, $plugin->get_sitekey(), $plugin->get_api_key()); 69 119 if (!$verification["success"]) { 70 wp_die($errorPrefix . FriendlyCaptcha_Plugin::default_error_user_message()); 120 return [ 121 'body' => '{"success":false}', 122 'response' => 123 [ 124 'code' => 200, 125 'message' => 'OK', 126 ], 127 ]; 71 128 } 72 129 73 130 $fieldName = FriendlyCaptcha_Plugin::$instance->get_solution_field_name(); 74 131 unset($_POST[$fieldName]); // suppress the solution in email message 132 133 return [ 134 'body' => '{"success":true}', 135 'response' => 136 [ 137 'code' => 200, 138 'message' => 'OK', 139 ], 140 ]; 75 141 } 76 142 } -
friendly-captcha/tags/1.15.6/modules/elementor/elementor.php
r3116869 r3201748 3 3 // https://developers.elementor.com/docs/form-fields/add-new-field/ 4 4 5 function add_form_field($form_fields_registrar)5 function frcaptcha_add_form_field($form_fields_registrar) 6 6 { 7 7 $plugin = FriendlyCaptcha_Plugin::$instance; … … 14 14 $form_fields_registrar->register(new \Elementor_Form_Friendlycaptcha_Field()); 15 15 } 16 add_action('elementor_pro/forms/fields/register', 'add_form_field'); 16 17 add_action('elementor_pro/forms/fields/register', 'frcaptcha_add_form_field'); -
friendly-captcha/tags/1.15.6/readme.txt
r3198937 r3201748 5 5 Tested up to: 6.5 6 6 Requires PHP: 7.3 7 Stable tag: 1.15. 57 Stable tag: 1.15.6 8 8 License: GPL v2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 97 97 == Changelog == 98 98 99 = 1.15.6 = 100 101 * Update CoBlocks integration to work with the latest version of the plugin 102 99 103 = 1.15.5 = 100 104 -
friendly-captcha/trunk/friendly-captcha.php
r3198937 r3201748 4 4 * Plugin Name: Friendly Captcha for WordPress 5 5 * Description: Protect WordPress website forms from spam and abuse with Friendly Captcha, a privacy-first anti-bot solution. 6 * Version: 1.15. 56 * Version: 1.15.6 7 7 * Requires at least: 5.0 8 8 * Requires PHP: 7.3 … … 20 20 } 21 21 22 define('FRIENDLY_CAPTCHA_VERSION', '1.15. 5');22 define('FRIENDLY_CAPTCHA_VERSION', '1.15.6'); 23 23 define('FRIENDLY_CAPTCHA_FRIENDLY_CHALLENGE_VERSION', '0.9.18'); 24 24 define('FRIENDLY_CAPTCHA_FRIENDLY_CAPTCHA_SDK_VERSION', '0.1.10'); -
friendly-captcha/trunk/includes/core.php
r3161336 r3201748 68 68 "entry" => "coblocks/coblocks.php", 69 69 "plugins" => array("coblocks/class-coblocks.php"), 70 "settings_description" => "Enable Friendly Captcha for <a href=\"https://wordpress.org/plugins/coblocks/\" target=\"_blank\">CoBlocks</a> forms. <br> Please insert the Friendly Captcha block into each form which should be protected. If multiple CoBlocks forms are used on the same page, all of them must use Friendly Captcha.",70 "settings_description" => "Enable Friendly Captcha for <a href=\"https://wordpress.org/plugins/coblocks/\" target=\"_blank\">CoBlocks</a> forms.", 71 71 ), 72 72 array( … … 75 75 "entry" => "fluentform/fluentform.php", 76 76 "plugins" => array("fluentform/fluentform.php"), 77 "settings_description" => "Enable Friendly Captcha for <a href=\"https://wordpress.org/plugins/fluentform/\" target=\"_blank\">Fluentform</a> forms. <br>",77 "settings_description" => "Enable Friendly Captcha for <a href=\"https://wordpress.org/plugins/fluentform/\" target=\"_blank\">Fluentform</a> forms.", 78 78 ), 79 79 array( -
friendly-captcha/trunk/modules/coblocks/coblocks.php
r3116869 r3201748 1 1 <?php 2 2 3 add_action('coblocks_register_form_blocks', array('frcaptcha_coblocks_load_addon', 'load'), 5); 4 add_action('coblocks_before_form_submit', array('frcaptcha_coblocks_load_addon', 'before_form_submit'), 5, 2); 3 // Implementation inspired by https://github.com/hCaptcha/hcaptcha-wordpress-plugin/blob/master/src/php/CoBlocks/Form.php 4 5 add_filter('render_block', array('Frcaptcha_Coblocks', 'render_block'), 10, 3); 6 add_filter('render_block_data', array('Frcaptcha_Coblocks', 'render_block_data'), 10, 3); 7 8 class Frcaptcha_Coblocks 9 { 10 private const FRIENDLY_CAPTCHA_DUMMY_TOKEN = 'friendlycaptcha_token'; 11 12 /** 13 * Add Friendly Captcha to CoBlocks form. 14 * 15 * @param string|mixed $block_content The block content. 16 * @param array $block The full block, including name and attributes. 17 * @param WP_Block $instance The block instance. 18 * 19 * @return string 20 * @noinspection PhpUnusedParameterInspection 21 */ 22 public static function render_block($block_content, array $block, WP_Block $instance): string 23 { 24 $block_content = (string) $block_content; 25 if ('coblocks/form' !== $block['blockName']) { 26 return $block_content; 27 } 28 29 $plugin = FriendlyCaptcha_Plugin::$instance; 30 if (!$plugin->is_configured()) { 31 return $block_content; 32 } 5 33 6 34 7 class frcaptcha_coblocks_load_addon 8 { 9 public static function load() 35 frcaptcha_enqueue_widget_scripts(); 36 37 $elements = frcaptcha_generate_widget_tag_from_plugin($plugin); 38 return str_replace('<button type="submit"', $elements . '<button type="submit"', $block_content); 39 } 40 41 /** 42 * Render block context filter. 43 * CoBlocks has no filters in form processing. So, we need to do some tricks. 44 * 45 * @since WP 5.1.0 46 * 47 * @param array|mixed $parsed_block The block being rendered. 48 * @param array $source_block An unmodified copy of $parsed_block, as it appeared in the source content. 49 * 50 * @return array 51 * @noinspection PhpUnusedParameterInspection 52 */ 53 public static function render_block_data($parsed_block, array $source_block): array 54 { 55 static $filters_added; 56 if ($filters_added) { 57 return $parsed_block; 58 } 59 60 $parsed_block = (array) $parsed_block; 61 $block_name = $parsed_block['blockName'] ?? ''; 62 if ('coblocks/form' !== $block_name) { 63 return $parsed_block; 64 } 65 66 $form_submission = isset($_POST['action']) ? sanitize_text_field(wp_unslash($_POST['action'])) : ''; 67 if ('coblocks-form-submit' !== $form_submission) { 68 return $parsed_block; 69 } 70 71 // We cannot add filters right here. 72 // In this case, the calculation of form hash in the coblocks_render_coblocks_form_block() will fail. 73 add_action('coblocks_before_form_submit', ['Frcaptcha_Coblocks', 'before_form_submit'], 10, 2); 74 75 $filters_added = true; 76 77 return $parsed_block; 78 } 79 80 public static function before_form_submit(array $post, array $atts): void 81 { 82 add_filter('pre_option_coblocks_google_recaptcha_site_key', '__return_true'); 83 add_filter('pre_option_coblocks_google_recaptcha_secret_key', '__return_true'); 84 85 $_POST['g-recaptcha-token'] = self::FRIENDLY_CAPTCHA_DUMMY_TOKEN; 86 87 add_filter('pre_http_request', ['Frcaptcha_Coblocks', 'verify'], 10, 3); 88 } 89 90 public static function verify($response, array $parsed_args, string $url) 10 91 { 11 92 $plugin = FriendlyCaptcha_Plugin::$instance; … … 14 95 } 15 96 16 $instance = new frcaptcha_coblocks_load_addon(); 17 18 register_block_type( 19 __DIR__, 20 array( 21 'render_callback' => array($instance, 'render_field_friendly_captcha'), 22 ) 23 ); 24 25 add_action('enqueue_block_editor_assets', array($instance, 'frcaptcha_coblocks_enqueue_block_editor_assets')); 26 } 27 28 public function render_field_friendly_captcha($is_preview) 29 { 30 frcaptcha_enqueue_widget_scripts(); 31 return frcaptcha_generate_widget_tag_from_plugin(FriendlyCaptcha_Plugin::$instance); 32 } 33 34 public function frcaptcha_coblocks_enqueue_block_editor_assets() 35 { 36 wp_enqueue_script( 37 'frcaptcha_coblocks_load_addon', 38 plugin_dir_url(__FILE__) . '/script.js', 39 array('wp-blocks', 'wp-editor', 'wp-element', 'wp-i18n'), 40 filemtime(plugin_dir_path(__FILE__) . 'script.js') 41 ); 42 wp_localize_script('frcaptcha_coblocks_load_addon', 'frcaptcha_coblocks_settings', ['preview' => plugin_dir_url(dirname(dirname(__FILE__))) . 'assets/preview.png']); 43 } 44 45 public static function before_form_submit($postData, $atts) 46 { 47 $plugin = FriendlyCaptcha_Plugin::$instance; 48 49 if (!$plugin->is_configured()) { 50 return; 97 if ( 98 CoBlocks_Form::GCAPTCHA_VERIFY_URL !== $url || 99 self::FRIENDLY_CAPTCHA_DUMMY_TOKEN !== $parsed_args['body']['response'] 100 ) { 101 return $response; 51 102 } 52 103 53 // if the current page has any friendly captcha widget, the check will be enforced 54 // that means if there are two forms, they both need to use the widget 55 // checking the existing widget for the current form seems not practical 56 // most pages are expected to have only one form though 57 if (!has_block('frcaptcha/field-friendly-captcha')) { 58 return; 59 } 104 remove_filter('pre_http_request', ['Frcaptcha_Coblocks', 'verify']); 60 105 61 $errorPrefix = '<strong>' . __('Error', 'wp-captcha') . '</strong> : ';62 106 $solution = frcaptcha_get_sanitized_frcaptcha_solution_from_post(); 63 64 107 if (empty($solution)) { 65 wp_die($errorPrefix . FriendlyCaptcha_Plugin::default_error_user_message() . __(" (captcha missing)", "frcaptcha")); 108 return [ 109 'body' => '{"success":false}', 110 'response' => 111 [ 112 'code' => 200, 113 'message' => 'OK', 114 ], 115 ]; 66 116 } 67 117 68 118 $verification = frcaptcha_verify_captcha_solution($solution, $plugin->get_sitekey(), $plugin->get_api_key()); 69 119 if (!$verification["success"]) { 70 wp_die($errorPrefix . FriendlyCaptcha_Plugin::default_error_user_message()); 120 return [ 121 'body' => '{"success":false}', 122 'response' => 123 [ 124 'code' => 200, 125 'message' => 'OK', 126 ], 127 ]; 71 128 } 72 129 73 130 $fieldName = FriendlyCaptcha_Plugin::$instance->get_solution_field_name(); 74 131 unset($_POST[$fieldName]); // suppress the solution in email message 132 133 return [ 134 'body' => '{"success":true}', 135 'response' => 136 [ 137 'code' => 200, 138 'message' => 'OK', 139 ], 140 ]; 75 141 } 76 142 } -
friendly-captcha/trunk/modules/elementor/elementor.php
r3116869 r3201748 3 3 // https://developers.elementor.com/docs/form-fields/add-new-field/ 4 4 5 function add_form_field($form_fields_registrar)5 function frcaptcha_add_form_field($form_fields_registrar) 6 6 { 7 7 $plugin = FriendlyCaptcha_Plugin::$instance; … … 14 14 $form_fields_registrar->register(new \Elementor_Form_Friendlycaptcha_Field()); 15 15 } 16 add_action('elementor_pro/forms/fields/register', 'add_form_field'); 16 17 add_action('elementor_pro/forms/fields/register', 'frcaptcha_add_form_field'); -
friendly-captcha/trunk/readme.txt
r3198937 r3201748 5 5 Tested up to: 6.5 6 6 Requires PHP: 7.3 7 Stable tag: 1.15. 57 Stable tag: 1.15.6 8 8 License: GPL v2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 97 97 == Changelog == 98 98 99 = 1.15.6 = 100 101 * Update CoBlocks integration to work with the latest version of the plugin 102 99 103 = 1.15.5 = 100 104
Note: See TracChangeset
for help on using the changeset viewer.