From dfbcf0b77051e2e38735ee65d0cd8957e92e5944 Mon Sep 17 00:00:00 2001
From: "Donald A. Lobo" <lobo@civicrm.org>
Date: Sun, 14 Apr 2013 16:27:35 -0700
Subject: [PATCH] Give WP more flexibility in layout of WP code vs CiviCRM
 location

---
 CRM/Utils/System/WordPress.php | 48 ++++++++++++++++++++++------------
 1 file changed, 32 insertions(+), 16 deletions(-)

diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php
index 65d00d9428..6f08bfe92e 100644
--- a/CRM/Utils/System/WordPress.php
+++ b/CRM/Utils/System/WordPress.php
@@ -433,26 +433,42 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
     return true;
   }
 
+  function validInstallDir($dir) {
+    $includePath = "$dir/wp-includes";
+    if (
+      @opendir($includePath) &&
+      file_exists("$includePath/version.php")
+    ) {
+      return TRUE;
+    }
+    return FALSE;
+  }
+
   function cmsRootPath() {
     $cmsRoot = $valid = NULL;
-    $pathVars = explode('/', str_replace('\\', '/', $_SERVER['SCRIPT_FILENAME']));
-
-    //might be windows installation.
-    $firstVar = array_shift($pathVars);
-    if ($firstVar) {
-      $cmsRoot = $firstVar;
+    if (defined('CIVICRM_CMSDIR')) {
+      if ($this->validInstallDir(CIVICRM_CMSDIR)) {
+        $cmsRoot = CIVICRM_CMSDIR;
+        $valid = TRUE;
+      }
     }
+    else {
+      $pathVars = explode('/', str_replace('\\', '/', $_SERVER['SCRIPT_FILENAME']));
 
-    //start w/ csm dir search.
-    foreach ($pathVars as $var) {
-      $cmsRoot .= "/$var";
-      $cmsIncludePath = "$cmsRoot/wp-includes";
-      //stop as we found bootstrap.
-      if (@opendir($cmsIncludePath) &&
-        file_exists("$cmsIncludePath/version.php")
-      ) {
-        $valid = TRUE;
-        break;
+      //might be windows installation.
+      $firstVar = array_shift($pathVars);
+      if ($firstVar) {
+        $cmsRoot = $firstVar;
+      }
+
+      //start w/ csm dir search.
+      foreach ($pathVars as $var) {
+        $cmsRoot .= "/$var";
+        if ($this->validInstallDir($cmsRoot)) {
+          //stop as we found bootstrap.
+          $valid = TRUE;
+          break;
+        }
       }
     }
 
-- 
GitLab