Plugin Directory

Changeset 3371971


Ignore:
Timestamp:
10/02/2025 07:10:08 PM (5 months ago)
Author:
finalwebsites
Message:

Cookie update, fix for submissions

Location:
fw-integration-for-emailoctopus
Files:
22 added
4 edited

Legend:

Unmodified
Added
Removed
  • fw-integration-for-emailoctopus/trunk/fw-integration-for-emailoctopus.php

    r3260135 r3371971  
    22/*
    33Plugin Name: EO4WP: EmailOctopus for WordPress
    4 Version: 1.0.8.6
     4Version: 1.0.10
    55Plugin URI: https://www.finalwebsites.com/emailoctopus-for-wordpress/
    66Description: Increase the count of new subscribers for your blog or website by using EmailOctopus and this integration plugin.
     
    3131
    3232define('FWEO_DIR', plugin_dir_path( __FILE__ ));
    33 define('FW_EO_VER', '1.0.8.6');
     33define('FW_EO_VER', '1.0.10');
    3434
    3535include_once FWEO_DIR.'include/options.php';
     
    8080        add_action( 'wp_ajax_nopriv_emailoctopus_subscribeform_action', array($this, 'subform_action_callback') );
    8181
    82         add_action( 'wp_ajax_eo_loadtime', array($this, 'subform_loadtime_callback' ));
    83         add_action( 'wp_ajax_nopriv_eo_loadtime', array($this, 'subform_loadtime_callback' ));
    84 
    8582        if ( class_exists( 'WooCommerce') ) {
    8683
     
    9794        }
    9895    }
     96
     97
     98   
    9999
    100100    public function load_admin_style() {
     
    289289    }
    290290
    291     public function subform_loadtime_callback() {
    292         if (isset($_COOKIE['eosub_loadtime'])) {
    293             return;
    294         } else {
    295             if (isset($_SERVER['HTTP_HOST'])) {
    296                 $host = sanitize_text_field( wp_unslash($_SERVER['HTTP_HOST']) );
    297                 setcookie("eosub_loadtime", time(), 0, '/', $host);
    298             }
    299         }
    300     }
    301 
    302 
    303291    public function subform_action_callback() {
    304292        $error = '';
     
    313301            } else {
    314302                $valid_captcha = true;
     303   
    315304                if (empty($_COOKIE['eosub_loadtime']) || (int)$_COOKIE['eosub_loadtime'] > (time()-15)) {
     305
    316306                    $valid_captcha = false;
    317307                    $error = __( 'Invalid form submission, please try again.', 'fw-integration-for-emailoctopus' );
  • fw-integration-for-emailoctopus/trunk/include/class-woo-emailoctopus-integration.php

    r3260135 r3371971  
    160160    public function add_subscriber_callback( $order_id, $old_status, $new_status ) {
    161161
    162         $subscribed = get_post_meta($order_id, 'fweo_emailoctopus_subscribed', true);
    163         if ($subscribed == 'subscribed') return; // don't subscribe again if the order status is changed
    164         $order = wc_get_order( $order_id );
    165         if (!in_array($new_status, array('completed', 'processing'))) return;
    166 
    167         $settings = get_option('woocommerce_fws-woo-emailoctopus_settings');
    168         $billing_email  = $order->get_billing_email();
    169         $first_name = $order->get_billing_first_name();
    170         $last_name = $order->get_billing_last_name();
    171 
    172         if (function_exists('pll_get_post_language')) {
    173             $language = pll_get_post_language($order_id);
    174         }
    175        
    176         $tags = array();
    177         if (isset($settings['em_store_categories']) && $settings['em_store_categories'] == 'yes') {
    178             $categs = $this->get_product_categories($order);
    179             $tags = $categs;
    180         }
    181         if (isset($settings['em_store_used_coupon']) && $settings['em_store_used_coupon'] == 'yes') {
    182             $coupons = $order->get_coupon_codes();
    183             if (count($coupons) > 0) {
    184                 $tags[] = 'coupon';
    185             }
    186         }
    187         if ($subscribed == 'checked') {
    188             $tags[] = 'newsletter';
    189         }
    190 
    191        
    192         $fields = array('FirstName' => $first_name, 'LastName' => $last_name);
    193 
    194         if (isset($settings['em_send_language']) && $settings['em_send_language'] == 'yes' && !empty($language)) {
    195             $fields['Language'] = $language;
    196         }
    197         if (isset($settings['em_store_last_purchase']) && $settings['em_store_last_purchase'] == 'yes') {
    198             $fields['LastPurchase'] = gmdate('Y-m-d');
    199         }
    200         if (count($tags) > 0) $fields['tags'] = implode(',', $tags);
    201        
    202         $handler = new FWEO_EmailOctopus_integration();
    203        
    204         $response = $handler->add_subscriber($billing_email, $settings['list'], $fields, true);
    205 
    206         if (isset($response['error']['code'])) {
    207             $order->add_order_note('EmailOctopus error: '. $response['error']['message']);
    208         } else {
    209             $order->add_order_note( $billing_email.' added to the mailing list');
    210             update_post_meta( $order_id, 'fweo_emailoctopus_subscribed', 'subscribed');
     162        if ($subscribed = get_post_meta($order_id, 'fweo_emailoctopus_subscribed', true)) {
     163            if ($subscribed == 'subscribed') return; // don't subscribe again if the order status is changed
     164            $order = wc_get_order( $order_id );
     165            if (!in_array($new_status, array('completed', 'processing'))) return;
     166
     167            $settings = get_option('woocommerce_fws-woo-emailoctopus_settings');
     168            $billing_email  = $order->get_billing_email();
     169            $first_name = $order->get_billing_first_name();
     170            $last_name = $order->get_billing_last_name();
     171
     172            if (function_exists('pll_get_post_language')) {
     173                $language = pll_get_post_language($order_id);
     174            }
     175           
     176            $tags = array();
     177            if (isset($settings['em_store_categories']) && $settings['em_store_categories'] == 'yes') {
     178                $categs = $this->get_product_categories($order);
     179                $tags = $categs;
     180            }
     181            if (isset($settings['em_store_used_coupon']) && $settings['em_store_used_coupon'] == 'yes') {
     182                $coupons = $order->get_coupon_codes();
     183                if (count($coupons) > 0) {
     184                    $tags[] = 'coupon';
     185                }
     186            }
     187            if ($subscribed == 'checked') {
     188                $tags[] = 'newsletter';
     189            }
     190
     191           
     192            $fields = array('FirstName' => $first_name, 'LastName' => $last_name);
     193
     194            if (isset($settings['em_send_language']) && $settings['em_send_language'] == 'yes' && !empty($language)) {
     195                $fields['Language'] = $language;
     196            }
     197            if (isset($settings['em_store_last_purchase']) && $settings['em_store_last_purchase'] == 'yes') {
     198                $fields['LastPurchase'] = gmdate('Y-m-d');
     199            }
     200            if (count($tags) > 0) $fields['tags'] = implode(',', $tags);
     201           
     202            $handler = new FWEO_EmailOctopus_integration();
     203           
     204            $response = $handler->add_subscriber($billing_email, $settings['list'], $fields, true);
     205
     206            if (isset($response['error']['code'])) {
     207                $order->add_order_note('EmailOctopus error: '. $response['error']['message']);
     208            } else {
     209                $order->add_order_note( $billing_email.' added to the mailing list');
     210                update_post_meta( $order_id, 'fweo_emailoctopus_subscribed', 'subscribed');
     211            }
    211212        }
    212213    }
  • fw-integration-for-emailoctopus/trunk/include/emailoctopus.js

    r3069613 r3371971  
    44}
    55
     6function setCookie(name,value,days) {
     7    var expires = "";
     8    if (days) {
     9        var date = new Date();
     10        date.setTime(date.getTime() + (days*24*60*60*1000));
     11        expires = "; expires=" + date.toUTCString();
     12    }
     13    document.cookie = name + "=" + (value || "")  + expires + "; path=/";
     14}
     15function getCookie(name) {
     16    var nameEQ = name + "=";
     17    var ca = document.cookie.split(';');
     18    for(var i=0;i < ca.length;i++) {
     19        var c = ca[i];
     20        while (c.charAt(0)==' ') c = c.substring(1,c.length);
     21        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
     22    }
     23    return null;
     24}
     25var timenow = Math.floor(Date.now() / 1000);
     26if (null == getCookie('eosub_loadtime')) {
     27    setCookie('eosub_loadtime', timenow, 0);
     28}
     29
    630
    731jQuery(document).ready(function($) {
    8     $.get( eo_ajax_object.ajax_url, { action: "eo_loadtime" } );
    932    $('.emailoctopus-optin form').each(function(i, obj) {
    1033        var curr_id = $(this).attr('id');
  • fw-integration-for-emailoctopus/trunk/readme.txt

    r3260135 r3371971  
    77Requires PHP: 7.4
    88Tested up to: 6.7
    9 Stable tag: 1.0.8.6
     9Stable tag: 1.0.10
    1010
    1111Increase the subscribers for your website by using EmailOctopus and this professional integration plugin for WordPress, Elementor and WooCommerce.
     
    107107== Changelog ==
    108108
     109= 1.0.10 =
     110* Bug fixes
     111    * Fixed an issue in the WooCommerce integration where a certain setting would sign up all customers for the newsletter.
     112* Improvements
     113    * Replaced the cookie ajax request (in WordPress) with a simple JavaScript cookie script for load time improvements.
     114
    109115= 1.0.8.6 =
    110116* Improvements
Note: See TracChangeset for help on using the changeset viewer.