Skip to content

Commit

Permalink
Add system check to ensure WP base page exists
Browse files Browse the repository at this point in the history
  • Loading branch information
agh1 committed Jun 25, 2020
1 parent de71d03 commit 2586fbb
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions CRM/Utils/Check/Component/Cms.php
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;
}

}

0 comments on commit 2586fbb

Please sign in to comment.