Plugin Directory

Changeset 3125319


Ignore:
Timestamp:
07/25/2024 01:26:59 PM (19 months ago)
Author:
simpleform
Message:

refactor: code rewritten following the coding standards
fix: general errors

Location:
simpleform-recaptcha
Files:
57 added
7 edited

Legend:

Unmodified
Added
Removed
  • simpleform-recaptcha/trunk/README.txt

    r2712286 r3125319  
    11=== SimpleForm reCAPTCHA ===
    2 Contributors: simpleform
    3 Donate link: https://wpsform.com/
    4 Tags: contact form, spam, recaptcha, antispam, simpleform addon, spam manager, google, bot, captcha, form
    5 Requires at least: 5.6
    6 Tested up to: 5.9
    7 Requires PHP: 5.6
    8 Stable tag: 1.1.2
     2Contributors: simpleform, gianpic
     3Donate link: paypal.me/simpleformdonation
     4Tags: contact form, spam, recaptcha, antispam, simpleform addon
     5Requires at least: 5.9
     6Tested up to: 6.6
     7Requires PHP: 7.4
     8Stable tag: 1.2.0
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    6060== Changelog ==
    6161
     62= 1.2.0 (25 July 2024) =
     63* Changed: code refactoring
     64* Fixed: general errors
     65* Added: compatibility with SimpleForm 2.2.0 version
     66
    6267= 1.1.2 (20 April 2022) =
    6368* Fixed: missing control on recaptcha_threshold setting in form submitted without AJAX
     
    7681== Demo ==
    7782 
    78 You don’t know SimpleForm yet? Check out our [Demo](https://wpsform.com/demo/) and find out how it works.
     83You don’t know SimpleForm yet? Check out our [Demo]() and find out how it works.
    7984
    8085== Upgrade Notice ==
  • simpleform-recaptcha/trunk/admin/index.php

    r2468921 r3125319  
    1 <?php // Silence is golden
     1<?php
     2/**
     3 * Silence is golden.
     4 *
     5 * @package SimpleForm reCAPTCHA/admin
     6 */
  • simpleform-recaptcha/trunk/admin/js/admin.js

    r2537040 r3125319  
     1/**
     2 * JavaScript code delegated to the backend functionality of the plugin.
     3 *
     4 * @package SimpleForm reCAPTCHA
     5 * @subpackage SimpleForm reCAPTCHA/admin
     6 */
     7
    18(function( $ ) {
    29    'use strict';
    3    
    4      $( window ).load(function() {
    510
    6        $("#math-captcha").on("click", function() { $('.trcaptcha.clabel').removeClass('unseen'); });
    7        $("#google-captcha").on("click", function() { $('.trcaptcha.clabel').addClass('unseen'); });
    8        
    9        $('#captcha-field').on('change', function () {
    10          var selectVal = $("#captcha-field option:selected").val();
    11          if ( selectVal == 'hidden' ) { $('.trcaptcha').addClass('unseen'); }
    12          else {
    13              $('.trcaptcha').removeClass('unseen');
    14               if ( $('#math-captcha').prop('checked') == true || sform_recaptcha_object.usage == 'off' ) { $('.trcaptcha.clabel').removeClass('unseen'); }
    15               else { $('.trcaptcha.clabel').addClass('unseen');
    16               }
    17          }
    18        });         
     11    $( window ).on(
     12        'load',
     13        function() {
    1914
    20        $('#recaptcha').on("click", function() {
    21          if($(this).prop('checked') == true ) {
    22              $('#tdrecaptcha').removeClass('last');         
    23              $('.trrecaptcha').removeClass('unseen');
    24              if ( $('#v2-checkbox').prop('checked') == true ) {
    25                   $('.trrecaptcha.style').removeClass('unseen');
    26                   $('.trrecaptcha.badge').addClass('unseen');
    27                   $('.trrecaptcha.threshold').addClass('unseen');
    28                   $('.trrecaptcha.usage').addClass('unseen');
    29              } else {
    30                   $('.trrecaptcha.style').addClass('unseen');
    31                   $('.trrecaptcha.badge').removeClass('unseen');
    32                   if ( $('#v3').prop('checked') == true ) {
    33                   $('.trrecaptcha.threshold').removeClass('unseen');
    34                   } else {
    35                   $('.trrecaptcha.threshold').addClass('unseen');                     
    36                   }
    37                  
    38                  if($('#recaptcha-badge').prop('checked') == true ) {
    39                  $('#thbadge, #tdbadge').removeClass('last');         
    40                  $('.trrecaptcha.usage').removeClass('unseen');
    41                  } else {
    42                  $('#thbadge, #tdbadge').addClass('last');         
    43                  $('.trrecaptcha.usage').addClass('unseen');
    44                  }
    45              }
    46          }
    47          else {
    48              $('.trrecaptcha').addClass('unseen');
    49              $('#tdrecaptcha').addClass('last');         
    50          }
    51        });
     15            $( '#math-captcha' ).on(
     16                'click',
     17                function() {
     18                    $( '.trcaptcha.clabel' ).removeClass( 'unseen' );
     19                }
     20            );
    5221
    53        $("#v2-checkbox").on("click", function() { $("span.rctype").html(sform_recaptcha_object.v2); $('.trrecaptcha.style, .trrecaptcha.v2').removeClass('unseen'); $('.trrecaptcha.threshold, .trrecaptcha.badge, .trrecaptcha.usage').addClass('unseen'); });
    54        $("#v2-invisible").on("click", function() { $("span.rctype").html(sform_recaptcha_object.v2i); $('.trrecaptcha.badge').removeClass('unseen'); $('.trrecaptcha.threshold, .trrecaptcha.style, .trrecaptcha.v2').addClass('unseen');
    55            
    56          if($('#recaptcha-badge').prop('checked') == true ) {
    57              $('#thbadge, #tdbadge').removeClass('last');         
    58              $('.trrecaptcha.usage').removeClass('unseen');
    59          }
    60          else {
    61              $('#thbadge, #tdbadge').addClass('last');         
    62              $('.trrecaptcha.usage').addClass('unseen');
    63          }
    64            
    65        });
    66        $("#v3").on("click", function() { $("span.rctype").html(sform_recaptcha_object.v3); $('.trrecaptcha.threshold, .trrecaptcha.badge').removeClass('unseen'); $('.trrecaptcha.style, .trrecaptcha.v2').addClass('unseen');
    67            
    68          if($('#recaptcha-badge').prop('checked') == true ) {
    69              $('#thbadge, #tdbadge').removeClass('last');         
    70              $('.trrecaptcha.usage').removeClass('unseen');
    71          }
    72          else {
    73              $('#thbadge, #tdbadge').addClass('last');         
    74              $('.trrecaptcha.usage').addClass('unseen');
    75          }
    76            
    77        });
     22            $( '#google-captcha' ).on(
     23                'click',
     24                function() {
     25                    $( '.trcaptcha.clabel' ).addClass( 'unseen' );
     26                }
     27            );
    7828
    79        $('#recaptcha-badge').on("click", function() {
    80          if($(this).prop('checked') == true ) {
    81              $('#thbadge, #tdbadge').removeClass('last');         
    82              $('.trrecaptcha.usage').removeClass('unseen');
    83          }
    84          else {
    85              $('#thbadge, #tdbadge').addClass('last');         
    86              $('.trrecaptcha.usage').addClass('unseen');
    87          }
    88        });         
     29            $( '#captcha_field' ).on(
     30                'change',
     31                function() {
     32                    var selectVal = $( '#captcha_field option:selected' ).val();
     33                    if ( selectVal == 'hidden' ) {
     34                        $( '.trcaptcha' ).addClass( 'unseen' );
     35                    } else {
     36                        $( '.trcaptcha' ).removeClass( 'unseen' );
     37                        if ( $( '#math-captcha' ).prop( 'checked' ) == true ) {
     38                            $( '.trcaptcha.clabel' ).removeClass( 'unseen' );
     39                        } else {
     40                            $( '.trcaptcha.clabel' ).addClass( 'unseen' );
     41                        }
     42                    }
     43                }
     44            );
    8945
    90      });
     46            $( '#recaptcha' ).on(
     47                'click',
     48                function() {
     49                    if ( $( this ).prop( 'checked' ) == true ) {
     50                        $( '#tdrecaptcha' ).removeClass( 'last' );
     51                        $( '.trrecaptcha' ).removeClass( 'unseen' );
     52                        if ( $( '#v2-checkbox' ).prop( 'checked' ) == true ) {
     53                            $( '.trrecaptcha.style' ).removeClass( 'unseen' );
     54                            $( '.trrecaptcha.badge' ).addClass( 'unseen' );
     55                            $( '.trrecaptcha.threshold' ).addClass( 'unseen' );
     56                            $( '.trrecaptcha.usage' ).addClass( 'unseen' );
     57                        } else {
     58                            $( '.trrecaptcha.style' ).addClass( 'unseen' );
     59                            $( '.trrecaptcha.badge' ).removeClass( 'unseen' );
     60                            if ( $( '#v3' ).prop( 'checked' ) == true ) {
     61                                $( '.trrecaptcha.threshold' ).removeClass( 'unseen' );
     62                            } else {
     63                                $( '.trrecaptcha.threshold' ).addClass( 'unseen' );
     64                            }
     65                            if ( $( '#recaptcha-badge' ).prop( 'checked' ) == true ) {
     66                                $( '#thbadge, #tdbadge' ).removeClass( 'last' );
     67                                $( '.trrecaptcha.usage' ).removeClass( 'unseen' );
     68                            } else {
     69                                $( '#thbadge, #tdbadge' ).addClass( 'last' );
     70                                $( '.trrecaptcha.usage' ).addClass( 'unseen' );
     71                            }
     72                        }
     73                    } else {
     74                        $( '.trrecaptcha' ).addClass( 'unseen' );
     75                        $( '#tdrecaptcha' ).addClass( 'last' );
     76                    }
     77                }
     78            );
     79
     80            $( '#v2-checkbox' ).on(
     81                'click',
     82                function() {
     83                    $( 'span.rctype' ).html( sform_recaptcha_object.v2 );
     84                    $( '.trrecaptcha.style, .trrecaptcha.v2' ).removeClass( 'unseen' );
     85                    $( '.trrecaptcha.threshold, .trrecaptcha.badge, .trrecaptcha.usage' ).addClass( 'unseen' );
     86                }
     87            );
     88
     89            $( '#v2-invisible' ).on(
     90                'click',
     91                function() {
     92                    $( 'span.rctype' ).html( sform_recaptcha_object.v2i );
     93                    $( '.trrecaptcha.badge' ).removeClass( 'unseen' );
     94                    $( '.trrecaptcha.threshold, .trrecaptcha.style, .trrecaptcha.v2' ).addClass( 'unseen' );
     95                    if ( $( '#recaptcha-badge' ).prop( 'checked' ) == true ) {
     96                        $( '#thbadge, #tdbadge' ).removeClass( 'last' );
     97                        $( '.trrecaptcha.usage' ).removeClass( 'unseen' );
     98                    } else {
     99                        $( '#thbadge, #tdbadge' ).addClass( 'last' );
     100                        $( '.trrecaptcha.usage' ).addClass( 'unseen' );
     101                    }
     102                }
     103            );
     104
     105            $( '#v3' ).on(
     106                'click',
     107                function() {
     108                    $( 'span.rctype' ).html( sform_recaptcha_object.v3 );
     109                    $( '.trrecaptcha.threshold, .trrecaptcha.badge' ).removeClass( 'unseen' );
     110                    $( '.trrecaptcha.style, .trrecaptcha.v2' ).addClass( 'unseen' );
     111                    if ( $( '#recaptcha-badge' ).prop( 'checked' ) == true ) {
     112                        $( '#thbadge, #tdbadge' ).removeClass( 'last' );
     113                        $( '.trrecaptcha.usage' ).removeClass( 'unseen' );
     114                    } else {
     115                        $( '#thbadge, #tdbadge' ).addClass( 'last' );
     116                        $( '.trrecaptcha.usage' ).addClass( 'unseen' );
     117                    }
     118                }
     119            );
     120
     121            $( '#recaptcha-badge' ).on(
     122                'click',
     123                function() {
     124                    if ( $( this ).prop( 'checked' ) == true ) {
     125                        $( '#thbadge, #tdbadge' ).removeClass( 'last' );
     126                        $( '.trrecaptcha.usage' ).removeClass( 'unseen' );
     127                    } else {
     128                        $( '#thbadge, #tdbadge' ).addClass( 'last' );
     129                        $( '.trrecaptcha.usage' ).addClass( 'unseen' );
     130                    }
     131                }
     132            );
     133
     134        }
     135    );
    91136
    92137})( jQuery );
  • simpleform-recaptcha/trunk/includes/index.php

    r2468921 r3125319  
    1 <?php // Silence is golden
     1<?php
     2/**
     3 * Silence is golden.
     4 *
     5 * @package SimpleForm reCAPTCHA/includes
     6 */
  • simpleform-recaptcha/trunk/index.php

    r2468921 r3125319  
    1 <?php // Silence is golden
     1<?php
     2/**
     3 * Silence is golden.
     4 *
     5 * @package SimpleForm reCAPTCHA
     6 */
  • simpleform-recaptcha/trunk/simpleform-recaptcha.php

    r2712286 r3125319  
    11<?php
    2 
    32/**
    43 *
    5  * Plugin Name:  SimpleForm reCAPTCHA
    6  * Description:  Stop Bot Spam! This SimpleForm addon allows you to require users to confirm that they are not a robot by completing the Google reCAPTCHA.
    7  * Version:      1.1.2
    8  * Author:       WPSForm Team
    9  * Author URI:   https://wpsform.com
    10  * License:      GPL-2.0+
    11  * License URI:  http://www.gnu.org/licenses/gpl-2.0.txt
    12  * Text Domain:  simpleform-recaptcha
    13  * Domain Path:  /languages
     4 * Plugin Name:       SimpleForm reCAPTCHA
     5 * Description:       Stop Bot Spam! This SimpleForm addon allows you to require users to confirm that they are not a robot by completing the Google reCAPTCHA.
     6 * Version:           1.2.0
     7 * Requires at least: 5.9
     8 * Requires PHP:      7.4
     9 * Author:            SimpleForm Team
     10 * License:           GPL-2.0+
     11 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
     12 * Text Domain:       simpleform-recaptcha
     13 * Requires Plugins:  simpleform
    1414 *
     15 * @package           SimpleForm reCAPTCHA
    1516 */
    1617
    17 if ( ! defined( 'WPINC' ) ) { die; }
     18defined( 'WPINC' ) || exit;
    1819
    1920/**
    2021 * Plugin constants.
    2122 *
    22  * @since    1.0
     23 * @since 1.0.0
    2324 */
    24  
    25 define( 'SIMPLEFORM_RECAPTCHA_NAME', 'SimpleForm reCAPTCHA' );
    26 define( 'SIMPLEFORM_RECAPTCHA_VERSION', '1.1.2' );
    27 define( 'SIMPLEFORM_RECAPTCHA_DB_VERSION', '1.0' );
     25
     26define( 'SIMPLEFORM_RECAPTCHA_NAME', 'SimpleForm reCAPTCHA' );
     27define( 'SIMPLEFORM_RECAPTCHA_VERSION', '1.2.0' );
    2828define( 'SIMPLEFORM_RECAPTCHA_BASENAME', plugin_basename( __FILE__ ) );
    2929define( 'SIMPLEFORM_RECAPTCHA_PATH', plugin_dir_path( __FILE__ ) );
    30 define( 'SIMPLEFORM_REQUIRED_VERSION_FOR_RECAPTCHA', '2.1.7' );
     30if ( ! defined( 'SIMPLEFORM_VERSION_REQUIRED' ) ) {
     31    define( 'SIMPLEFORM_VERSION_REQUIRED', '2.2.0' );
     32}
    3133
    3234/**
    3335 * The code that runs during plugin activation.
    3436 *
    35  * @since    1.0
     37 * @since 1.0.0
     38 *
     39 * @param bool $network_wide Whether to enable the plugin for all sites in the network
     40 *                           or just the current site. Multisite only. Default false.
     41 *
     42 * @return void
    3643 */
    37  
    38 function activate_simpleform_recaptcha($network_wide) {
    39     require_once plugin_dir_path( __FILE__ ) . 'includes/class-activator.php';
    40     SimpleForm_reCaptcha_Activator::activate($network_wide);
     44function activate_simpleform_recaptcha( $network_wide ) {
     45    require_once plugin_dir_path( __FILE__ ) . 'includes/class-simpleform-recaptcha-activator.php';
     46    SimpleForm_ReCaptcha_Activator::activate( $network_wide );
    4147}
    4248
    43 /** 
    44  * Change settings when a new site into a network is created.
     49/**
     50 * Edit settings when a new site into a network is created.
    4551 *
    46  * @since    1.0
    47  */
    48 
    49 function simpleform_recaptcha_on_create_blog($params) {
    50     require_once plugin_dir_path( __FILE__ ) . 'includes/class-activator.php';
    51     SimpleForm_reCaptcha_Activator::on_create_blog($params);
     52 * @since 1.0.0
     53 *
     54 * @param WP_Site $new_site New site object.
     55 *
     56 * @return void
     57 */
     58function simpleform_recaptcha_network( $new_site ) {
     59    require_once plugin_dir_path( __FILE__ ) . 'includes/class-simpleform-recaptcha-activator.php';
     60    SimpleForm_ReCaptcha_Activator::on_create_blog( $new_site );
    5261}
    5362
    54 add_action( 'wp_insert_site', 'simpleform_recaptcha_on_create_blog');
     63add_action( 'wp_insert_site', 'simpleform_recaptcha_network' );
    5564
    5665/**
    5766 * The code that runs during plugin deactivation.
    5867 *
    59  * @since    1.0
     68 * @since 1.0.0
     69 *
     70 * @return void
    6071 */
    61  
    6272function deactivate_simpleform_recaptcha() {
    63     require_once plugin_dir_path( __FILE__ ) . 'includes/class-deactivator.php';
    64     SimpleForm_reCaptcha_Deactivator::deactivate();
     73    require_once plugin_dir_path( __FILE__ ) . 'includes/class-simpleform-recaptcha-deactivator.php';
     74    SimpleForm_ReCaptcha_Deactivator::deactivate();
    6575}
    6676
     
    7181 * The core plugin class.
    7282 *
    73  * @since    1.0
     83 * @since 1.0.0
    7484 */
    75  
    76 require plugin_dir_path( __FILE__ ) . '/includes/class-core.php';
     85
     86require plugin_dir_path( __FILE__ ) . '/includes/class-simpleform-recaptcha.php';
    7787
    7888/**
    7989 * Begins execution of the plugin.
    8090 *
    81  * @since    1.0
     91 * @since 1.0.0
     92 *
     93 * @return void
    8294 */
    83  
    84 function run_SimpleForm_reCaptcha() {
     95function run_simpleform_recaptcha() {
    8596
    86     $plugin = new SimpleForm_reCaptcha();
     97    $plugin = new SimpleForm_ReCaptcha();
    8798    $plugin->run();
    88 
    8999}
    90100
    91 run_SimpleForm_reCaptcha();
     101run_simpleform_recaptcha();
  • simpleform-recaptcha/trunk/uninstall.php

    r2508149 r3125319  
    11<?php
    2 
    32/**
    4  * Fired when the plugin is uninstalled.
     3 * File delegated to the uninstalling the plugin.
    54 *
    6  * @since      1.0
     5 * @package SimpleForm reCAPTCHA
    76 */
    87
    9 // Prevent direct access. Exit if file is not called by WordPress.
    10 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
    11     exit;
     8defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
     9
     10// Detect the simpleform plugin installation.
     11$plugin_file = defined( 'WP_PLUGIN_DIR' ) ? WP_PLUGIN_DIR . '/simpleform/simpleform.php' : '';
     12
     13if ( file_exists( $plugin_file ) ) {
     14
     15    global $wpdb;
     16
     17    if ( ! is_multisite() ) {
     18
     19        $settings         = (array) get_option( 'sform_settings', array() );
     20        $attributes       = (array) get_option( 'sform_attributes', array() );
     21        $shortcodes_table = $wpdb->prefix . 'sform_shortcodes';
     22
     23        if ( $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $shortcodes_table ) ) === $shortcodes_table ) { // phpcs:ignore         
     24            $forms = $wpdb->get_col( "SELECT id FROM {$wpdb->prefix}sform_shortcodes WHERE id != '1'" ); // phpcs:ignore
     25        } else {
     26            $forms = array();
     27        }
     28
     29        // Detect the parent plugin activation.
     30        if ( $settings ) {
     31
     32            $addon_settings = array(
     33                'recaptcha'            => $settings['recaptcha'],
     34                'recaptcha_type'       => $settings['recaptcha_type'],
     35                'recaptcha_site_key'   => $settings['recaptcha_site_key'],
     36                'recaptcha_secret_key' => $settings['recaptcha_secret_key'],
     37                'recaptcha_threshold'  => $settings['recaptcha_threshold'],
     38                'recaptcha_style'      => $settings['recaptcha_style'],
     39                'recaptcha_badge'      => $settings['recaptcha_badge'],
     40                'unverified_recaptcha' => $settings['unverified_recaptcha'],
     41                'expired_recaptcha'    => $settings['expired_recaptcha'],
     42                'invalid_recaptcha'    => $settings['invalid_recaptcha'],
     43            );
     44
     45            $new_settings = array_diff_key( $settings, $addon_settings );
     46            update_option( 'sform_settings', $new_settings );
     47
     48            foreach ( $forms as $form ) {
     49
     50                $form_settings = (array) get_option( 'sform_' . $form . '_settings', array() );
     51
     52                if ( $form_settings ) {
     53
     54                    $addon_settings = array(
     55                        'recaptcha'            => $form_settings['recaptcha'],
     56                        'recaptcha_type'       => $form_settings['recaptcha_type'],
     57                        'recaptcha_site_key'   => $form_settings['recaptcha_site_key'],
     58                        'recaptcha_secret_key' => $form_settings['recaptcha_secret_key'],
     59                        'recaptcha_threshold'  => $form_settings['recaptcha_threshold'],
     60                        'recaptcha_style'      => $form_settings['recaptcha_style'],
     61                        'recaptcha_badge'      => $form_settings['recaptcha_badge'],
     62                        'unverified_recaptcha' => $form_settings['unverified_recaptcha'],
     63                        'expired_recaptcha'    => $form_settings['expired_recaptcha'],
     64                        'invalid_recaptcha'    => $form_settings['invalid_recaptcha'],
     65                    );
     66
     67                    $new_form_settings = array_diff_key( $form_settings, $addon_settings );
     68                    update_option( 'sform_' . $form . '_settings', $new_form_settings );
     69
     70                }
     71            }
     72        }
     73
     74        if ( $attributes ) {
     75
     76            $addon_attributes = array(
     77                'captcha_type' => $attributes['captcha_type'],
     78            );
     79
     80            $new_attributes = array_diff_key( $attributes, $addon_attributes );
     81            update_option( 'sform_attributes', $new_attributes );
     82
     83            foreach ( $forms as $form ) {
     84
     85                $form_attributes = (array) get_option( 'sform_' . $form . '_attributes', array() );
     86
     87                if ( $form_attributes ) {
     88
     89                    $addon_attributes = array(
     90                        'captcha_type' => $form_attributes['captcha_type'],
     91                    );
     92
     93                    $new_form_attributes = array_diff_key( $form_attributes, $addon_attributes );
     94                    update_option( 'sform_' . $form . '_attributes', $new_form_attributes );
     95
     96                }
     97            }
     98        }
     99    } else {
     100
     101        $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); // phpcs:ignore
     102        $original_blog_id = get_current_blog_id();
     103
     104        foreach ( $blog_ids as $blogid ) {
     105
     106            switch_to_blog( $blogid );
     107            $settings         = (array) get_option( 'sform_settings', array() );
     108            $attributes       = (array) get_option( 'sform_attributes', array() );
     109            $shortcodes_table = $wpdb->prefix . 'sform_shortcodes';
     110
     111            if ( $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $shortcodes_table ) ) === $shortcodes_table ) { // phpcs:ignore
     112                $forms      = $wpdb->get_col( "SELECT id FROM {$wpdb->prefix}sform_shortcodes WHERE id != '1'" ); // phpcs:ignore
     113            } else {
     114                $forms = array();
     115            }
     116
     117            // Detect the parent plugin activation.
     118            if ( $settings ) {
     119
     120                $addon_settings = array(
     121                    'recaptcha'            => $settings['recaptcha'],
     122                    'recaptcha_type'       => $settings['recaptcha_type'],
     123                    'recaptcha_site_key'   => $settings['recaptcha_site_key'],
     124                    'recaptcha_secret_key' => $settings['recaptcha_secret_key'],
     125                    'recaptcha_threshold'  => $settings['recaptcha_threshold'],
     126                    'recaptcha_style'      => $settings['recaptcha_style'],
     127                    'recaptcha_badge'      => $settings['recaptcha_badge'],
     128                    'unverified_recaptcha' => $settings['unverified_recaptcha'],
     129                    'expired_recaptcha'    => $settings['expired_recaptcha'],
     130                    'invalid_recaptcha'    => $settings['invalid_recaptcha'],
     131                );
     132
     133                $new_settings = array_diff_key( $settings, $addon_settings );
     134                update_option( 'sform_settings', $new_settings );
     135
     136                foreach ( $forms as $form ) {
     137
     138                    $form_settings = (array) get_option( 'sform_' . $form . '_settings', array() );
     139
     140                    if ( $form_settings ) {
     141
     142                        $addon_settings = array(
     143                            'recaptcha'            => $form_settings['recaptcha'],
     144                            'recaptcha_type'       => $form_settings['recaptcha_type'],
     145                            'recaptcha_site_key'   => $form_settings['recaptcha_site_key'],
     146                            'recaptcha_secret_key' => $form_settings['recaptcha_secret_key'],
     147                            'recaptcha_threshold'  => $form_settings['recaptcha_threshold'],
     148                            'recaptcha_style'      => $form_settings['recaptcha_style'],
     149                            'recaptcha_badge'      => $form_settings['recaptcha_badge'],
     150                            'unverified_recaptcha' => $form_settings['unverified_recaptcha'],
     151                            'expired_recaptcha'    => $form_settings['expired_recaptcha'],
     152                            'invalid_recaptcha'    => $form_settings['invalid_recaptcha'],
     153                        );
     154
     155                        $new_form_settings = array_diff_key( $form_settings, $addon_settings );
     156                        update_option( 'sform_' . $form . '_settings', $new_form_settings );
     157
     158                    }
     159                }
     160            }
     161
     162            if ( $attributes ) {
     163
     164                $addon_attributes = array(
     165                    'captcha_type' => $attributes['captcha_type'],
     166                );
     167
     168                $new_attributes = array_diff_key( $attributes, $addon_attributes );
     169                update_option( 'sform_attributes', $new_attributes );
     170
     171                foreach ( $forms as $form ) {
     172
     173                    $form_attributes = (array) get_option( 'sform_' . $form . '_attributes', array() );
     174
     175                    if ( $form_attributes ) {
     176
     177                        $addon_attributes = array(
     178                            'captcha_type' => $form_attributes['captcha_type'],
     179                        );
     180
     181                        $new_form_attributes = array_diff_key( $form_attributes, $addon_attributes );
     182                        update_option( 'sform_' . $form . '_attributes', $new_form_attributes );
     183
     184                    }
     185                }
     186            }
     187        }
     188
     189        switch_to_blog( $original_blog_id );
     190
     191    }
     192} else {
     193
     194    global $wpdb;
     195    $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'sform_submissions' ); // phpcs:ignore
     196    $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'sform_shortcodes' ); // phpcs:ignore
     197    $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'sform\_%'" ); // phpcs:ignore
     198    $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'sform\-%'" ); // phpcs:ignore
     199    $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '%\_sform\_%'" ); // phpcs:ignore
     200
    12201}
    13 
    14 // Detect core plugin
    15 $plugin_file = 'simpleform/simpleform.php';
    16 if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_file ) ) {
    17 
    18  if ( !is_multisite() )  {
    19   $settings = get_option('sform_settings');
    20   global $wpdb;
    21   $shortcodes_table = $wpdb->prefix . 'sform_shortcodes';
    22   $ids = $wpdb->get_col("SELECT id FROM `$shortcodes_table` WHERE id != '1'"); 
    23   if ( $settings ) {
    24   $sform_addon_settings = array( 'recaptcha' => $settings['recaptcha'], 'recaptcha_type' => $settings['recaptcha_type'], 'recaptcha_site_key' => $settings['recaptcha_site_key'], 'recaptcha_secret_key' => $settings['recaptcha_secret_key'], 'recaptcha_threshold' => $settings['recaptcha_threshold'], 'recaptcha_style' => $settings['recaptcha_style'], 'recaptcha_badge' => $settings['recaptcha_badge'], 'recaptcha_notice' => $settings['recaptcha_notice'], 'unverified_recaptcha' => $settings['unverified_recaptcha'], 'expired_recaptcha' => $settings['expired_recaptcha'], 'invalid_recaptcha' => $settings['invalid_recaptcha'] );
    25   $sform_core_settings = array_diff_key($settings,$sform_addon_settings);
    26   update_option('sform_settings', $sform_core_settings);
    27   if ( $ids ) {
    28     foreach ( $ids as $id ) {
    29     $form_settings = get_option('sform_'.$id.'_settings');
    30     if ( $form_settings != false ) {
    31        $form_settings_nv = array_diff_key($form_settings,$sform_addon_settings);
    32        update_option('sform_'.$id.'_settings', $form_settings_nv);
    33     }
    34     }
    35   }
    36   }
    37   $attributes = get_option('sform_attributes');
    38   if ( $attributes ) {
    39   $sform_addon_attributes = array( 'captcha_type' => $attributes['captcha_type'] );
    40   $sform_core_attributes = array_diff_key($attributes,$sform_addon_attributes);
    41   update_option('sform_attributes', $sform_core_attributes);
    42   }
    43   if ( $ids ) {
    44     foreach ( $ids as $id ) {
    45     $form_attributes = get_option('sform_'.$id.'_attributes');
    46     if ( $form_attributes != false ) {
    47        $sform_addon_attributes = array( 'captcha_type' => $form_attributes['captcha_type'] );
    48        $form_attributes_nv = array_diff_key($form_attributes,$sform_addon_attributes);
    49        update_option('sform_'.$id.'_attributes', $form_attributes_nv);
    50     }
    51     }
    52   }
    53   }
    54 
    55  else {
    56     global $wpdb;
    57     $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
    58     $original_blog_id = get_current_blog_id();
    59     foreach ( $blog_ids as $blog_id ) {
    60       switch_to_blog( $blog_id );
    61       $settings = get_option('sform_settings');
    62       if ( $settings ) {
    63         $sform_addon_settings = array( 'recaptcha' => $settings['recaptcha'], 'recaptcha_type' => $settings['recaptcha_type'], 'recaptcha_site_key' => $settings['recaptcha_site_key'], 'recaptcha_secret_key' => $settings['recaptcha_secret_key'], 'recaptcha_threshold' => $settings['recaptcha_threshold'], 'recaptcha_style' => $settings['recaptcha_style'], 'recaptcha_badge' => $settings['recaptcha_badge'], 'recaptcha_notice' => $settings['recaptcha_notice'], 'unverified_recaptcha' => $settings['unverified_recaptcha'], 'expired_recaptcha' => $settings['expired_recaptcha'], 'invalid_recaptcha' => $settings['invalid_recaptcha'] );
    64         $sform_core_settings = array_diff_key($settings,$sform_addon_settings);
    65         update_option('sform_settings', $sform_core_settings);
    66         if ( $ids ) {
    67          foreach ( $ids as $id ) {
    68          $form_settings = get_option('sform_'.$id.'_settings');
    69          if ( $form_settings != false ) {
    70          $form_settings_nv = array_diff_key($form_settings,$sform_addon_settings);
    71          update_option('sform_'.$id.'_settings', $form_settings_nv);
    72          }
    73          }
    74         }
    75       }
    76       $attributes = get_option('sform_attributes');
    77       if ( $attributes ) {
    78         $sform_addon_attributes = array( 'captcha_type' => $settings['captcha_type'] );
    79         $sform_core_attributes = array_diff_key($attributes,$sform_addon_attributes);
    80         update_option('sform_attributes', $sform_core_attributes);
    81       }
    82       if ( $ids ) {
    83         foreach ( $ids as $id ) {
    84         $form_attributes = get_option('sform_'.$id.'_attributes');
    85         if ( $form_attributes != false ) {
    86          $sform_addon_attributes = array( 'captcha_type' => $form_attributes['captcha_type'] );
    87          $form_attributes_nv = array_diff_key($form_attributes,$sform_addon_attributes);
    88          update_option('sform_'.$id.'_attributes', $form_attributes_nv);
    89         }
    90         }
    91       }
    92     }
    93     switch_to_blog( $original_blog_id );
    94  }
    95 }
    96 
    97 else {
    98   global $wpdb;
    99   $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'sform_submissions' );
    100   $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'sform\_%'" );
    101   $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'sform\-%'" );
    102   $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '%\_sform\_%'" );
    103 }
Note: See TracChangeset for help on using the changeset viewer.