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

Abspath defined #4743

Merged
merged 5 commits into from Mar 31, 2018
Merged
Diff settings

Always

Just for now

Copy path View file
@@ -19,3 +19,33 @@ Feature: Runner WP-CLI
ABSPATH defined: /foo/
"""

Scenario: ABSPATH can be defined outside of WP-CLI
Given an empty directory
And a wp-cli.yml file:
"""
require:
- abspath.php
"""
And a abspath.php file:
"""
<?php
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', '/some_path/' );
}
"""

When I try `wp no-such-command --debug`
Then STDERR should not contain:
"""
Constant ABSPATH already defined in
"""
And STDERR should contain:
"""
ABSPATH defined: /some_path/
"""

When I try `wp no-such-command --path=/foo --debug`
Then STDERR should contain:
"""
The --path parameter cannot be used when ABSPATH is already defined elsewhere
"""
Copy path View file
@@ -232,7 +232,14 @@ private function find_wp_root() {
* @param string $path
*/
private static function set_wp_root( $path ) {
define( 'ABSPATH', Utils\normalize_path( Utils\trailingslashit( $path ) ) );
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', Utils\normalize_path( Utils\trailingslashit( $path ) ) );
} elseif ( ! is_null( $path ) ) {
WP_CLI::error_multi_line( array(
'The --path parameter cannot be used when ABSPATH is already defined elsewhere',
'ABSPATH is defined as: "' . ABSPATH . '"',
) );
}
WP_CLI::debug( 'ABSPATH defined: ' . ABSPATH, 'bootstrap' );
$_SERVER['DOCUMENT_ROOT'] = realpath( $path );
ProTip! Use n and p to navigate between commits in a pull request.