WP_CLI
Runner::set_wp_root
Set WordPress root as a given path.
Method of the class: Runner{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = Runner::set_wp_root( $path );
- $path(string) (required)
- .
Runner::set_wp_root() Runner::set wp root code WP-CLI 2.13.0-alpha
private static function set_wp_root( $path ) {
if ( ! defined( 'ABSPATH' ) ) {
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- Declaring a WP native constant.
define( 'ABSPATH', Utils\normalize_path( Utils\trailingslashit( $path ) ) );
} elseif ( ! is_null( $path ) ) {
WP_CLI::error_multi_line(
[
'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 );
}