From 9509977f7eaf2e6b564106ebdbe1679b0769b687 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 18 May 2020 17:39:15 -0700 Subject: [PATCH] (REF) Move `wp.frontend`, `wp.backend`, etc entirely into WordPress.php --- CRM/Utils/System/WordPress.php | 30 ++++++++++++++++++++++++++++++ Civi/Core/Paths.php | 19 ------------------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php index 715b05b280..cc06150c58 100644 --- a/CRM/Utils/System/WordPress.php +++ b/CRM/Utils/System/WordPress.php @@ -35,6 +35,36 @@ 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 { + 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 */ diff --git a/Civi/Core/Paths.php b/Civi/Core/Paths.php index d0d15814b3..f918cf94df 100644 --- a/Civi/Core/Paths.php +++ b/Civi/Core/Paths.php @@ -30,7 +30,6 @@ class Paths { * Class constructor. */ public function __construct() { - $paths = $this; $this ->register('civicrm.root', function () { return \CRM_Core_Config::singleton()->userSystem->getCiviSourceStorage(); @@ -84,24 +83,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(), -- 2.25.1