Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-17633: Changes to support WP in it's own directory. #11031

Merged
merged 1 commit into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions CRM/Utils/System/WordPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ public function url(
}

/**
* 27-09-2016
* CRM-16421 CRM-17633 WIP Changes to support WP in it's own directory
* https://wiki.civicrm.org/confluence/display/CRM/WordPress+installed+in+its+own+directory+issues
* For now leave hard coded wp-admin references.
* TODO: remove wp-admin references and replace with admin_url() in the future. Look at best way to get path to admin_url
*
* @param $absolute
* @param $frontend
* @param $forceBackend
Expand All @@ -274,22 +280,12 @@ public function url(
*/
private function getBaseUrl($absolute, $frontend, $forceBackend) {
$config = CRM_Core_Config::singleton();

$base = $absolute ? $config->userFrameworkBaseURL : $config->useFrameworkRelativeBase;

if ((is_admin() && !$frontend) || $forceBackend) {
$base .= 'wp-admin/admin.php';
return $base;
return Civi::paths()->getUrl('[wp.backend]/.', $absolute ? 'absolute' : 'relative');
}
elseif (defined('CIVICRM_UF_WP_BASEPAGE')) {
$base .= CIVICRM_UF_WP_BASEPAGE;
return $base;
}
elseif (isset($config->wpBasePage)) {
$base .= $config->wpBasePage;
return $base;
else {
return Civi::paths()->getUrl('[wp.frontend]/.', $absolute ? 'absolute' : 'relative');
}
return $base;
}

/**
Expand Down
19 changes: 19 additions & 0 deletions Civi/Core/Paths.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Paths {
* Class constructor.
*/
public function __construct() {
$paths = $this;
$this
->register('civicrm.root', function () {
return \CRM_Core_Config::singleton()->userSystem->getCiviSourceStorage();
Expand All @@ -55,6 +56,24 @@ public function __construct() {
->register('civicrm.files', function () {
return \CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
})
->register('wp.frontend.base', function () {
return array('url' => CIVICRM_UF_BASEURL);
})
->register('wp.frontend', function () use ($paths) {
$config = \CRM_Core_Config::singleton();
$suffix = defined('CIVICRM_UF_WP_BASEPAGE') ? CIVICRM_UF_WP_BASEPAGE : $config->wpBasePage;
return array(
'url' => $paths->getVariable('wp.frontend.base', 'url') . $suffix,
);
})
->register('wp.backend.base', function () {
return array('url' => CIVICRM_UF_BASEURL . 'wp-admin/');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kcristiano Are you sure that wp-admin/ should be hard-coded here? The admin_url filter allows this to be overridden, so if this path has to be correct without bootstrapping WordPress, then perhaps there needs to be a setting for it somewhere? OTOH, perhaps I'm raising an issue that's outside the scope of this PR.

Copy link
Member Author

@kcristiano kcristiano Oct 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@christianwach I see the point and had originally done that. In one of the iterations (this PR in various forms dates back to Ft Collins Sprint in June 2016), @totten made the followimng PRs that have been added: kcristiano@48c4fe6 and kcristiano@8b0c250 This section kcristiano@8b0c250#diff-46f9229e858ccffc107ef60a91809c43L286 removed the call to admin_url(). I attempted to add back, but had errors depending on the WP configuration.

As I would much rather have this in and then improve than hold it back even longer, I consider switching to admin_url() as a TODO. We can create an issue for that and fix it after these changes are tested through an RC. As this is an installer patch and it affects both civicrm-core and civicrm-wordpress we'll get more testing once it hits RC.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kcristiano Gotcha. Seems like a good idea.

})
->register('wp.backend', function () use ($paths) {
return array(
'url' => $paths->getVariable('wp.backend.base', 'url') . 'admin.php',
);
})
->register('cms', function () {
return array(
'path' => \CRM_Core_Config::singleton()->userSystem->cmsRootPath(),
Expand Down
19 changes: 16 additions & 3 deletions install/civicrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ function civicrm_main(&$config) {

if ($installType == 'drupal') {
$siteDir = isset($config['site_dir']) ? $config['site_dir'] : getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']);
civicrm_setup($cmsPath . DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR .
$siteDir . DIRECTORY_SEPARATOR . 'files'
civicrm_setup($cmsPath . DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . $siteDir . DIRECTORY_SEPARATOR . 'files'
);
}
elseif ($installType == 'backdrop') {
Expand Down Expand Up @@ -139,7 +138,6 @@ function civicrm_main(&$config) {
civicrm_write_file($configFile,
$string
);

}

/**
Expand Down Expand Up @@ -217,6 +215,9 @@ function civicrm_config(&$config) {
global $compileDir;
global $tplPath, $installType;

// Ex: $extraSettings[] = '$civicrm_settings["domain"]["foo"] = "bar";';
$extraSettings = array();

$params = array(
'crmRoot' => $crmPath,
'templateCompileDir' => $compileDir,
Expand Down Expand Up @@ -274,6 +275,18 @@ function civicrm_config(&$config) {

// CRM-12386
$params['crmRoot'] = addslashes($params['crmRoot']);
//CRM-16421

$extraSettings[] = sprintf('$civicrm_paths[\'wp.frontend.base\'][\'url\'] = %s;', var_export(home_url() . '/', 1));
$extraSettings[] = sprintf('$civicrm_paths[\'wp.backend.base\'][\'url\'] = %s;', var_export(admin_url(), 1));
$extraSettings[] = sprintf('$civicrm_setting[\'URL Preferences\'][\'userFrameworkResourceURL\'] = %s;', var_export(plugin_dir_url(CIVICRM_PLUGIN_FILE) . 'civicrm', 1));
}

if ($extraSettings) {
$params['extraSettings'] = "Additional settings generated by installer:\n" . implode("\n", $extraSettings);
}
else {
$params['extraSettings'] = "";
}

$params['siteKey'] = md5(rand() . mt_rand() . rand() . uniqid('', TRUE) . $params['baseURL']);
Expand Down
4 changes: 3 additions & 1 deletion templates/CRM/common/civicrm.settings.php.template
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* CiviCRM Configuration File.
*/
global $civicrm_setting;
global $civicrm_root, $civicrm_setting, $civicrm_paths;

/**
* Content Management System (CMS) Host:
Expand Down Expand Up @@ -76,6 +76,8 @@ if (!defined('CIVICRM_UF_DSN') && CIVICRM_UF !== 'UnitTests') {
define( 'CIVICRM_UF_DSN' , 'mysql://%%CMSdbUser%%:%%CMSdbPass%%@%%CMSdbHost%%/%%CMSdbName%%?new_link=true');
}

// %%extraSettings%%

/**
* CiviCRM Database Settings
*
Expand Down