'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.
* Moved from CRM_Utils_System_Base
*/
public function getDefaultFileStorage() {
+ // NOTE: On WordPress, this will be circumvented in the future. However,
+ // should retain it to allow transitional/upgrade code determine the old value.
+
$config = CRM_Core_Config::singleton();
$cmsUrl = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);
$cmsPath = $this->cmsRootPath();
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