From 421117814d206aef5ab2cad985613314d003fe94 Mon Sep 17 00:00:00 2001 From: Christian Wach Date: Mon, 25 Nov 2019 14:05:13 +0000 Subject: [PATCH] Set CMS Root in "civicrm_paths" more reliably --- civicrm.php | 9 +++++++++ wp-cli/civicrm.php | 19 ++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/civicrm.php b/civicrm.php index aab5658..606046e 100644 --- a/civicrm.php +++ b/civicrm.php @@ -364,6 +364,15 @@ public function setup_instance() { session_start(); } + /* + * AJAX calls do not set the 'cms.root' item, so make sure it is set here so + * the CiviCRM doesn't fall back on flaky directory traversal code. + */ + global $civicrm_paths; + if (empty($civicrm_paths['cms.root']['path'])) { + $civicrm_paths['cms.root']['path'] = untrailingslashit(ABSPATH); + } + // Get classes and instantiate $this->include_files(); diff --git a/wp-cli/civicrm.php b/wp-cli/civicrm.php index 60ecaa3..ba044b6 100644 --- a/wp-cli/civicrm.php +++ b/wp-cli/civicrm.php @@ -165,13 +165,6 @@ public function __invoke( $args, $assoc_args ) { return WP_CLI::error( "Unrecognized command - '$command'" ); } - # if --path is set, save for later use by Civi - global $civicrm_paths; - $wp_cli_config = WP_CLI::get_config(); - if (!empty($wp_cli_config['path'])) { - $civicrm_paths['cms.root']['path'] = $wp_cli_config['path']; - } - # run command return $this->{$command_router[ $command ]}(); @@ -1331,4 +1324,16 @@ private function unzip( $destination_path, $option = 'zipfile' ) { WP_CLI::add_command( 'civicrm', 'CiviCRM_Command' ); WP_CLI::add_command( 'cv', 'CiviCRM_Command' ); + # Set path early. + WP_CLI::add_hook( 'before_wp_load', function() { + + # if --path is set, save for later use by Civi + global $civicrm_paths; + $wp_cli_config = WP_CLI::get_config(); + if (!empty($wp_cli_config['path'])) { + $civicrm_paths['cms.root']['path'] = $wp_cli_config['path']; + } + + } ); + }