-
-
Notifications
You must be signed in to change notification settings - Fork 88
WPML Rewrites defaulting to last language prefix found #342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…the primary language
|
FWIW before we actually apply this we should check a few other scenarios of site configurations (WPML has a few different types of settings). I don't forsee if affecting those since it should work, but better to check. I just didn't have time to test them |
|
@shaneonabike is this where you have the primary locale in the url or not? |
|
The patch looks sensible, but I don't have the necessary WPML/Polylang licenses or setup to test. If anyone can setup and test it would be appreciated. |
|
@shaneonabike Okay, I can confirm your issue but only in certain circumstances. Firstly, it looks to me as though this only happens when not using "Use directory for default language" as per the screenshot below.
Secondly, it seems that CiviCRM has to have been installed in a language that is no longer the default for the problem to occur... or at least that's what I'm finding. And furthermore I cannot actually change the Basepage to the one I want to make things work again. A possible reason for the problem is that the Basepage ID isn't quite what CiviCRM thinks it is, since it uses So it looks to me like we need to rethink the way in which CiviCRM handles identifying the Basepage - i.e. it should store the ID not the path. And FWIW, the code in this PR doesn't solve that. In summary, I think there are deeper problems than the one which this PR addresses. |
Correction to the above: I think I see the problem when the default language is the one which the Basepage is set to. If I switch the default language to one that isn't the same as the Basepage is set to, then everything works as expected with the current code. I think a way forward might be to use the |
|
@christianwach Yes we are using
Can you elaborate on what you mean here? This site has been around for quite some time, and didn't do anything unusual. We have:
In my output I verified the IDs and they match properly both the What is happening is that after the array unique basically the rewrites are created for Is that clearer maybe? |
So to reiterate what you are saying here (it took me a few runs to get my head around it)
Did you also translate the basepage? If that's the case I'm happy to test that scenario also? But also if that IS the case then maybe we have to reverse the code somewhat to "help it along"? I don't think I Have an edge case setup here.. Thoughts? |
|
I just wanted to reloop on this to see if there wouldn't be a way to potentially integrate this. I don't think that it should generate so many duplicate paths as it is, and clearly it seems wrong (to me at least) that the translation path appears on the basepage of the other language. That is what my patch is attempting to address. |
@shaneonabike I think the blocker is the problem I stated here. I'd like to see some work done on addressing this before returning to this WPML issue. Perhaps as simple as getting a new setting for the Basepage ID into CiviCRM Core. That would give us a chance to fix this properly. |
|
hey @christianwach hope you are well! We already have that with CiviCRM Admin tools so could their be a linkage via that OR are you implying that we really need something in core that would take care of this? If so, can you point to me where this is actually getting set in the first place. I don't think I understand how core is aware at all which is the correct basePage (besides obviously it's initial creation of the page, but then if someone deletes it and recreates a new one). My gutt says it just searches for |
@shaneonabike It's non-obvious how to get a new setting into Core. I had to have help for |
|
@eileenmcnaughton is a key person to gatekeep having too many settings in CiviCRM / agreeing to a new one. A provisional approach sometimes sees them created as PHP variables in civicrm.settings.php and not in the UI. |
|
So to articulate the considerations when adding settings to core
If @christianwach & @kcristiano consider a setting makes sense, given the above, then I think they understand this particular PR better than I do. With regards to how to add them - @christianwach is right to give civicrm/civicrm-core@fdd770d as an example - in most cases you will also want to have a key like
|
|
@eileenmcnaughton Thanks for detailing the issue with settings in Core. My suggestion of a new setting is aimed at eventually deprecating and removing the current
This query to retrieve the Basepage fails in certain circumstances in a WPML context - whereas calling I'm open to the idea of deprecating the Core |
|
Also, I think that this behaviour is already kind of overwritten or optional via the |
@shaneonabike Not sure what you mean here. Can you explain? |
|
@christianwach Maybe it isn't
|
|
@shaneonabike Yes, that's shown on the Settings page, but the setting itself is held in CiviCRM Core and is the Page path not its ID. |
|
Oh boy! 😿 Ok well there we have it .. wouldn't this just be a matter of changing the code over to use the |
@shaneonabike If only it were simple, but there's a fair bit of code in Core that uses the current setting: https://github.com/search?q=repo%3Acivicrm%2Fcivicrm-core%20wpBasePage&type=code sigh |
|
I want to loop back on this because I have been receiving comments about this from people. For now I have patched this on several larger distributions of sites we have and it's working. My approach was to basically reduce down the permalink structure since it is repeating (thus confusing the system) with duplicates. I am happy to work with Core and yourselves to find a solution to remove the Page ID or whatever other solution we have in the future, but we should probably make this functional for people now in the meantime right? |
|
@shaneonabike I don't have the resources to implement the reworking of the |
|
@christianwach So are you suggesting that rather than proposing my fix you want me to implement a hook so that it looks like this
I could do that but it still won't resolve the issue that some people are having with regards to WPML because it would rely on them to implement a solution to resolve it. We ultimately want this to work out of the box right? Primary what I was trying to do to reduce the permalinks that were duplicated. I posted above, but will post here again. Putting both languages associated to the same But correct me if I'm wrong cause I could have misunderstood. I really appreciate your time and guidance and just want to make something that works for the community. |
|
Also, as a side note it could be good for someone (I could) to reach out to WPML to see if they wanted to basically work with us on this. They would have resources to do so and it's in their interest to make things function. |
|
@shaneonabike my issue is I have no ability to test this PR. We currently have no one on WPML. Other WP Translation plugins yes but not WPML. A testing site that is configured would also be a big help. For that reason if we could provide the necessary hooks via an extension/plugin I'd be more comfortable. If they can install translations, They could install an extension. Asking WPML for help is a good idea and cannot hurt. |
@shaneonabike I've said this previously - This PR may paper over the cracks in your "Language URL format" scenario but doesn't seem to be tested in other "Language URL format" scenarios and could therefore break sites that don't have your particular setup. Anyone wanting to replace the behaviour in this class can do that with the existing code, e.g. remove_action('civicrm_after_rewrite_rules', [civi_wp()->compat->wpml, 'rewrite_rules']);
add_action('civicrm_after_rewrite_rules', 'my_wpml_rewrite_rules', 10, 2);
function my_wpml_rewrite_rules($flush_rewrite_rules, $basepage) {
// Your logic here.
}Perhaps a matrix of scenarios with outcomes (e.g. this one) with your code and the existing code might help? |



Based on dev/wordpress#153
Description
Recently, we have been having a problem with the base CiviCRM page not rendering paths like
event/info/...properly except for the translated pages.After further research, I found that the rewrites were defaulting to the page id of the translated CiviCRM page.
The first path
^civicrm/([^?]*)?should be pointing to the Base Page not the actual translated page.Setup
After
Essentially, what this does is not to add the language translation redirect to the
basepage IDand vic versa. In my scenario this is totally messing with the translation of CiviCRM and causing a page not found on the translated link.Specifically
and also for the other languages