CiviMail sent via wp-cli and cron mangles mailing urls on WP
Starting in 5.19 we have an issue with URLs in CiviMail. If Track links is on the URLs get mangled. Dradt Emails are fine, as well as if you kick off the scheduled job manually (UI or CLI).
However, if cron runs the job the URLS are broken:
Mailing Urls expected:
https://example.org//wp-content/plugins/civicrm/civicrm/extern/url.php?u=19&qid=31
But we get:
Tested Enviornments:
CiviCRM 5.19.x
WP: 5.3
wp-cli : 2.3 or 2.4
php 7.1 or 7.2 or 7.3
Cron run via script:
#!/bin/bash
/usr/local/bin/wp --user=civicron --url=https://example.org --path=/home/example/public_html --timezone="America/New_York" civicrm api job.execute auth=0
On Single site we can work around using cv
or cli.php
That fails on Multi-Domain
#/usr/local/bin/php /usr/local/bin/cv api job.execute --user=civicron --cwd=/home/example/public_html
Multi-Site Example:
WP MS 5.3
CiviCRM 5.19.1
php 7.1 (also tested 7.2)
wp-cli 2.4 (also tested 2.3)
cli.php results
you need to configure site : PHP Fatal error: Uncaught RuntimeException: Undefined constant: CIVICRM_UF_BASEURL in /home/members/example/sites/example.org/web/wp-content/plugins/civicrm/civicrm/CRM/Utils/System/WordPress
.php:105
cv results
you need to configure site : PHP Fatal error: Uncaught RuntimeException: Undefined constant: CIVICRM_UF_BASEURL in /home/members/example/sites/example.org/web/wp-content/plugins/civicrm/civicrm/CRM/Utils/System/WordPress
.php:105
script:
#!/bin/bash
#/usr/bin/php /home/members/example/sites/example.org/users/example/bin/cv api job.execute --user=civicron --cwd=/home/members/example/sites/example.org/users/example/web
#/usr/bin/php /home/members/example/sites/example.org/users/example/web/wp-content/plugins/civicrm/civicrm/bin/cli.php -s https://example-la.org -u civicron -p "civicrm" -e Job -a execute
#/usr/bin/php /home/members/example/sites/example.org/users/example/web/wp-content/plugins/civicrm/civicrm/bin/cli.php -s https://www.example.org -u civicron -p "civicrm" -e Job -a execute
/home/members/example/sites/example.org/users/example/bin/wp --user=tadpole --url=https://www.example.org --timezone="America/New_York" civicrm api job.execute auth=0
/home/members/example/sites/example.org/users/example/bin/wp --user=tadpole --url=https://another-example.org --timezone="America/New_York" civicrm api job.execute auth=0
We can fix the mangled URLS with a Work Around via .htaccess
#email redirect
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example-la\.org$ [NC]
RewriteRule ^home\/members\/example\/sites\/example.org\/web\/(.*)$ "https\:\/\/example-la\.org\/$1" [R=301,L,QSA]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example\.org$ [NC]
RewriteRule ^home\/members\/example\/sites\/example.org\/web\/(.*)$ "https\:\/\/www\.example\.org\/$1" [R=301,L,QSA]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.org$ [NC]
RewriteRule ^home\/members\/example\/sites\/example.org\/web\/(.*)$ "https\:\/\/example\.org\/$1" [R=301,L,QSA]
Reviewed with @haystack and @andrei Chritian came up with this Patch that I added to our local repo: https://github.com/tadpolecc/civicrm/commit/9470e1fb51ef317ee6d3f211af1bbf99e91431db
PR will be coming as this is a regression