-
-
Notifications
You must be signed in to change notification settings - Fork 827
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add system check to ensure WP base page exists
- Loading branch information
Showing
1 changed file
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* | ||
* @package CRM | ||
* @copyright CiviCRM LLC https://civicrm.org/licensing | ||
*/ | ||
class CRM_Utils_Check_Component_Cms extends CRM_Utils_Check_Component { | ||
|
||
/** | ||
* For sites running in WordPress, make sure the configured base page exists. | ||
* | ||
* @return array | ||
* Instances of CRM_Utils_Check_Message | ||
*/ | ||
public static function checkWpBasePage() { | ||
$config = CRM_Core_Config::singleton(); | ||
if ($config->userFramework != 'WordPress') { | ||
return []; | ||
} | ||
$messages = []; | ||
|
||
$slug = $config->wpBasePage; | ||
$pageArgs = [ | ||
'name' => $slug, | ||
'post_type' => 'page', | ||
'post_status' => 'publish', | ||
'numberposts' => 1, | ||
]; | ||
$basePage = get_posts($pageArgs); | ||
if (!$basePage) { | ||
$cmsSettings = CRM_Utils_System::url( | ||
'civicrm/admin/setting', | ||
$query = ['reset' => 1], | ||
FALSE, | ||
NULL, | ||
TRUE, | ||
FALSE, | ||
TRUE | ||
); | ||
$messageText = [ | ||
ts( | ||
'CiviCRM relies upon a base page in WordPress at %1%2, but it is missing.', | ||
[ | ||
1 => $config->userFrameworkBaseURL, | ||
2 => $slug, | ||
] | ||
), | ||
]; | ||
if ($slug == 'civicrm') { | ||
$messageText[] = ts( | ||
'If you have an alternative base page, it can be set in the <a href="%2">WordPress integration settings</a>.', | ||
[ | ||
1 => $config->userFrameworkBaseURL, | ||
2 => $cmsSettings, | ||
] | ||
); | ||
} | ||
else { | ||
$pageArgs['name'] = 'civicrm'; | ||
$defaultBasePage = get_posts($pageArgs); | ||
if ($defaultBasePage) { | ||
$messageText[] = ts( | ||
'The default is %1civicrm, which <a href="%1civicrm">does exist on this site</a>.', | ||
[1 => $config->userFrameworkBaseURL] | ||
); | ||
} | ||
else { | ||
$messageText[] = ts( | ||
'The default is %1civicrm, but that does not exist on this site either.', | ||
[1 => $config->userFrameworkBaseURL] | ||
); | ||
} | ||
$messageText[] = ts( | ||
'You can set the correct base page in the <a href="%1">WordPress integration settings</a>.', | ||
[1 => $cmsSettings] | ||
); | ||
} | ||
$messages[] = new CRM_Utils_Check_Message( | ||
__FUNCTION__, | ||
implode(' ', $messageText), | ||
ts('WordPress Base Page Missing'), | ||
\Psr\Log\LogLevel::ERROR, | ||
'fa-wordpress' | ||
); | ||
} | ||
|
||
return $messages; | ||
} | ||
|
||
} |