Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set CMS Root in "civicrm_paths" more reliably #171

Merged
merged 1 commit into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions civicrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
19 changes: 12 additions & 7 deletions wp-cli/civicrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]}();

Expand Down Expand Up @@ -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'];
}

} );

}