Skip to content
Snippets Groups Projects
Unverified Commit 88890043 authored by Seamus Lee's avatar Seamus Lee Committed by GitHub
Browse files

Merge pull request #17360 from totten/master-wp-var

WP - Change definitions of `cms.root`, `civicrm.root`
parents 7f9acf5b 716bdc94
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,87 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
$this->is_wordpress = TRUE;
}
public function initialize() {
parent::initialize();
$this->registerPathVars();
}
/**
* Specify the default computation for various paths/URLs.
*/
protected function registerPathVars():void {
$isNormalBoot = function_exists('get_option');
if ($isNormalBoot) {
// Normal mode - CMS boots first, then calls Civi. "Normal" web pages and newer extern routes.
// To simplify the code-paths, some items are re-registered with WP-specific functions.
$cmsRoot = function() {
return [
'path' => untrailingslashit(ABSPATH),
'url' => home_url(),
];
};
Civi::paths()->register('cms', $cmsRoot);
Civi::paths()->register('cms.root', $cmsRoot);
Civi::paths()->register('civicrm.files', function () {
$upload_dir = wp_get_upload_dir();
return [
'path' => $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR,
'url' => $upload_dir['baseurl'] . '/civicrm/',
];
});
Civi::paths()->register('civicrm.root', function () {
return [
'path' => CIVICRM_PLUGIN_DIR . 'civicrm' . DIRECTORY_SEPARATOR,
'url' => CIVICRM_PLUGIN_URL . 'civicrm/',
];
});
Civi::paths()->register('wp.frontend.base', function () {
return [
'url' => home_url('/'),
];
});
Civi::paths()->register('wp.frontend', function () {
$config = CRM_Core_Config::singleton();
$basepage = get_page_by_path($config->wpBasePage);
return [
'url' => get_permalink($basepage->ID),
];
});
Civi::paths()->register('wp.backend.base', function () {
return [
'url' => admin_url(),
];
});
Civi::paths()->register('wp.backend', function() {
return [
'url' => admin_url('admin.php'),
];
});
}
else {
// Legacy support - only relevant for older extern routes.
Civi::paths()
->register('wp.frontend.base', function () {
return ['url' => rtrim(CIVICRM_UF_BASEURL, '/') . '/'];
})
->register('wp.frontend', function () {
$config = \CRM_Core_Config::singleton();
$suffix = defined('CIVICRM_UF_WP_BASEPAGE') ? CIVICRM_UF_WP_BASEPAGE : $config->wpBasePage;
return [
'url' => Civi::paths()->getVariable('wp.frontend.base', 'url') . $suffix,
];
})
->register('wp.backend.base', function () {
return ['url' => rtrim(CIVICRM_UF_BASEURL, '/') . '/wp-admin/'];
})
->register('wp.backend', function () {
return [
'url' => Civi::paths()->getVariable('wp.backend.base', 'url') . 'admin.php',
];
});
}
}
/**
* @inheritDoc
*/
......
......@@ -30,7 +30,10 @@ class Paths {
* Class constructor.
*/
public function __construct() {
$paths = $this;
// Below is a *default* set of functions to calculate paths/URLs.
// Some variables may be overridden as follow:
// - The global `$civicrm_paths` may be preset before Civi boots. (Ex: via `civicrm.settings.php`, `settings.php`, or `vendor/autoload.php`)
// - Variables may be re-registered. (Ex: via `CRM_Utils_System_WordPress`)
$this
->register('civicrm.root', function () {
return \CRM_Core_Config::singleton()->userSystem->getCiviSourceStorage();
......@@ -84,24 +87,6 @@ class Paths {
'path' => is_dir($dir) ? $dir : \Civi::paths()->getPath('[civicrm.root]/l10n'),
];
})
->register('wp.frontend.base', function () {
return ['url' => rtrim(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 [
'url' => $paths->getVariable('wp.frontend.base', 'url') . $suffix,
];
})
->register('wp.backend.base', function () {
return ['url' => rtrim(CIVICRM_UF_BASEURL, '/') . '/wp-admin/'];
})
->register('wp.backend', function () use ($paths) {
return [
'url' => $paths->getVariable('wp.backend.base', 'url') . 'admin.php',
];
})
->register('cms', function () {
return [
'path' => \CRM_Core_Config::singleton()->userSystem->cmsRootPath(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment