3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Utils_Check_Component_Cms
extends CRM_Utils_Check_Component
{
20 * For sites running in WordPress, make sure the configured base page exists.
22 * @return CRM_Utils_Check_Message[]
24 public static function checkWpBasePage() {
25 $config = CRM_Core_Config
::singleton();
26 if ($config->userFramework
!= 'WordPress') {
30 // There are a lot potential configurations in a multisite context where
31 // this could show a false positive. This completely skips multisite for
36 switch (self
::pageExists($config->wpBasePage
)) {
38 // Page is here and published
44 'CiviCRM relies upon a <a href="%1%2">base page in WordPress</a>, but it is not published.',
46 1 => $config->userFrameworkBaseURL
,
47 2 => $config->wpBasePage
,
54 // Page is missing, but let's look around to see if the default is there
55 // --either the default as modified by civicrm_basepage_slug or the
56 // default default, `civicrm`.
57 $cmsSettings = CRM_Utils_System
::url(
58 'civicrm/admin/setting',
59 $query = ['reset' => 1],
68 'CiviCRM relies upon a base page in WordPress at %1%2, but it is missing.',
70 1 => $config->userFrameworkBaseURL
,
71 2 => $config->wpBasePage
,
76 $altSlugs = array_unique([
77 apply_filters('civicrm_basepage_slug', 'civicrm'),
81 if (in_array($config->wpBasePage
, $altSlugs)) {
83 'If you have an alternative base page, it can be set in the <a href="%2">WordPress integration settings</a>.',
85 1 => $config->userFrameworkBaseURL
,
91 foreach ($altSlugs as $slug) {
92 $exists = self
::pageExists($slug);
94 // One of the possible defaults is here, published or not.
96 'The default is %1%2, which <a href="%1%2">does exist on this site</a>.',
98 1 => $config->userFrameworkBaseURL
,
103 $messageText[] = ts('However, it is not published.');
105 // We've found one, and if the `civicrm_basepage_slug` filter has
106 // modified the default, we should go with it.
111 // We went through the default(s) and couldn't find one. Defer to
112 // the one modified by the filter.
114 'The default is %1%2, but that does not exist on this site either.',
116 1 => $config->userFrameworkBaseURL
,
123 'You can set the correct base page in the <a href="%1">WordPress integration settings</a>.',
130 new CRM_Utils_Check_Message(
132 implode(' ', $messageText),
133 ts('WordPress Base Page Missing'),
134 \Psr\Log\LogLevel
::ERROR
,
141 * See if a page exists and is published.
143 * @param string $slug
147 * 0 if it's present but not published
148 * 1 if it's present and published
150 private static function pageExists($slug) {
151 $basePage = get_page_by_path($slug);
156 return (int) ($basePage->post_status
== 'publish');