Plugin Directory

Changeset 3261810


Ignore:
Timestamp:
03/25/2025 10:02:18 PM (12 months ago)
Author:
mvpis
Message:

Updated to support Ajax

Location:
fluentc-translation
Files:
79 added
5 edited

Legend:

Unmodified
Added
Removed
  • fluentc-translation/trunk/fluentc_wordpress_plugin.php

    r3255173 r3261810  
    77 * Plugin URI: https://www.fluentc.ai
    88 * Description: A plugin that enables website owners to easily install the FluentC Translation on their WordPress site.
    9  * Version: 2.4.4
     9 * Version: 2.4.5
    1010 * Author: FluentC
    1111 * Author URI: https://www.fluentc.ai
     
    1717define( 'FLUENTC_DIR', __DIR__ );
    1818define( 'FLUENTC_SLUG', 'fluentc_translation' );
    19 define( 'FLUENTC_TRANSLATION_VERSION', "2.4.4" );
     19define( 'FLUENTC_TRANSLATION_VERSION', "2.4.5" );
    2020define( 'FLUENTC_TRANSLATION_PLUGIN_DIR', plugin_dir_path(__FILE__) );
    2121define( 'FLUENTC_TRANSLATION_PLUGIN_URL', plugin_dir_url(__FILE__) );
  • fluentc-translation/trunk/readme.txt

    r3255173 r3261810  
    55Requires at least: 4.6
    66Tested up to: 6.6.2
    7 Stable tag: 2.4.4
     7Stable tag: 2.4.5
    88Requires PHP: 7.3
    99License: GPLv2 or later
  • fluentc-translation/trunk/src/actions/class-wordpress.php

    r3255173 r3261810  
    169169        add_action('fluentc_language_set', array($this, 'refresh_language_code'));
    170170       
    171    
     171        // Register browser language detection and redirection.
     172        add_action('template_redirect', array($this, 'fluentc_language_redirect'), 1);
    172173    }
    173174   
     
    268269        }
    269270       
    270         if (is_admin() || wp_doing_ajax() || defined('DOING_CRON') || wp_is_xml_request()) {
     271        if (is_admin() || is_404() || defined('DOING_CRON') || wp_is_xml_request()) {
    271272            return;
    272273        }
  • fluentc-translation/trunk/src/services/class-widget.php

    r3255173 r3261810  
    116116                  });' . "\n";
    117117                $header_code .= '        f.setupWidget(\'fluentc-widget\' );' . "\n";
     118
     119        if ($lang) {
     120            $header_code .= '        // Add language to AJAX requests' . "\n";
     121            $header_code .= '        (function() {' . "\n";
     122            $header_code .= '            var ajaxOpen = XMLHttpRequest.prototype.open;' . "\n";
     123            $header_code .= '            XMLHttpRequest.prototype.open = function() {' . "\n";
     124            $header_code .= '                var method = arguments[0];' . "\n";
     125            $header_code .= '                var url = arguments[1];' . "\n";
     126            $header_code .= '                if (typeof url === "string" && url.indexOf("admin-ajax.php") !== -1) {' . "\n";
     127            $header_code .= '                    url += (url.indexOf("?") !== -1 ? "&" : "?") + "fluentc_language=' . $lang . '";' . "\n";
     128            $header_code .= '                    arguments[1] = url;' . "\n";
     129            $header_code .= '                }' . "\n";
     130            $header_code .= '                return ajaxOpen.apply(this, arguments);' . "\n";
     131            $header_code .= '            };' . "\n";
     132            $header_code .= '        })();' . "\n";
     133        }
    118134                $header_code .= '    });';
    119135
  • fluentc-translation/trunk/src/utils/class-language.php

    r3255173 r3261810  
    270270        }
    271271       
     272        // Check for AJAX request with language parameter
     273        if (wp_doing_ajax() && isset($_REQUEST['fluentc_language'])) {
     274            $ajax_language = sanitize_text_field($_REQUEST['fluentc_language']);
     275            // Validate the language code against available languages
     276            if (!empty($ajax_language) && in_array($ajax_language, $this->available_languages)) {
     277                // Store in property for future calls
     278                $this->current_language = $ajax_language;
     279                return $ajax_language;
     280            }
     281        }
     282       
    272283        // Only try regex method if we have the language list
    273284        if (!empty($this->regex_lang)) {
Note: See TracChangeset for help on using the changeset viewer.