Plugin Directory

Changeset 3253494


Ignore:
Timestamp:
03/10/2025 05:06:45 PM (13 months ago)
Author:
mvpis
Message:

Updated with improvements and bug fixes

Location:
fluentc-translation
Files:
79 added
3 edited

Legend:

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

    r3252669 r3253494  
    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.1
     9 * Version: 2.4.2
    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.1" );
     19define( 'FLUENTC_TRANSLATION_VERSION', "2.4.2" );
    2020define( 'FLUENTC_TRANSLATION_PLUGIN_DIR', plugin_dir_path(__FILE__) );
    2121define( 'FLUENTC_TRANSLATION_PLUGIN_URL', plugin_dir_url(__FILE__) );
  • fluentc-translation/trunk/readme.txt

    r3252669 r3253494  
    55Requires at least: 4.6
    66Tested up to: 6.6.2
    7 Stable tag: 2.4.1
     7Stable tag: 2.4.2
    88Requires PHP: 7.3
    99License: GPLv2 or later
  • fluentc-translation/trunk/src/actions/class-links.php

    r3249935 r3253494  
    254254    }
    255255
    256    /**
     256  /**
    257257 * Modify rewrite rules to handle language prefixes for all existing rules
    258  * with special handling for the home page
     258 * with special handling for the home page and non-English source languages
    259259 *
    260260 * @param array $rules WordPress rewrite rules
     
    318318    return $final_rules;
    319319}
     320
    320321/**
    321322 * Filter the template for home page in different languages
     323 * Enhanced to properly handle non-English source languages
    322324 */
    323325public function filter_template_for_home_page() {
    324326    global $wp_query;
    325327   
    326     // Check if this is a language-prefixed home page
    327     if (isset($wp_query->query_vars['fluentc_language']) &&
    328         is_home() &&
    329         !is_front_page()) {
    330        
    331         // Check if a static page is set as the front page
    332         $show_on_front = get_option('show_on_front');
    333         $page_on_front = get_option('page_on_front');
    334        
    335         if ($show_on_front === 'page' && $page_on_front) {
    336             // Set up the main query to load the front page
    337             $wp_query->is_home = false;
    338             $wp_query->is_page = true;
    339             $wp_query->is_singular = true;
    340             $wp_query->is_front_page = true;
     328    // Check if this is a language-prefixed page
     329    if (!isset($wp_query->query_vars['fluentc_language'])) {
     330        return;
     331    }
     332   
     333    $language = $wp_query->query_vars['fluentc_language'];
     334    $source_language = $this->fluentc_language->fluentc_site_language();
     335   
     336    // Only proceed if this is a different language than the source
     337    // and either we have no posts or this is detected as home when it shouldn't be
     338    if ($language !== $source_language &&
     339        (empty($wp_query->posts) || (is_home() && !empty($wp_query->query)))) {
     340       
     341        // Get the requested path
     342        $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
     343        $path = wp_parse_url($request_uri, PHP_URL_PATH);
     344       
     345        // Remove language prefix from path to get the source path
     346        $path = preg_replace('/^\/' . preg_quote($language, '/') . '\//', '/', $path);
     347        $path = rtrim($path, '/');
     348        $slug = trim($path, '/');
     349       
     350        // Check if we're dealing with homepage or a specific page
     351        if (empty($slug) || $slug === $language) {
     352            // This is the homepage in a different language
     353            $show_on_front = get_option('show_on_front');
     354            $page_on_front = get_option('page_on_front');
    341355           
    342             // Set the queried object to be the front page
    343             $front_page = get_post($page_on_front);
    344             $wp_query->queried_object = $front_page;
    345             $wp_query->queried_object_id = $page_on_front;
     356            if ($show_on_front === 'page' && $page_on_front) {
     357                // Set up the main query to load the front page
     358                $wp_query->is_home = false;
     359                $wp_query->is_page = true;
     360                $wp_query->is_singular = true;
     361                $wp_query->is_front_page = true;
     362               
     363                // Set the queried object to be the front page
     364                $front_page = get_post($page_on_front);
     365                $wp_query->queried_object = $front_page;
     366                $wp_query->queried_object_id = $page_on_front;
     367                $wp_query->post = $front_page;
     368                $wp_query->posts = array($front_page);
     369                $wp_query->post_count = 1;
     370               
     371                // Force using the page template
     372                add_filter('template_include', function($template) use ($front_page) {
     373                    if (is_object($front_page) && isset($front_page->ID)) {
     374                        $page_template = get_page_template_slug($front_page->ID);
     375                        if ($page_template) {
     376                            $templates = array($page_template);
     377                        } else {
     378                            $templates = array('page.php', 'singular.php', 'index.php');
     379                        }
     380                       
     381                        $new_template = locate_template($templates);
     382                        if ($new_template) {
     383                            return $new_template;
     384                        }
     385                    }
     386                    return $template;
     387                }, 99);
     388            }
     389        } else if (empty($wp_query->posts)) {
     390            // This is a specific page that failed to resolve - try to find it
     391            $page = get_page_by_path($slug);
    346392           
    347             // Force using the page template
    348             add_filter('template_include', function($template) use ($front_page) {
    349                 if (is_object($front_page) && $front_page->ID) {
    350                     $page_template = get_page_template_slug($front_page->ID);
    351                     if ($page_template) {
    352                         $templates = array($page_template);
    353                     } else {
    354                         $templates = array('page.php', 'singular.php', 'index.php');
    355                     }
    356                    
    357                     $new_template = locate_template($templates);
    358                     if ($new_template) {
    359                         return $new_template;
    360                     }
     393            if ($page) {
     394                // Set up the query to display this page
     395                $wp_query->is_home = false;
     396                $wp_query->is_page = true;
     397                $wp_query->is_singular = true;
     398                $wp_query->post = $page;
     399                $wp_query->posts = array($page);
     400                $wp_query->post_count = 1;
     401                $wp_query->queried_object = $page;
     402                $wp_query->queried_object_id = $page->ID;
     403               
     404                // Add debugging info if needed
     405                if (defined('WP_DEBUG') && WP_DEBUG) {
     406                    error_log('FluentC: Resolved page ' . $slug . ' to ID ' . $page->ID);
    361407                }
    362                 return $template;
    363             }, 99);
     408            } else if (defined('WP_DEBUG') && WP_DEBUG) {
     409                // Log for debugging if the page couldn't be found
     410                error_log('FluentC: Could not resolve page for path: ' . $slug);
     411            }
    364412        }
    365413    }
Note: See TracChangeset for help on using the changeset viewer.