Plugin Directory

Changeset 3201748


Ignore:
Timestamp:
12/03/2024 01:45:56 PM (13 months ago)
Author:
friendlycaptcha
Message:

Update to version 1.15.6 from GitHub

Location:
friendly-captcha
Files:
4 deleted
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • friendly-captcha/tags/1.15.6/friendly-captcha.php

    r3198937 r3201748  
    44 * Plugin Name: Friendly Captcha for WordPress
    55 * Description: Protect WordPress website forms from spam and abuse with Friendly Captcha, a privacy-first anti-bot solution.
    6  * Version: 1.15.5
     6 * Version: 1.15.6
    77 * Requires at least: 5.0
    88 * Requires PHP: 7.3
     
    2020}
    2121
    22 define('FRIENDLY_CAPTCHA_VERSION', '1.15.5');
     22define('FRIENDLY_CAPTCHA_VERSION', '1.15.6');
    2323define('FRIENDLY_CAPTCHA_FRIENDLY_CHALLENGE_VERSION', '0.9.18');
    2424define('FRIENDLY_CAPTCHA_FRIENDLY_CAPTCHA_SDK_VERSION', '0.1.10');
  • friendly-captcha/tags/1.15.6/includes/core.php

    r3161336 r3201748  
    6868            "entry" => "coblocks/coblocks.php",
    6969            "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.",
    7171        ),
    7272        array(
     
    7575            "entry" => "fluentform/fluentform.php",
    7676            "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.",
    7878        ),
    7979        array(
  • friendly-captcha/tags/1.15.6/modules/coblocks/coblocks.php

    r3116869 r3201748  
    11<?php
    22
    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
     5add_filter('render_block', array('Frcaptcha_Coblocks', 'render_block'), 10, 3);
     6add_filter('render_block_data', array('Frcaptcha_Coblocks', 'render_block_data'), 10, 3);
     7
     8class 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        }
    533
    634
    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)
    1091    {
    1192        $plugin = FriendlyCaptcha_Plugin::$instance;
     
    1495        }
    1596
    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;
    51102        }
    52103
    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']);
    60105
    61         $errorPrefix = '<strong>' . __('Error', 'wp-captcha') . '</strong> : ';
    62106        $solution = frcaptcha_get_sanitized_frcaptcha_solution_from_post();
    63 
    64107        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            ];
    66116        }
    67117
    68118        $verification = frcaptcha_verify_captcha_solution($solution, $plugin->get_sitekey(), $plugin->get_api_key());
    69119        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            ];
    71128        }
    72129
    73130        $fieldName = FriendlyCaptcha_Plugin::$instance->get_solution_field_name();
    74131        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        ];
    75141    }
    76142}
  • friendly-captcha/tags/1.15.6/modules/elementor/elementor.php

    r3116869 r3201748  
    33// https://developers.elementor.com/docs/form-fields/add-new-field/
    44
    5 function add_form_field($form_fields_registrar)
     5function frcaptcha_add_form_field($form_fields_registrar)
    66{
    77    $plugin = FriendlyCaptcha_Plugin::$instance;
     
    1414    $form_fields_registrar->register(new \Elementor_Form_Friendlycaptcha_Field());
    1515}
    16 add_action('elementor_pro/forms/fields/register', 'add_form_field');
     16
     17add_action('elementor_pro/forms/fields/register', 'frcaptcha_add_form_field');
  • friendly-captcha/tags/1.15.6/readme.txt

    r3198937 r3201748  
    55Tested up to: 6.5
    66Requires PHP: 7.3
    7 Stable tag: 1.15.5
     7Stable tag: 1.15.6
    88License: GPL v2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html 
     
    9797== Changelog ==
    9898
     99= 1.15.6 =
     100
     101* Update CoBlocks integration to work with the latest version of the plugin
     102
    99103= 1.15.5 =
    100104
  • friendly-captcha/trunk/friendly-captcha.php

    r3198937 r3201748  
    44 * Plugin Name: Friendly Captcha for WordPress
    55 * Description: Protect WordPress website forms from spam and abuse with Friendly Captcha, a privacy-first anti-bot solution.
    6  * Version: 1.15.5
     6 * Version: 1.15.6
    77 * Requires at least: 5.0
    88 * Requires PHP: 7.3
     
    2020}
    2121
    22 define('FRIENDLY_CAPTCHA_VERSION', '1.15.5');
     22define('FRIENDLY_CAPTCHA_VERSION', '1.15.6');
    2323define('FRIENDLY_CAPTCHA_FRIENDLY_CHALLENGE_VERSION', '0.9.18');
    2424define('FRIENDLY_CAPTCHA_FRIENDLY_CAPTCHA_SDK_VERSION', '0.1.10');
  • friendly-captcha/trunk/includes/core.php

    r3161336 r3201748  
    6868            "entry" => "coblocks/coblocks.php",
    6969            "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.",
    7171        ),
    7272        array(
     
    7575            "entry" => "fluentform/fluentform.php",
    7676            "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.",
    7878        ),
    7979        array(
  • friendly-captcha/trunk/modules/coblocks/coblocks.php

    r3116869 r3201748  
    11<?php
    22
    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
     5add_filter('render_block', array('Frcaptcha_Coblocks', 'render_block'), 10, 3);
     6add_filter('render_block_data', array('Frcaptcha_Coblocks', 'render_block_data'), 10, 3);
     7
     8class 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        }
    533
    634
    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)
    1091    {
    1192        $plugin = FriendlyCaptcha_Plugin::$instance;
     
    1495        }
    1596
    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;
    51102        }
    52103
    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']);
    60105
    61         $errorPrefix = '<strong>' . __('Error', 'wp-captcha') . '</strong> : ';
    62106        $solution = frcaptcha_get_sanitized_frcaptcha_solution_from_post();
    63 
    64107        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            ];
    66116        }
    67117
    68118        $verification = frcaptcha_verify_captcha_solution($solution, $plugin->get_sitekey(), $plugin->get_api_key());
    69119        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            ];
    71128        }
    72129
    73130        $fieldName = FriendlyCaptcha_Plugin::$instance->get_solution_field_name();
    74131        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        ];
    75141    }
    76142}
  • friendly-captcha/trunk/modules/elementor/elementor.php

    r3116869 r3201748  
    33// https://developers.elementor.com/docs/form-fields/add-new-field/
    44
    5 function add_form_field($form_fields_registrar)
     5function frcaptcha_add_form_field($form_fields_registrar)
    66{
    77    $plugin = FriendlyCaptcha_Plugin::$instance;
     
    1414    $form_fields_registrar->register(new \Elementor_Form_Friendlycaptcha_Field());
    1515}
    16 add_action('elementor_pro/forms/fields/register', 'add_form_field');
     16
     17add_action('elementor_pro/forms/fields/register', 'frcaptcha_add_form_field');
  • friendly-captcha/trunk/readme.txt

    r3198937 r3201748  
    55Tested up to: 6.5
    66Requires PHP: 7.3
    7 Stable tag: 1.15.5
     7Stable tag: 1.15.6
    88License: GPL v2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html 
     
    9797== Changelog ==
    9898
     99= 1.15.6 =
     100
     101* Update CoBlocks integration to work with the latest version of the plugin
     102
    99103= 1.15.5 =
    100104
Note: See TracChangeset for help on using the changeset viewer.