X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FSystem%2FWordPress.php;h=f3691eff7c04c085ac6bb9a40fcb921e2a65af6b;hb=337df6ce3ad091bfd6da1556fabd4b87fe0a1c6d;hp=4e86eb89bf9f37a415b734a6ef2327ad5258b146;hpb=926dba90e039b168a5f93cd588b2577c879c468a;p=civicrm-core.git diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php index 4e86eb89bf..f3691eff7c 100644 --- a/CRM/Utils/System/WordPress.php +++ b/CRM/Utils/System/WordPress.php @@ -82,6 +82,44 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { 'url' => admin_url('admin.php'), ]; }); + Civi::paths()->register('civicrm.files', function () { + $upload_dir = wp_get_upload_dir(); + + $old = CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage(); + $new = [ + 'path' => $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR, + 'url' => $upload_dir['baseurl'] . '/civicrm/', + ]; + + if ($old['path'] === $new['path']) { + return $new; + } + + $oldExists = file_exists($old['path']); + $newExists = file_exists($new['path']); + + if ($oldExists && !$newExists) { + return $old; + } + elseif (!$oldExists && $newExists) { + return $new; + } + elseif (!$oldExists && !$newExists) { + // neither exists. but that's ok. we're in one of these two cases: + // - we're just starting installation... which will get sorted in a moment + // when someone calls mkdir(). + // - we're running a bespoke setup... which will get sorted in a moment + // by applying $civicrm_paths. + return $new; + } + elseif ($oldExists && $newExists) { + // situation ambiguous. encourage admin to set value explicitly. + if (!isset($GLOBALS['civicrm_paths']['civicrm.files'])) { + \Civi::log()->warning("The system has data from both old+new conventions. Please use civicrm.settings.php to set civicrm.files explicitly."); + } + return $new; + } + }); } else { // Legacy support - only relevant for older extern routes. @@ -281,9 +319,9 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { if ($config->userFrameworkFrontend) { global $post; if (get_option('permalink_structure') != '') { - $script = get_permalink($post->ID); + $script = $post ? get_permalink($post->ID) : ""; } - if ($config->wpBasePage == $post->post_name) { + if ($post && $config->wpBasePage == $post->post_name) { $basepage = TRUE; } // when shortcode is included in page