wp-media / wp-rocket

Performance optimization plugin for WordPress
https://wp-rocket.me
GNU General Public License v2.0
689 stars 215 forks source link

Links preload and RUCSS is referencing the wrong siteUrl when Polylang is using multiple domains #3876

Open DahmaniAdame opened 3 years ago

DahmaniAdame commented 3 years ago

Before submitting an issue please check that you’ve completed the following steps:

Describe the bug When Polylang uses multiple domains, the home_url() used on https://github.com/wp-media/wp-rocket/blob/40ecc6c70de1995295a1994fb77a6ecb93885287/inc/Engine/Preload/Links/Subscriber.php#L132 returns the wrong language home URL.

Example: Main language = domain.com Additional language = domain.com.au

home_url() will return domain.com for both.

To Reproduce Steps to reproduce the behavior:

  1. Enable Polylang with multiple domains.
  2. Enable WP Rocket Links Preload.
  3. Visit a page different than the base language.
  4. Check our RocketPreloadLinksConfig referencing the wrong domain.

Expected behavior WP Rocket referencing the right home URL for each language site even if it uses a different domain.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Polylang has a constant PLL_FILTER_HOME_URL set to true by default - reference https://polylang.pro/doc/php-constants/ But it didn't help home_url() to serve the right language home URL.

The following fixed the issue:

Replacing home_url() by rtrim(pll_home_url(), '/') on https://github.com/wp-media/wp-rocket/blob/40ecc6c70de1995295a1994fb77a6ecb93885287/inc/Engine/Preload/Links/Subscriber.php#L132

rtrim() is needed because Polylang adds a trailing slash after the URL when using pll_home_url().

Removing siteUrl from the $config array and adding conditionally like this one should work:

if (defined( 'POLYLANG_VERSION' )) {
  $config['siteUrl'] = rtrim(pll_home_url(), '/');
} else {
  $config['siteUrl'] = home_url();
}

Backlog Grooming (for WP Media dev team use only)

DahmaniAdame commented 3 years ago

Ticket - https://secure.helpscout.net/conversation/1495156823/259303/

mostafa-hisham commented 2 years ago

Reproduce the problem :heavy_multiplication_x: I can see the issue

Identify the root cause we need to use the pll_home_url to get the correct URL instead ofhome_url()

Scope a solution

  1. we need to add the "rocket_preload_links_config" filter to use the correct site URL before getting preload links in wp-rocket/inc/3rd-party/plugins/i18n/polylang.php
    function rocket_exclude_js_disqus( $config ) {
            rtrim(pll_home_url(), '/');
        return $config;
    }
    add_filter( 'rocket_preload_links_config', 'polylang_preload_links_config' );
  2. Refactor the full file to be under our new structure.
  3. add tests

Estimate the effort [M]

WordPresseur commented 1 year ago

A consequence of this issue is that the RUCSS generates the home_url() used css for all the domains.

webtrainingwheels commented 11 months ago

https://wp-media.slack.com/archives/C029G1B5HD2/p1680680060444579

bugrevealingbme commented 1 month ago

still? sad