Upstatement / routes

Simple routing for WordPress
188 stars 38 forks source link

when WPML uses GET param as lang format #12

Open luzel opened 6 years ago

luzel commented 6 years ago

Wordpress 4.9.1 (multisite) Timber 1.5.2

When WPML language URL format is "Language name added as a parameter" there is issue with calculating base_path in method Routes::map(). Function get_bloginfo('url') returns URL containg "?lang=en" which ends up with wrong base_path (I am not sure but maybe this is bug beacuse of multisite)

Fix on forked github repo: https://github.com/luzel/routes

Part-A commented 6 years ago

This issue is not limited to multisite - it is apparent for single site, using WPML, timber and routes installed via composer (not plugin version).

Even when the lang is in the url (www.afakeurl.com/us/) routing via Routes is broken - this may be due to WPML incorrectly adding a '/' to the url returned by get_bloginfo('url'). Luzel's fix works in this situation too as it removes the '/'.

It would make sense to include Luzel's fix, or some version of, in Upstatement/routes.

stevecomrie commented 6 years ago

Pretty sure I'm running into either this exact bug or a variation of it.

In the Routes::map() function the $base_path variable used in the setBasePath() function used to always be something like: "/" or "/lang/", but some where in an update (maybe with WPML), I started getting a $base_path value of: "/lang//".

I was able to fix this with a simple:

$base_path = str_replace( "//", "/", $base_path );

Right before:

$upstatement_routes->router->setBasePath($base_path);

I don't like modifying the local version of Routes.php, so hopefully a fix will be incoming soon for this.

n3storm commented 4 years ago

Same happens to me. I made a more elaborate fix only replacing double dash "//" if is found.

A proper fix would be great.

jarednova commented 4 years ago

@n3storm @stevecomrie. Thanks for the nudge, sorry I missed this last year. Just pushed #12 to resolve