Plugin Directory

Changeset 3217889


Ignore:
Timestamp:
01/06/2025 05:35:06 PM (15 months ago)
Author:
sjcope
Message:

recaptcha

Location:
consignment-store-for-woocommerce
Files:
36 added
8 edited

Legend:

Unmodified
Added
Removed
  • consignment-store-for-woocommerce/trunk/README.txt

    r3116667 r3217889  
    33Donate link: https://charlenesweb.ca/donate/
    44Tags: consignment store, consignment for WooCommerce
    5 Requires at least: 6.5.5
    6 Requires PHP: 7.4
    7 Tested up to: 6.6
    8 Stable tag: 1.7.9
     5Requires at least: 6.7.1
     6Requires PHP: 8.0
     7Tested up to: 7.4
     8Stable tag: 1.8
    99License: GPLv2
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    7777
    7878== Changelog ==
     79= 1.8 =
     80* Remove reCaptcha 2 from plugin
     81
    7982= 1.7.9 =
    8083* Go through WP 6.6 compatibility requirements. No changes required.
     
    135138
    136139== Upgrade Notice ==
     140= 1.8 =
     141* Remove reCaptcha 2 from plugin. Update when convenient.
     142
    137143= 1.7.9 =
    138144* Tag update. Update version when convenient.
  • consignment-store-for-woocommerce/trunk/admin/class-cws-consignment-admin.php

    r3022689 r3217889  
    809809            }
    810810        }
    811     }
    812     return $data;
    813 }
    814 
    815 // get the recaptcha site key and secret -- called from ajax fcn to save settings
    816 function cwscsGetRecaptchas($version) {
    817     $myData = cwscsGetSettingByKeyReturnArray($version);
    818     $data = array('version' => $version);
    819     if (is_array($myData)) {
    820         if (isset($myData[0]))
    821             $data['site_key'] = $myData[0];
    822         else
    823             $data['site_key'] = "";
    824         if (isset($myData[1]))
    825             $data['secret'] = $myData[1];
    826         else
    827             $data['secret'] = "";
    828811    }
    829812    return $data;
  • consignment-store-for-woocommerce/trunk/admin/js/cws-consignment-admin.js

    r3051865 r3217889  
    22    'use strict';
    33    $( window ).load(function() {
    4         console.log('TEST: loaded');
    54        // Check item approved status and show appropriate email   
    65        $('.cwscheckapproved').click(function () {
     
    1312                $ ('#rejected-email').addClass("cwshidden");
    1413                $ ('.hideifrejected').removeClass("cwshidden");
    15                 console.log("Removed?")
    1614            } else if (i == 2) { // rejected
    1715                $ ('#approved-email').addClass("cwshidden");
     
    5250                    break;
    5351                case 4:
    54                     var btn_text = "Save reCAPTCHA v2";
    55                     break;
    56                 case 5:
    57                     var btn_text = "Save reCAPTCHA v3";
    58                     break; 
    59                 case 6:
    6052                    var btn_text = "Save Emails";
    6153                    break;
     
    114106                    break;
    115107                case "btnsave_4":
    116                 case "btnsave_5":
    117                     if (thisid == "btnsave_4") {
    118                         var ext = "v2";
    119                         var contentid = "contenttab_4";
    120                         var cwscs_method = "saverecaptchav2";
    121                     } else {
    122                         var ext = "v3";
    123                         var contentid = "contenttab_5";
    124                         var cwscs_method = "saverecaptchav3";
    125                     }
    126                     // allowed to set it to blank
    127                     if (typeof $('#cwscs_version' + ext).val() != "undefined" && typeof $('#cwscs_site_key' + ext).val() != "undefined" && typeof $('#cwscs_secret' + ext).val() != "undefined") {
    128                         var cwscs_value = $('#cwscs_site_key' + ext).val() + '::' + $('#cwscs_secret' + ext).val();
    129                         var cwscs_key = $('#cwscs_version' + ext).val();
    130                     } else {
    131                         var cwscs_key = "";
    132                         var cwscs_value = "";
    133                     }
    134                     break;
    135                 case "btnsave_6":
    136                     var contentid = "contenttab_6";
     108                    var contentid = "contenttab_4";
    137109                    var cwscs_method = "saveemails";
    138110                    var cwscs_key = "emails";
     
    144116                    break; 
    145117                default:
    146                     console.log('TEST: not found');
    147118                    var cwscs_method = "";
    148119                    break;
    149120            }
    150             console.log('TEST: at end and ' + cwscs_key);
    151121            if (cwscs_key == "") {
    152122                $('#cwscs_msg').html('<p class="failmsg">Could not update. Please refresh and try again.</p>');
     
    253223    return ct;
    254224}
    255 // Recaptcha settings
    256 function showRecaptchaSettings(data) {
    257     var ct = "";
    258     var site_key = "";
    259     var secret = "";
    260     var version = "";
    261     var ext = "";
    262     if (data) {
    263         for (var key in data) {
    264             switch (key) {
    265                 case "version":
    266                     if (data[key] == "recaptcha-v2") {
    267                         var ct = '<h3>Google reCAPTCHA v2</h3>';
    268                         var version = "recaptcha-v2";
    269                         var ext = "v2";
    270                     } else if (data[key] == "recaptcha-v3") {
    271                         var ct = '<h3>Google reCAPTCHA v3</h3>';
    272                         var version = "recaptcha-v3";
    273                         var ext = "v3";
    274                     } else {
    275                         var ct = '<h3>Google reCAPTCHA</h3>';
    276                     }
    277                     break;
    278                 case "site_key":
    279                     var site_key = data[key];
    280                     break;
    281                 case "secret":
    282                     var secret = data[key];
    283                     break; 
    284             } // END switch
    285         } // END loop on data
    286     }
    287     ct += '<input type="hidden" name="version" id="cwscs_version' + ext + '" value="' + version + '" /> <p> <label for="cwscs_site_key' + ext + '">Site Key</label><br /> <input type="text" name="cwscs_site_key' + ext + '" id="cwscs_site_key' + ext + '" value="' + site_key + '" style="width:350px"/> </p> <p> <label for="cwscs_secret' + ext + '">Secret</label><br /> <input type="text" name="cwscs_secret" id="cwscs_secret' + ext + '" value="' + secret + '" style="width:350px"/> </p>';
    288     return ct;
    289 }
    290225
    291226// Email settings
     
    310245////////////////////////////////  ADMIN SPINNER  FUNCTIONS  /////////////////////////////////
    311246function startAdminSpinner(title) {
    312     console.log("Start spinner");
    313247    if (!title || title == "") {
    314248        title = "Processing...";
     
    319253function stopAdminSpinner() {
    320254    jQuery('#myoverlay').remove();
    321     console.log('stopped spinner');
    322 }
     255}
  • consignment-store-for-woocommerce/trunk/admin/partials/cws-consignment-admin-display.php

    r3022689 r3217889  
    276276////////////////////////////////////////////////////////////////////////////////////////////
    277277function cwscsShowSettingsMenu($menu_slug, $msg) {
    278     $tabs = array("General", "Categories", "Store Policy", "Store Splits", "Google reCAPTCHA v2", "Google reCAPTCHA v3", "Emails");
     278    $tabs = array("General", "Categories", "Store Policy", "Store Splits", "Emails");
    279279    $icons = array("dashicons-admin-tools", "dashicons-category", "dashicons-edit", "dashicons-chart-pie", "dashicons-admin-generic", "dashicons-admin-generic", "dashicons-email-alt");
    280280    $content = cwscsGetSettingsContent();
     
    283283    <div class="cwscs_tab">';
    284284    foreach ($tabs as $i => $tab) {
    285         if ($i == 0 || $i == 5) { // hide General and recaptcha v3
     285        if ($i == 0 || $i == 5) { // hide General
    286286            echo '
    287287            <button class="cwscs_tablinks cwshidden" id="btntab_'.esc_html($i).'"><span class="dashicons '.esc_html($icons[$i]).'"></span>'.esc_html($tab).'</button>';
     
    341341    $allSplits = cwscsGetAllSplits();
    342342    $content[] = cwscsShowStoreSplits($mySplits, $allSplits);
    343    
    344     // recaptcha v2
    345     $myRecaptcha = cwscsGetSettingByKeyReturnArray("recaptcha-v2");
    346     $content[] = cwscsShowRecaptcha($myRecaptcha, "recaptcha-v2");
    347    
    348     // recaptcha v3
    349     //$myRecaptcha = cwscsGetSettingByKeyReturnArray("recaptcha-v3"); no v3 for now
    350     //$content[] = cwscsShowRecaptcha($myRecaptcha, "recaptcha-v3");
    351     $content[] = "";
    352343   
    353344    // Emails
     
    493484}
    494485
    495 // Display the recaptcha options
    496 function cwscsShowRecaptcha($myRecaptcha, $version) {
    497     // any current values?
    498     $site_key = "";
    499     $secret = "";
    500     if ($version == "recaptcha-v2")
    501         $ext = 'v2';
    502     else
    503         $ext = 'v3';
    504     if (is_array($myRecaptcha)) {
    505         if (isset($myRecaptcha[0]) && $myRecaptcha[0] != "")
    506             $site_key = $myRecaptcha[0];
    507         if (isset($myRecaptcha[1]) && $myRecaptcha[1] != "")
    508             $secret = $myRecaptcha[1];
    509     }
    510     $ct = '
    511     <input type="hidden" name="version" id="cwscs_version'.$ext.'" value="'.$version.'" />
    512     <p>
    513         <label for="cwscs_site_key'.$ext.'">Site Key</label><br />
    514         <input type="text" name="cwscs_site_key" id="cwscs_site_key'.$ext.'" value="'.$site_key.'" style="width:350px"/>
    515     </p>
    516     <p>
    517         <label for="cwscs_secret'.$ext.'">Secret</label><br />
    518         <input type="text" name="cwscs_secret" id="cwscs_secret'.$ext.'" value="'.$secret.'" style="width:350px"/>
    519     </p>';
    520     return $ct;
    521 }
    522486// Show the email settings form
    523487function cwscsShowEmails($emails) {
     
    598562        <li>Store Policy</li>
    599563        <li>Store Splits</li>
    600         <li>Google reCAPTCHA v2</li>
    601564        <li>Emails</li>
    602565    </ol>   
     
    613576    <p>Check which splits to display on the Add Item form. These are only show to Administrators. </p>
    614577    <p>By default, there are 2 splits available. </p>
    615     <h4>Google reCAPTCHA v2</h4>
    616     <p>Enter your site key and secret to enable the Google reCAPTCHA v2 "I am not a robot" checkbox on the Add Item form.</p>
    617578    <h4>Emails</h4>
    618579    <p>Enter the send from email or leave blank to use the WordPress default address.</p>
  • consignment-store-for-woocommerce/trunk/cws-consignment.php

    r3116667 r3217889  
    1717 * Plugin URI:        https://charlenesweb.ca/
    1818 * Description:       Consignment Store for WooCommerce
    19  * Version:           1.7.9
     19 * Version:           1.8
    2020 * Author:            Charlene's Web Services
    2121 * Author URI:        https://charlenesweb.ca/plugins
  • consignment-store-for-woocommerce/trunk/includes/class-cws-consignment.php

    r3116667 r3217889  
    7171            $this->version = PLUGIN_NAME_VERSION;
    7272        } else {
    73             $this->version = '1.7.9';
     73            $this->version = '1.8';
    7474        }
    7575        $this->plugin_name = 'cws-consignment';
  • consignment-store-for-woocommerce/trunk/public/class-cws-consignment-public.php

    r3051874 r3217889  
    9393
    9494        wp_enqueue_script($this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/cws-consignment-public.js', array( 'jquery' ), $this->version, false );
    95        
    96         // do we need the reCaptcha scripts? Check for keys. Do v2 then v3
    97         $myRecaptcha = cwscsGetSettingByKeyReturnArray("recaptcha-v2");
    98         if (isset($myRecaptcha) && is_array($myRecaptcha) && isset($myRecaptcha[0]) && isset($myRecaptcha[1]) && $myRecaptcha[0] != "" && $myRecaptcha[1] != "") {
    99             wp_register_script(
    100                 'cwscs-google-recaptchav2',
    101                 'https://www.google.com/recaptcha/api.js',
    102                 array(),
    103                 $this->version,
    104                 true
    105             );
    106             wp_enqueue_script("cwscs-google-recaptchav2");
    107         }
    108         /* no v3 for now
    109         else { // check for v3
    110             $myRecaptcha = cwscsGetSettingByKeyReturnArray("recaptcha-v3");
    111             if (isset($myRecaptcha) && is_array($myRecaptcha) && isset($myRecaptcha[0]) && isset($myRecaptcha[1]) && $myRecaptcha[0] != "" && $myRecaptcha[1] != "") {
    112                 wp_register_script(
    113                     'cwscs-google-recaptchav3',
    114                     'https://www.google.com/recaptcha/api.js',
    115                     array(),
    116                     $this->version,
    117                     true
    118                 );
    119                 wp_enqueue_script('cwscs-google-recaptchav3', "https://www.google.com/recaptcha/api.js?render=".$myRecaptcha[0]."&ver=".$this->version);
    120             }
    121         }
    122         */
     95
    12396        // for ajax functions
    12497        wp_localize_script(
     
    248221        } // END is logged in
    249222       
    250         // get recaptcha settings - do here since need if submitted
    251         $recaptcha = cwscsGetMyRecaptcha();
    252223        $max_upload_size = wp_max_upload_size();
    253224        $displayMaxSize = $max_upload_size/1000000;
     
    256227            // validate the form before doing anything
    257228            $ok = true;
    258             if (isset($recaptcha) && isset($recaptcha['version']) && $recaptcha['version'] == "v2") {
    259                 if (!isset($_POST['g-recaptcha-response'])) {
    260                     $results = array('status'=>0, 'error'=>'Please check captcha checkbox. ');
    261                     $ok = false;
    262                 } else
    263                     $secret = $recaptcha['secret'];
    264             } else
    265                 $secret = ""; // not in play
     229            $secret = ""; // not in play
    266230            // check sku if admin
    267231            if ($admin && (!isset($_POST['sku']) || $_POST['sku'] == "")) {
     
    516480                    $ct .= '<input type="hidden" name="policy_accepted" id="policy_accepted" value=2 >';
    517481                }
    518                 // recaptcha? save a hidden field if so to help with processing
    519                 $isRc3 = false;
     482
    520483                $disabled = "";
    521                 if (isset($recaptcha) && isset($recaptcha['version'])) {
    522                     if ($recaptcha['version'] == "v2") {
    523                         $ct .= '
    524                         <input type="hidden" name="rc2" id="rc2" value="'.esc_html($recaptcha['site_key']).'" >
    525                         <div class="clear">&nbsp;</div>
    526                         <div class="g-recaptcha" data-sitekey="'.esc_attr($recaptcha['site_key']).'"  data-callback="cc_enableSubmitBtn">></div>
    527       <br/>';
    528                         $disabled = 'disabled="disabled" ';
    529                     }
    530                     /* no recaptcha v3 for now
    531                     elseif ($recaptcha['version'] == "v3") {
    532                         $ct .= '<input type="hidden" name="rc3" id="rc3" value="'.$recaptcha['site_key'].'" >';
    533                         $isRc3 = true;
    534                     }*/
    535                 }
    536484                $ct .= '
    537485                <p id="cwscs_errormsg" class="failmsg cwshidden"></p>
     
    744692    return $results;
    745693}
    746 // Get recaptcha settings, if any
    747 function cwscsGetMyRecaptcha() {
    748     $results = array();
    749    
    750     $myRecaptcha = cwscsGetSettingByKeyReturnArray("recaptcha-v2");
    751     if (isset($myRecaptcha) && is_array($myRecaptcha) && isset($myRecaptcha[0]) && isset($myRecaptcha[1]) && $myRecaptcha[0] != "" && $myRecaptcha[1] != "") {
    752         $results = array("version"=>"v2", "site_key"=>$myRecaptcha[0], "secret"=>$myRecaptcha[1]);
    753     } else { // check for v3
    754         $myRecaptcha = cwscsGetSettingByKeyReturnArray("recaptcha-v3");
    755         if (isset($myRecaptcha) && is_array($myRecaptcha) && isset($myRecaptcha[0]) && isset($myRecaptcha[1]) && $myRecaptcha[0] != "" && $myRecaptcha[1] != "") {
    756             $results = array("version"=>"v3", "site_key"=>$myRecaptcha[0], "secret"=>$myRecaptcha[1]);
    757         }
    758     }
    759     return $results;
    760 }
    761 // validate the additem form including recaptcha
     694
     695// validate the additem form
    762696function cwscsValidateAddItem($secret) {
    763697    $status = 1;
     
    776710        $status = 0;
    777711    }
    778     if ($status == 1 && $secret != "") { // validate recaptcha if in play
    779         if(!isset($_POST['g-recaptcha-response'])){
    780             $error .= 'Please check the the reCaptcha checkbox. ';
    781             $status = 0;
    782         } else {
    783             $captcha = sanitize_text_field($_POST['g-recaptcha-response']);
    784             $ip = $_SERVER['REMOTE_ADDR'];
    785             // post request to server
    786             $url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($secret) .  '&response=' . urlencode($captcha);
    787             //$response = file_get_contents($url);
    788             $response = wp_remote_get($url);
    789             $status = 0; // pessimist
    790             if ( is_array( $response ) && !is_wp_error( $response ) ) {
    791                 $headers = $response['headers']; // array of http header lines
    792                 $body =  wp_remote_retrieve_body( $response ) ; // array of http header lines
    793                 $response_code =  wp_remote_retrieve_response_code( $response );
    794                 if ($response_code == 200) {
    795                     $responseBody = json_decode($body, true);
    796                     if ($responseBody['success'] === true) {
    797                         $status = 1;
    798                     } elseif ($responseBody['error-codes'] && $responseBody['error-codes'][0] == "timeout-or-duplicate") {
    799                         $error = "Your form has expired. Please fill in the form below and click Add Item. ";                   
    800                     } else {
    801                         $error = 'You did not pass the anti-spam check and we cannot accept your submission. ;';
    802                     }
    803                 } else
    804                     $error = 'We could not contact Google to validate the form. Please try again later. ';
    805             } elseif (!is_wp_error( $response )) {
    806                 $error = 'We could not contact Google to validate the form. Please try again later. ';
    807             } else
    808                 $error = 'We could not contact Google to validate the form. Please try again later. ';
    809         }
    810     }
     712
    811713    $results = array('status'=>$status, 'error'=>$error);
    812714    return $results;
  • consignment-store-for-woocommerce/trunk/public/js/cws-consignment-public.js

    r3051874 r3217889  
    4141        }); // END toggledivbyid
    4242       
    43         // Handle additem form submit - if recaptcha v3 then have to intercept
     43        // Handle additem form submit
    4444        $('#cwscs_formadditem').submit(function() {
    4545            cwsStartSpinner("Please wait...") ;
Note: See TracChangeset for help on using the changeset viewer.