return apply_filters('civicrm_exit_after_fatal', $ret);
}
+ /**
+ * Make sure clean URLs are properly set in settings file.
+ *
+ * @return CRM_Utils_Check_Message[]
+ */
+ public function checkCleanurls() {
+ $config = CRM_Core_Config::singleton();
+ $clean = 0;
+ if (defined('CIVICRM_CLEANURL')) {
+ $clean = CIVICRM_CLEANURL;
+ }
+ if ($clean == 1) {
+ //cleanURLs are enabled in CiviCRM, let's make sure the wordpress permalink settings and cache are actually correct by checking the first active contribution page
+ $contributionPages = \Civi\Api4\ContributionPage::get(FALSE)
+ ->addSelect('id')
+ ->addWhere('is_active', '=', TRUE)
+ ->setLimit(1)
+ ->execute();
+ if (count($contributionPages) > 0) {
+ $activePageId = $contributionPages[0]['id'];
+ $message = self::checkCleanPage('/contribute/transact/?reset=1&id=', $activePageId, $config);
+
+ return $message;
+ }
+ else {
+ //no active contribution pages, we can check an event page. This probably won't ever happen.
+ $eventPages = \Civi\Api4\Event::get(FALSE)
+ ->addSelect('id')
+ ->addWhere('is_active', '=', TRUE)
+ ->setLimit(1)
+ ->execute();
+ if (count($eventPages) > 0) {
+ $activePageId = $eventPages[0]['id'];
+ $message = self::checkCleanPage('/event/info/?reset=1&id=', $activePageId, $config);
+
+ return $message;
+ }
+ else {
+ //If there are no active event or contribution pages, we'll skip this check for now.
+
+ return [];
+ }
+ }
+ }
+ else {
+ //cleanURLs aren't enabled or aren't defined correctly in CiviCRM, admin should check civicrm.settings.php
+ $warning = ts('Clean URLs are not enabled correctly in CiviCRM. This can lead to "valid id" errors for users registering for events or making donations. Check civicrm.settings.php and review <a %1>the documentation</a> for more information.', [1 => 'href="' . CRM_Utils_System::docURL2('sysadmin/integration/wordpress/clean-urls/', TRUE) . '"']);
+
+ return [
+ new CRM_Utils_Check_Message(
+ __FUNCTION__,
+ $warning,
+ ts('Clean URLs Not Enabled'),
+ \Psr\Log\LogLevel::WARNING,
+ 'fa-wordpress'
+ ),
+ ];
+ }
+ }
+
+ private static function checkCleanPage($slug, $id, $config) {
+ $page = $config->userFrameworkBaseURL . $config->wpBasePage . $slug . $id;
+ try {
+ $client = new \GuzzleHttp\Client();
+ $res = $client->head($page, ['http_errors' => FALSE]);
+ $httpCode = $res->getStatusCode();
+ }
+ catch (Exception $e) {
+ Civi::log()->error("Could not run " . __FUNCTION__ . " on $page. GuzzleHttp\Client returned " . $e->getMessage());
+
+ return [
+ new CRM_Utils_Check_Message(
+ __FUNCTION__,
+ ts('Could not load a clean page to check'),
+ ts('Guzzle client error'),
+ \Psr\Log\LogLevel::ERROR,
+ 'fa-wordpress'
+ ),
+ ];
+ }
+
+ if ($httpCode == 404) {
+ $warning = ts('<a %1>Click here to go to Settings > Permalinks, then click "Save" to refresh the cache.</a>', [1 => 'href="' . get_admin_url(NULL, 'options-permalink.php') . '"']);
+ $message = new CRM_Utils_Check_Message(
+ __FUNCTION__,
+ $warning,
+ ts('Wordpress Permalinks cache needs to be refreshed.'),
+ \Psr\Log\LogLevel::WARNING,
+ 'fa-wordpress'
+ );
+
+ return [$message];
+ }
+
+ //sanity
+ return [];
+
+ }
+
}