Plugin Directory

Changeset 3444289


Ignore:
Timestamp:
01/21/2026 05:01:40 PM (4 weeks ago)
Author:
rnzo
Message:

Code refactor

Location:
contact-form-7-mailchimp-extension
Files:
9 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • contact-form-7-mailchimp-extension/tags/0.9.72/assets/js/chimpmatic-lite.js

    r3442168 r3444289  
    547547                    const data = await response.json();
    548548                    if (wrapper) wrapper.classList.remove('is-saving');
    549                     if (!data.success) this.checked = !enabled;
     549                    if (data.success) {
     550                        // Sync defaultChecked to prevent CF7 beforeunload warning
     551                        this.defaultChecked = this.checked;
     552                    } else {
     553                        this.checked = !enabled;
     554                    }
    550555                } catch (error) {
    551556                    if (wrapper) wrapper.classList.remove('is-saving');
     
    562567        if (selects.length === 0) return;
    563568
     569        const perFormFields = ['double_optin', 'sync_tags'];
     570
    564571        selects.forEach(function(select) {
    565572            select.addEventListener('change', async function() {
    566573                const field = this.dataset.field;
    567                 const enabled = this.value === '1';
     574                const value = this.value === '1';
    568575                const wrapper = this.closest('.mcee-container');
    569576
     
    571578
    572579                try {
    573                     const response = await fetch(chimpmaticLite.restUrl + 'settings/toggle', {
     580                    let url, body;
     581
     582                    if (perFormFields.includes(field)) {
     583                        const formId = getFormId();
     584                        if (!formId) {
     585                            if (wrapper) wrapper.classList.remove('is-saving');
     586                            this.value = value ? '0' : '1';
     587                            return;
     588                        }
     589                        const rootUrl = chimpmaticLite.restUrl.replace('chimpmatic-lite/v1/', '');
     590                        url = rootUrl + 'cmatic/form/setting';
     591                        body = JSON.stringify({ form_id: formId, field, value });
     592                    } else {
     593                        url = chimpmaticLite.restUrl + 'settings/toggle';
     594                        body = JSON.stringify({ field, enabled: value });
     595                    }
     596
     597                    const response = await fetch(url, {
    574598                        method: 'POST',
    575599                        headers: {
     
    577601                            'X-WP-Nonce': chimpmaticLite.restNonce
    578602                        },
    579                         body: JSON.stringify({ field, enabled })
     603                        body
    580604                    });
    581605
    582606                    const data = await response.json();
    583607                    if (wrapper) wrapper.classList.remove('is-saving');
    584                     if (!data.success) {
    585                         this.value = enabled ? '0' : '1';
     608                    if (data.success) {
     609                        // Sync defaultSelected to prevent CF7 beforeunload warning
     610                        Array.from(this.options).forEach(function(opt) {
     611                            opt.defaultSelected = opt.selected;
     612                        });
     613                    } else {
     614                        this.value = value ? '0' : '1';
    586615                    }
    587616                } catch (error) {
    588617                    if (wrapper) wrapper.classList.remove('is-saving');
    589                     this.value = enabled ? '0' : '1';
     618                    this.value = value ? '0' : '1';
    590619                }
    591620            });
  • contact-form-7-mailchimp-extension/tags/0.9.72/includes/services/class-cmatic-pro-syncer.php

    r3442192 r3444289  
    107107        }
    108108
    109         $domain     = str_ireplace( array( 'http://', 'https://' ), '', home_url() );
    110         $api_url    = 'https://chimpmatic.com/';
    111         $product_id = ! empty( $activation['product_id'] ) ? $activation['product_id'] : 436;
    112         $args       = array(
     109        $domain  = str_ireplace( array( 'http://', 'https://' ), '', home_url() );
     110        $api_url = 'https://chimpmatic.com/';
     111        $args    = array(
    113112            'wc_am_action' => 'update',
    114113            'slug'         => 'chimpmatic',
    115114            'plugin_name'  => self::PRO_PLUGIN_FILE,
    116115            'version'      => $current_version,
    117             'product_id'   => $product_id,
     116            'product_id'   => 436,
    118117            'api_key'      => $api_key,
    119118            'instance'     => $instance_id,
     
    153152        require_once ABSPATH . 'wp-admin/includes/file.php';
    154153
    155         // Check if Pro was active before upgrade.
    156         $was_active = is_plugin_active( self::PRO_PLUGIN_FILE );
    157 
    158154        $updates = get_site_transient( 'update_plugins' );
    159155        if ( ! is_object( $updates ) ) {
     
    174170            Cmatic_Options_Repository::set_option( 'pro_last_auto_sync', $sync_info->new_version );
    175171            Cmatic_Options_Repository::set_option( 'pro_last_auto_sync_at', gmdate( 'Y-m-d H:i:s' ) );
    176 
    177             // Reactivate Pro if it was active before upgrade.
    178             if ( $was_active && ! is_plugin_active( self::PRO_PLUGIN_FILE ) ) {
    179                 activate_plugin( self::PRO_PLUGIN_FILE );
    180             }
    181 
    182             // Clear the stale update transient to prevent "update available" banner.
    183             delete_site_transient( 'update_plugins' );
    184             wp_clean_plugins_cache();
    185172        }
    186173    }
  • contact-form-7-mailchimp-extension/tags/0.9.72/includes/services/submission/class-cmatic-status-resolver.php

    r3442168 r3444289  
    1515    public static function resolve( array $cf7_mch, array $posted_data, Cmatic_File_Logger $logger ): ?string {
    1616        // Double opt-in enabled (per-form setting).
    17         if ( ! empty( $cf7_mch['confsubs'] ) ) {
     17        if ( ! empty( $cf7_mch['double_optin'] ) || ! empty( $cf7_mch['confsubs'] ) ) {
    1818            return 'pending';
    1919        }
  • contact-form-7-mailchimp-extension/tags/0.9.72/includes/ui/class-cmatic-field-mapper.php

    r3442168 r3444289  
    195195
    196196    private static function render_double_optin( array $cf7_mch ): void {
    197         $value = ! empty( $cf7_mch['confsubs'] ) ? '1' : '0';
     197        $value = ! empty( $cf7_mch['double_optin'] ) || ! empty( $cf7_mch['confsubs'] ) ? '1' : '0';
    198198        ?>
    199199        <div class="mcee-container">
Note: See TracChangeset for help on using the changeset viewer.